Example of using the Timer to Send and Receive Commands to and from a Remote Device. The following code would be placed in the Timer Event Handling Embed for a Window (either the Main App Window or another Window Procedure started as a Thread). Note that the code never "waits around" for a Response from the Device. Once it sends a Command to the Device, it sets a "time out" value and then checks the Serial Port for a Response on successive iterations of the Timer Event. Using the Timer in this manner allows your Program to be responsive to other Windows Messages that are sent to your Program, and is an absolute requirement for 16 bit programs. In a pratical application, the code should also check a counter to insure that it does not endlessly repeat the sending of the same Command. For instance, if the Device does not respond, you will see that the Command is sent again. A Counter should be used to make sure that some action is performed after sending the same command a pre-set number of times. ! EventNum = SHORT(0) ! Event to Execute ! NumSecs = LONG ! For Keeping Tack of Response Time ! CommandStr = CSTRING(100) ! Command to String ! ResponseStr = CSTRING(100) ! Response String ! To start the ball rolling, either an Operator or the Window ! Opening code will set EventNum to 1 Case EventNum Of 1 ! Event #1 is to Send a Command If Clip(CommandStr) ! Make sure we have something to send ComPuts(PortNum,CommandStr) NumSecs = Clock() ! Get Current Time for Response Time EventNum = 2 ! Next time around, get response End Of 2 ! Event #2 is to get Response to our Command If RecvCount(PortNum) >= 3 ! Device will send ACK or NAK ComGetb(PortNum, ResponseStr) ! Get everything in Receive Buffer If Clip(ResponseStr) = 'ACK' ! If Device did what we told it to do EventNum = 3 ! Do Next Command Else EventNum = 1 ! Repeat Last Command End Else ! Check for Time Out ! Has 10 Seconds passed? If (Clock() - NumSecs) >= (10 * 100) OR Clock() < NumSecs EventNum = 1 ! Repeat Last Command End End Of 3 ! Sent Command and it was carried out ! Load up CommandStr with a new Command ! If no more Commands to carry out, set EventNum to 0 (or disable ! the timer). CommandStr = 'MoveRight60Degrees' ! Assuming the thing understands English! EventNum = 1 ! Send Command on next Pass Thru End