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

From SoftMC-Wiki
Jump to: navigation, search
m
m
Line 6: Line 6:
 
The program opens COM2 and waits for at least 3 bytes to arrive. Then it sends a message "done" and closes connection.
 
The program opens COM2 and waits for at least 3 bytes to arrive. Then it sends a message "done" and closes connection.
  
|EXAMPLE=
+
<pre>
common shared str1 as string<br/>
+
common shared str1 as string
common shared iteration_counter as long = 0<br/>
+
common shared iteration_counter as long = 0
common shared time_counter as long = 0<br/>
+
common shared time_counter as long = 0
<br/>
+
 
Program<br/>
+
Program
<br/>
+
 
try <br/>
+
try
close #2<br/>
+
close #2
catch else<br/>
+
catch else
<br/>
+
 
end try<br/>
+
end try
<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/>
+
 
 
while (loc(2) < 3) and (time_counter < 120)  '  allow 120 seconds for system start up to complete<br/>
 
while (loc(2) < 3) and (time_counter < 120)  '  allow 120 seconds for system start up to complete<br/>
sleep 1000<br/>
+
sleep 1000
time_counter = time_counter +1<br/>
+
time_counter = time_counter +1
end while<br/>
+
end while
<br/>
+
 
str1 = input$(loc(2),#2)<br/>
+
str1 = input$(loc(2),#2)
?str1<br/>
+
?str1
<br/>
+
 
 
print #2, "done"
 
print #2, "done"
<br/>
+
 
sleep 100<br/>
+
sleep 100
<br/>
+
 
close #2<br/>
+
close #2
<br/>
 
 
End Program
 
End Program
<br/>
+
 
 +
</pre>
  
 
|SEE ALSO=
 
|SEE ALSO=

Revision as of 13:55, 2 April 2014