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

From SoftMC-Wiki
Jump to: navigation, search
m
 
(17 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{Axystems:Template:Serial_Com
+
{{Languages|Program_Examples:Serial_Com:Serial_Com_Example}}
 +
The following example demonstrates the setup of a serial connection with softMC.
  
|DESCRIPTION=
 
The following example demonstrates the set up of a serial connection with softMC.<br/>
 
<br/>
 
 
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.
<br/>
 
<br/>
 
  
|EXAMPLE=
+
<syntaxhighlight lang="vb">
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/>
 
<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/>
 
<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=
+
Program
* [[Axystems:MC-Basic:OPEN|OPEN]]
 
* [[Axystems:MC-Basic:LOC|LOC]]
 
* [[Axystems:MC-Basic:PRINT|PRINT]]
 
* [[Axystems:MC-Basic:INPUT$|INPUT$]]
 
* [[Axystems:MC-Basic:CLOSE|CLOSE]]
 
* [[Axystems:MC-Basic:PRINT|PRINT]]
 
  
}}
+
try
 +
close #2
 +
catch else
 +
 
 +
end try
 +
 
 +
Open COM2 BaudRate=115200 Parity=0 DataBits=8 StopBit=1 XOnOff=1 As #2
 +
 
 +
while (loc(2) < 3) and (time_counter < 120) ' allow 120 seconds for system start up to complete
 +
sleep 1000
 +
time_counter = time_counter +1
 +
end while
 +
 
 +
str1 = input$(loc(2),#2)
 +
?str1
 +
 
 +
print #2, "done"
 +
sleep 100
 +
 
 +
close #2
 +
 
 +
End Program
 +
</syntaxhighlight>
 +
 
 +
 
 +
The example corresponds to commit SHA-1: ada143a7f402e6bbad24c13c56401a5393ce3d2b.
 +
 
 +
 
 +
== See Also ==
 +
* [[Serial Communication|'''Serial Communication''']]
 +
* [[MC-Basic:OPEN|OPEN]]
 +
* [[MC-Basic:LOC|LOC]]
 +
* [[MC-Basic:PRINT|PRINT]]
 +
* [[MC-Basic:INPUT$|INPUT$]]
 +
* [[MC-Basic:CLOSE|CLOSE]]
 +
* [[MC-Basic:PRINT|PRINT]]

Latest revision as of 08:19, 16 July 2017

Language: English  • 中文(简体)‎

The following example demonstrates the setup of a serial connection with softMC.

The program opens COM2 and waits for at least 3 bytes to arrive. Then it sends a message "done" and closes connection.

common shared str1 as string
common shared iteration_counter as long = 0
common shared time_counter as long = 0

Program

	try 
		close #2
	catch else

	end try

	Open COM2 BaudRate=115200 Parity=0 DataBits=8 StopBit=1 XOnOff=1 As #2

	while (loc(2) < 3) and (time_counter < 120) ' allow 120 seconds for system start up to complete
		sleep 1000
		time_counter = time_counter +1
	end while

	str1 = input$(loc(2),#2)
	?str1

	print #2, "done" 
	sleep 100

	close #2

End Program


The example corresponds to commit SHA-1: ada143a7f402e6bbad24c13c56401a5393ce3d2b.


See Also