Saturday 15 September 2012

Reading String as buffer for SerialPort using Start and Stop characters with C# -


Serial Protocol: I am interfering with the use of initialization and stopping letters to define "packets" Sometimes this event triggers the handler, all together, sometimes in two dumps, even if I believe that some confirmation is required to create a more robust application. I am very new so I appreciate your patience, but reading as much as I did on MSDN, I can not find the optimal way of doing this. I first appreciate what you can provide guidance

  Private Zero ComPort_DataReceived (Object Sender, SerialDataReceivedEventArgs E) {// Buffer String Buffer = Read all the data waiting in the comport . ReadExisting (); // Remove the data from the process string "//" and the stop "\\" character // buffer to start and send different routines for processing}    

You should add the code to a stringbinder example that is an area of ​​the square with your data recycled method. In this way you can "collect" pieces of packets. Every time you receive some data, you check that your code contains "StringBuilder" or . Only then can you remove the message. Later you will remove that package (including start / stop) from StringBuilder . Now check that there is another package (more start / stop) in it, as it is possible to get packages in parts as well that you can get more than one package at a time.

No comments:

Post a Comment