I installed SerialDataReceivedEventHandler, with a form-based program in VS2008 express. My serial port is configured as follows:
115200, 8N1
Dtr and Rts included
ReceivedBytesThreshold = 1
I have a device with which I interact with BlueTooth, from USB to Serial. Hyper terminal receives only fine data at any data rate. Data is regularly sent in 22 byte packets. This device has an adjustable data rate. At low data rates, 10-20 Hz, the code below works fine, no problem. However, when I increase the data transfer rate to 25 Hz, one call starts to receive reusable packets. I mean, there must be an event trigger for every incoming packet. With higher output speeds, I immediately checked the buffer size (BytesToRead command) when the event is fired, and then there are several packets in the buffer. I think that the event fires slowly, and by the time the code is reached, more packets are in the buffer. One test I doshows how many times the event is a trigger per second. At 10 Hz, I get 10 event triggers, awesome. At 100 Hz, I get something like 40 event triggers, not good. My goal for a data rate of 100 Hz is acceptable, preferably 200 Hz and optimal 300 Hz. This should work, because even at 300 Hz, it is only 52,800 bps, less than half the set baud rate of 115200. Anything I'm looking at?Anything I'm looking at?Anything I'm looking at?
public Form1()
{
InitializeComponent();
serialPort1.DataReceived += new SerialDataReceivedEventHandler(serialPort1_DataReceived);
}
private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
this.Invoke(new EventHandler(Display_Results));
}
private void Display_Results(object s, EventArgs e)
{
serialPort1.Read(IMU, 0, serial_Port1.BytesToRead);
}