switch statement not working in a wait_until wait statement
rrdbstudios
Posts: 160
.. I am waiting for a stable ip connection to be made before sending a command. Once the connection is made, the switch statement never fires off, only the "default" case, which shouldn't occur; the if statement I put in before functions properly, but I preferred the switch statement if it worked.
If anyone knows the reason for this, or sees my problem, please point it out. Also, I know this function isn't too eloquent, so if you have some thoughts to make it cleaner, by all means..
Please ignore the massive amount of comments and some extra variables that I have tried using to get the switch statement to work.
If anyone knows the reason for this, or sees my problem, please point it out. Also, I know this function isn't too eloquent, so if you have some thoughts to make it cleaner, by all means..
Please ignore the massive amount of comments and some extra variables that I have tried using to get the switch statement to work.
// ******** DM Switch Control DEFINE_FUNCTION INTEGER fnDoRoute(INTEGER nIn, INTEGER nOut, INTEGER nLev){//CHAR nIn[3], CHAR nOut[3], INTEGER nLev) { local_var SINTEGER nIPConnectionStatus; // close port just incase its already open IP_CLIENT_CLOSE (dvVideoSwitch.Port); //send_string 0, "'###opening connection to dm switch. IP Address: ', cVideoSwitchIP, ':41795'"; // IP (Direct) Method nIPConnectionStatus = IP_CLIENT_OPEN (dvVideoSwitch.Port,cVideoSwitchIP,41795,IP_TCP); wait_until (uVideoSwitch.nReady == 1) 'DM Switch connection ready' { //send_string 0, "'###connected to the dm switch successfully, sending command'"; wait 15{ // send_string 0, "'###insdie wait loop to send command to dm'" if(nLev == AUDIO){ send_string dvVideoSwitch, "'SETAUDIOROUTE ',ITOA(nIn),' ',ITOA(nOut + VIDEO_OUT_OFFSET),13,10"; send_string 0, "'#->SETAUDIOROUTE ',ITOA(nIn),' ',ITOA(nOut + VIDEO_OUT_OFFSET),13,10"; } else if(nLev == VIDEO){ send_string dvVideoSwitch, "'SETVIDEOROUTE ',ITOA(nIn),' ',ITOA(nOut + VIDEO_OUT_OFFSET),13,10"; send_string 0, "'#->SETVIDEOROUTE ',ITOA(nIn),' ',ITOA(nOut + VIDEO_OUT_OFFSET),13,10"; } else if(nLev == BOTH){ // using this because the switch statement isnt working?? send_string dvVideoSwitch, "'SETAVROUTE ',ITOA(nIn),' ',ITOA(nOut + VIDEO_OUT_OFFSET),13,10"; send_string 0, "'#->SETAVROUTE ',ITOA(nIn),' ',ITOA(nOut + VIDEO_OUT_OFFSET),13,10"; } else if(nLev == UPDATE_ALL){ send_string dvVideoSwitch, "'SETAVUROUTE ',ITOA(nIn),' ',ITOA(nOut + VIDEO_OUT_OFFSET),13,10"; send_string 0, "'#->SETAVUROUTE ',ITOA(nIn),' ',ITOA(nOut + VIDEO_OUT_OFFSET),13,10"; } // NOT WORKING FOR SOME REASON ?? /* switch (nLev) { case AUDIO : { send_string dvVideoSwitch, "'SETAUDIOROUTE ',ITOA(nIn),' ',ITOA(nOut + VIDEO_OUT_OFFSET),13,10"; send_string 0, "'###->SETAUDIOROUTE ',ITOA(nIn),' ',ITOA(nOut + VIDEO_OUT_OFFSET),13,10"; } case VIDEO : { send_string dvVideoSwitch, "'SETVIDEOROUTE ',ITOA(nIn),' ',ITOA(nOut + VIDEO_OUT_OFFSET),13,10"; send_string 0, "'###->SETVIDEOROUTE ',ITOA(nIn),' ',ITOA(nOut + VIDEO_OUT_OFFSET),13,10"; } case BOTH : { send_string dvVideoSwitch, "'SETAVROUTE ',ITOA(nIn),' ',ITOA(nOut + VIDEO_OUT_OFFSET),13,10"; send_string 0, "'###->SETAVROUTE ',ITOA(nIn),' ',ITOA(nOut + VIDEO_OUT_OFFSET),13,10"; } CASE UPDATE_ALL : { send_string dvVideoSwitch, "'SETAVUROUTE ',ITOA(nIn),' ',ITOA(nOut + VIDEO_OUT_OFFSET),13,10"; send_string 0, "'###->SETAVUROUTE ',ITOA(nIn),' ',ITOA(nOut + VIDEO_OUT_OFFSET),13,10"; } default: send_string 0,"'#######not seeing anything to send nIn=',itoa(nIn), ' nOut=',itoa(nOut), ' nLevel=',itoa(nLev)" }*/ wait 5 nIPConnectionStatus = IP_CLIENT_CLOSE(dvVideoSwitch.Port); if(nIPConnectionStatus == 0) { //send_string 0, "'###Sucessfully made AV Route Change'"; } } } }
0
Comments
IMHO, wait_until should simply never be used. If you find yourself using it, you are writing badly designed code.
You also typically don't need to call ip_client_close ever, unless you are shutting down a socket due to an offline event or some other strange occurrence. Why do you call it to close it in case its open? If its open, leave it open! You are sending a command to it!
The socket will close on its own via the underlying TCP mechanism, or will stay open and not require maintenance. There really is never a case I can think when you would want to manually close a socket by calling ip_client_close in the normal course of events.
You need the socket open to send a command. So to achieve this you should only send a command when it is open. How do you know when its open? Well in the online event it must be open. So send all your commands to the socket there, and if its closed and you need to send a command open it then and then send the command in the online event once its open. My guess about your switch statement is that by the time the wait_until happens, the variables are long past having scope so they are worthless.
Paul
If you equate it to a LOCAL_VAR then that may work, but I would rework your code....