Saturday, August 11, 2012 10:23 PM
I have a C# program that makes use of a SerialPort object. I'm successfully sending and receiving data over the Serial Port. It takes just milliseconds to do the actual sending and receiving, and the "other end" of the serial port (another computer communicating over an RF link) responds to requests for data in just milliseconds.
I'm processing the Incoming Data Events from the Serial Port. That processing includes receiving the data (very fast), displaying the received data in a form text box (very fast), and sending a request for more data back through the Serial Part (very fast). Since the other computer responds to each such request very fast (milliseconds), I expect to see really fast processing of this, almost real-time processing. But instead, there's a significant delay for each update that I see. Even though the actual receiving, sending, updating the text box takes just milliseconds (I timed them), each actual update takes more like half a second.
I suspect that the operating system is doing a heck of a lot of other things besides just running my program, but all I'm running is my specific program.
I tried increasing the Priority of my program but it has no effect.
What can I do to make this run faster? ALL it is doing is responding to the Incoming Data Events for the Serial port (which SHOULD be happening very fast) yet it takes a half second each time.
Saturday, August 11, 2012 10:58 PM
How much data is coming through? You have to keep in mind that the serial port is from the original IBM-PC (8086) design ... it isn't very fast (even if it's RF or IR). My initial guess is that you are bottlenecked "on the wire" and, with serial, you have a pretty small "wire".
You may also want to take a look at some perf counters ... I'm not 100% sure which ones would be detailed for serial port but I'd start with the process IO counters.
DevBiker (aka J Sawyer)
Microsoft MVP - Sql Server (StreamInsight)
If I answered your question, please mark as answer.
If my post was helpful, please mark as helpful.
Sunday, August 12, 2012 1:25 AM
I've put some timers on the code that actually handles the sending and receiving of data on the serial port and its extremely fast, 10 - 20 milliseconds, typically, 100 milliseconds tops. It's only transmitting 50 or so bytes at a time. But SOME-thing is taking up half a second's worth of processing during each transmission and I haven't been able to pin that down.
During a bunch of testing there was ONE run of the program in which it went particularly fast. I could actually watch it run almost in real-time, for brief periods of time. It would do ten or twenty transmissions, with accompanying updating of the Form's text, and then it would slow down again. It fluctuated between brief spurts of speed and short periods of slow processing. But that only happened once and I haven't been able to reproduce it again. I have no clue what caused it to do that. In every other run of the program is just plods along, taking about a half second for each transmission