Communicating with an USB Device
-
haolan wrote:
So translated into code you are saying that I should do something like this when i read:
Kind of, though there are async read methods that do all of this work for you and call you when there is some data to read.
haolan wrote:
The 10 bytes to read is because I know that the valid data always will be 10 characters long.
That's not how you do it. Even though your return data may be 10 bytes, you can still get it in several small chunks in multiple reads. Your code has to be able to reassemble the data as it comes in so it can provide a completed message back to the code that's expecting a 10 byte message.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007Ok.. I found this example at MSDN: public static void Read() { while (_continue) { try { string message = _serialPort.ReadLine(); Console.WriteLine(message); } catch (TimeoutException) { } } } And then you say I have to create a method that tries to parse the code, to check if it is a valid message, and if not, then it should run the read() again until the code can be parsed right?