Click to See Complete Forum and Search --> : Serial Port bit loss


Marco Leon
April 10th, 2008, 06:01 PM
I need to send an receive bytes to serial port. Numbers from 0 to 127 are transmitted correctly, but any number greater than 127 (128 to 255) always is readed as 63.

I coded in C# Visual Studio 8.0.5..:

...
SerialPort sp = new SerialPort("COM1", 2400, Parity.None, 8, StopBits.One);
...
sp.Open();
sp.ReadTimeout = 500;
...

private int TxRx(int Direcc)
{
char[] cDir = new char[1];
cDir[0] = Convert.ToChar(Direcc);

try
{
sp.Write(cDir, 0, 1);

}
catch (SystemException ex)
{
lbMensaje.Text = ex.Message;
return 255; //Tx error code
}

try
{
return sp.ReadByte();
}
catch (System.Exception ex)
{
lbMensaje.Text = ex.Message;
return 254; //Rx error code
}
}

I test linking pin 2 and 3 in DB-9 connector

Tanks in advance.

zdavis
April 10th, 2008, 10:30 PM
are you using a null modem cable.

Marco Leon
April 10th, 2008, 11:31 PM
Yes, and flow control is implemented in the software. Is it necessary to configure the port to use the software flow control?

zdavis
April 11th, 2008, 09:48 AM
what type of device are you communicating with?

if you knew what the newline character was for the device you could set your newline character and then use the readLine(). I don't see anywhere in your code where you have set flow control or handshake which is what it is called in the Serial Port Class. I believe it is an enum value.

http://msdn2.microsoft.com/en-us/library/system.io.ports.serialport.aspx

you can set it by saying



serialport.handshake = handshake.xonxoff



i hope that helps