Reputation: 988
We are developing WinCE SerialPort Application on .net compact framework 3.5.
In The serialPort Class we have DataReceived event, un fortunately it is firing only once.
Our serialport settings are below:
_com = new SerialPort();
_com.PortName = str_comport;
_com.BaudRate = pBaudRate;
_com.ReadTimeout = 1000 * 10 * 1;
_com.WriteTimeout = 1000 * 10 * 1;
_com.Handshake = Handshake.None;
_com.ReceivedBytesThreshold = 1;
_com.RtsEnable = true;
_com.DtrEnable = true;
_com.Parity = pParity;
_com.DataBits = pDataBits;
_com.StopBits = pStopBits;
_com.DataReceived += new SerialDataReceivedEventHandler(this.Receive);
_com.Open();
....
private void Receive(object sender, SerialDataReceivedEventArgs e)
{
_receivedString = _port.ReadExisting();
_log.WriteFile("RX : " + _receivedString);
}
We have tried opening port first and attaching data received Event also but of no use.
and the same code works fine on Windows XP/Windows 7 Machine.What could be the possible reason.
Upvotes: 0
Views: 1270
Reputation: 67168
We need to know more about what your expectation and the data coming in looks like. What does your Receive
method look like?
The ReceivedBytesThreshold
can be thought of as a trigger point on the input buffer. When the buffer size goes past that, only in a forward direction, you get an event. In this case it means when the receive buffer size goes from 0 to 1 byte, you'll get an event. You won't get one from, say 200 to 201. You don't get an event for every byte either.
So to make this effective, when you receive the event, you need to read all data from the buffer, bringing its size back to zero and effectively "resetting" the event trigger.
Upvotes: 1