Hello everyone,
I have a problem with reading SerialPort data.My code goes like this:
SerialPort sp = new SerialPort("COM3",9600,Parity.None,8,StopBits.One);
sp.Open();
sp.DtrEnable = true;
sp.RtsEnable = true;
//byte[] data = new byte[sp.BytesToRead];
// int i = sp.Read(data, 0, data.Length);
string val = sp.ReadExisting();
textBox1.Text = sp.ReadExisting();
sp.Close();
But it returns me thing.Output is just empty.
What would be the problem??
Thanks in advance,
Soumya
I have a problem with reading SerialPort data.My code goes like this:
SerialPort sp = new SerialPort("COM3",9600,Parity.None,8,StopBits.One);
sp.Open();
sp.DtrEnable = true;
sp.RtsEnable = true;
//byte[] data = new byte[sp.BytesToRead];
// int i = sp.Read(data, 0, data.Length);
string val = sp.ReadExisting();
textBox1.Text = sp.ReadExisting();
sp.Close();
But it returns me thing.Output is just empty.
What would be the problem??
Thanks in advance,
Soumya
Ryan AlfordPosted Aug 23, 2008, 11:25 AM
puneet guptaPosted Aug 23, 2008, 2:10 AM
Hi Saumya
Did u set the RThreshold value. It must be 0 for all received bytes and a number say n for those number of bytes you want to retrieve from the received buffer. This is in reference to mscomm control. But I guess same should be applicable to .net 2.0 fw serialport control.
Also have a look at the following useful link
http://msmvps.com/blogs/coad/archive/2005/03/23/SerialPort-_2800_RS_2D00_232-Serial-COM-Port_2900_-in-C_2300_-.NET.aspx
http://www.codeproject.com/KB/cs/serialcommunication.aspx
Regards
Puneet