Difference between revisions of "Program Examples:Serial Com:Serial Com Example"

From SoftMC-Wiki
Jump to: navigation, search
Line 2: Line 2:
  
 
|DESCRIPTION=
 
|DESCRIPTION=
The following example demonstrates the set up of a TCP-IP server that opens connection with multiple clients.<br/>
+
The following example demonstrates the set up of a serial connection with MCHD.<br/>
 
<br/>
 
<br/>
The server opens a socket and blocks on "Accept" until a client gets connected. Then an exchange of messages takes place and the server<br/>
+
The program opens COM2 and waits for at least 3 bytes to arrive. Then it sends a message "done" and closes connection.
closes the connection and gets blocked again waiting to accept the next client.<br/>
 
 
<br/>
 
<br/>
 
<br/>
 
<br/>
  
 
|EXAMPLE=
 
|EXAMPLE=
 +
common shared str1 as string<br/>
 +
common shared iteration_counter as long = 0<br/>
 +
common shared time_counter as long = 0<br/>
 +
<br/>
 +
Program<br/>
 +
<br/>
 +
try <br/>
 +
close #2<br/>
 +
catch else<br/>
 +
<br/>
 +
end try<br/>
 +
<br/>
 
Open COM2 BaudRate=115200 Parity=0 DataBits=8 StopBit=1 XOnOff=1 As #2<br/>
 
Open COM2 BaudRate=115200 Parity=0 DataBits=8 StopBit=1 XOnOff=1 As #2<br/>
sleep 3000<br/>
 
print #2, "done"<br/>
 
 
<br/>
 
<br/>
 +
while (loc(2) < 3) and (time_counter < 120)  '  allow 120 seconds for system start up to complete<br/>
 +
sleep 1000<br/>
 +
time_counter = time_counter +1<br/>
 +
end while<br/>
 +
<br/>
 +
str1 = input$(loc(2),#2)<br/>
 +
?str1<br/>
 +
<br/>
 +
print #2, "done"
 +
<br/>
 +
sleep 100<br/>
 +
<br/>
 +
close #2<br/>
 +
<br/>
 +
End Program
 +
<br/>
 +
 
|SEE ALSO=
 
|SEE ALSO=
 
* [[Axystems:MC-Basic:OPEN|OPEN]]
 
* [[Axystems:MC-Basic:OPEN|OPEN]]

Revision as of 10:52, 6 March 2014