Difference between revisions of "Program Examples:Serial Com:Serial Com Example"
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. | ||
| − | + | <pre> | |
| − | common shared str1 as string | + | common shared str1 as string |
| − | common shared iteration_counter as long = 0 | + | common shared iteration_counter as long = 0 |
| − | common shared time_counter as long = 0 | + | common shared time_counter as long = 0 |
| − | + | ||
| − | Program | + | Program |
| − | + | ||
| − | try | + | try |
| − | close #2 | + | close #2 |
| − | catch else | + | catch else |
| − | + | ||
| − | end try | + | end try |
| − | + | ||
| − | Open COM2 BaudRate=115200 Parity=0 DataBits=8 StopBit=1 XOnOff=1 As #2 | + | 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<br/> | while (loc(2) < 3) and (time_counter < 120) ' allow 120 seconds for system start up to complete<br/> | ||
| − | sleep 1000 | + | sleep 1000 |
| − | time_counter = time_counter +1 | + | time_counter = time_counter +1 |
| − | end while | + | end while |
| − | + | ||
| − | str1 = input$(loc(2),#2) | + | str1 = input$(loc(2),#2) |
| − | ?str1 | + | ?str1 |
| − | + | ||
print #2, "done" | print #2, "done" | ||
| − | + | ||
| − | sleep 100 | + | sleep 100 |
| − | + | ||
| − | close #2 | + | close #2 |
| − | |||
End Program | End Program | ||
| − | < | + | |
| + | </pre> | ||
|SEE ALSO= | |SEE ALSO= | ||