Bytestoread Serial Port C#
That is the data (frame) i receive (always 14 bytes):68 -'D'65 -'A'84 -'T'0127 Xh254 Xl00115 Yh51 Yl5019670 -'F'i do the job with this, (127254) is my X value and 11551 my Y value, i use these to plot it in a chart,my hardware now is sending frames continuoslyx = 1 y = 0,001 'D' 'A' 'T'.' F'x = 2 y = 0,002 'D' 'A' 'T'.' F'x = 3 y = 0,003 'D' 'A' 'T'.'
F'All data with this 'D' 'A' 'T'.' F' frame format is interesting for me, and continuosly read. When answering a question please:. Read the question carefully.
Understand that English isn't everyone's first language so be lenient of badspelling and grammar. Ms dos 6.2 boot disk. If a question is poorly phrased then either ask for clarification, ignore it, oredit the question and fix the problem. Insults are not welcome. Don't tell someone to read the manual.
Chances are they have and don't get it.Provide an answer or move on to the next question.Let's work to help developers, not make them feel stupid.
Just some recommendations, but they might be a key solving your performance problem and the problem with loosing data.Do all serial port communications in a separate thread and use only the synchronous read. Your thread is supposed to be blocked at the reading calls when the data sent is not yet arrived.Instead of using ReadByte try to read by bigger blocks by using int System.IO.Ports.SerialPort.Read(byte, int, int):.The reading of a block will introduce a delicate problem related to blocking and not loosing some data not delivered from the other end of the cable at the moment of waking up your thread.
C# Serial Port Bytestoread Always 0
In my recent answer I explained who to work with it in detail. Please see:.No, the question referenced above is not about thread suspend/resume, this is about the same serial port problem close to the one you have.:-)—SA. It's my english;) Yes should be a question.I mean reading a serial input without loosing packages is not a problem today.Processing data maybe is a bottleneck.So separating the two jobs should solve the problem. In the meaning, making a receiver which simply puts the packages into a queue which will be processed by another thread.Then ok if processing raw data is really time consuming then maybe memory becomes a problem. But this I think anyway can only be solved by improving the algorithms or improving the hardware.
I have implemented my idea (reading byte by byte and when in sync read one packed of 19 bytes at once)in my project and tested it.After opening serialport the first packet is incomplete the second is valid(reading byte by byte) and the rest reading full packet at once are all valid and processed in time.running for 15 minutes at 6.3 packets of 19 bytes per second: no packets lost, all valid.GrooverFromHollandPSI will submit my serial event code with comment after more testing at higher speed. When answering a question please:. Read the question carefully. Understand that English isn't everyone's first language so be lenient of badspelling and grammar.
If a question is poorly phrased then either ask for clarification, ignore it, oredit the question and fix the problem. Insults are not welcome. Don't tell someone to read the manual. Chances are they have and don't get it.Provide an answer or move on to the next question.Let's work to help developers, not make them feel stupid.