Reputation: 513
I want to use the stream class to read/write data to/from a serial port. I use the BaseStream to get the stream (link below) but the Length property doesn't work. Does anyone know how can I read the full buffer without knowing how many bytes there are?
http://msdn.microsoft.com/en-us/library/system.io.ports.serialport.basestream.aspx
Upvotes: 1
Views: 4343
Reputation: 133995
You can't. That is, you can't guarantee that you've received everything if all you have is the BaseStream
.
There are two ways you can know if you've received everything:
Or, depending on your application, you can do some kind of timing. That is, if you haven't received anything new for X number of seconds (or milliseconds?), you assume that you've received everything. That has the obvious drawback of not working well if the sender is especially slow.
Upvotes: 2