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.
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.