Is there a way to check that the bus is not active (ie sitting on a "1" or "hi"). If I can read this status, then I can sit in a loop until the appropriate time has elapsed----then either wait for the next start bit ("0" or "lo") to begin receiving the message stream, or to start sending my own message on the otherwise unoccupied serial bus.
I am using OPEN COM and GET to receive characters one by one at the moment but seem to be starting part way into a message so have some corrupt data. Unfortunately the messages are of variable length so finding the end of each is going to be my next challenge (the last character is a checksum (and not EOF or CR/LF) so is different each time.
IMMEDIATE EDIT---I think I may have discovered a possibility----I can use LOC and a WHILE/WEND loop I think, but if anyone has any suggestions I would still appreciate it.
MORE---yes, it is amazing how useful the Wiki is once you know the answer, or what to search for. It seems the example in the LOC section is close to what I am looking for--I can make use of this I think.
Code: Select all
Dim b As String
If Open Com ("com1:9600,n,8,1,cs,rs,ds,bin" For Binary As #1) <> 0 Then
Print "unable to open serial port"
End
end If
Print "Sending command: AT"
Print #1, "AT" + Chr(13, 10);
Sleep 500,1
Print "Response:"
While( LOC(1) > 0 )
b = Input(LOC(1), 1)
Print b;
Wend
Close #1