![]() Try ReceivedByte = YourSerialPort.ReadByte Catch ex As Exception ' Do something in case of a timeout. ' This is the only byte related send method there is.ĭon't use a Char based method unless you use ASCII. ![]() ![]() Something like this simplified code should do it: YourSerialPort.ReadTimeout = TimeInMilliseconds ' Set the receiver timeout YourSerialPort.Write(ByteArray1, Offset, Count) ' ByteArray1 must contain the first command. ![]() In case the response is ASCII, you can do this in a single statement using ReadLine, but you should be aware that all data are converted to 16-bit Unicode so this method should only be used in you really do receive Text. Just put ReadByte into a Do - Loop Until where you call ReadByte until you have received the termination character. The last response consists of a number of bytes where the last byte has a known value so it is fairly easy to catch the full telegram. ![]() If it doesn't matter that the UI thread is dead while waiting for the response, it is very simple - just make the above sequence 1-4 and call each Read in a try-catch statement so that you can catch the timeout in case your device is not responding to the poll (remember to set timeout time). ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |