Click here to Skip to main content
15,885,028 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I'm making a project, where I need to write to the serial port and read response from it as fast as possible. So I have written this code:

C#
serialPort.Open();
byte[] outBuf = new Byte[] { 59, (int)'4', (int)'3', (int)'1', 0, 0, 0 };
serialPort.Write(outBuf, 0, outBuf.Length);
byte a = Convert.ToByte(serialPort.ReadByte());
serialPort.Close();


But value of 'a' is always same as the first byte of outBuf (59 in this example).
If I close the port and open it again between reading and writing I get the correct value, but that takes to much time.
I also tried with serialPort.DiscardOutBuffer(); and it doesn't take any effect.

Does anybody know how to do that as fast as possible?

Thanks for help!
Posted

1 solution

Could you please try these alternatives

Serial Communication in C#

Serial Communication in C#
 
Share this answer
 
Comments
Rddezh 28-May-13 10:08am    
I tried with DataReceived event, but I still get 59 :(

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900