bob kings

bob kings

  • NA
  • 1
  • 0

Problem with serial communication with xon/xoff controls

Oct 22 2008 6:58 PM
Hi

I am a newbie in C# and somehow have to develop a software that communicates with an external device that has a RS232 interface.

I have some experiences with RS232 programming but none of them involves handshacking.

The parameters of this device is as follows:

baudrate: 1200
parity: odd
data bits: 7
stop bits: 1
handshacking: Xon/Xoff

If I use the hyperterminal in windows, it responds ok. But I cannot get the C# program to work.

Here is the part of the settings in the program:

SerialPort BalancePort = new SerialPort();
BalancePort.PortName = 'COM1';
BalancePort.BaudRate = 1200;
BalancePort.DataBits = 7;
BalancePort.Parity = System.IO.Ports.Parity.Odd;
BalancePort.StopBits = System.IO.Ports.StopBits.One;
BalancePort.Handshake = System.IO.Ports.Handshake.XOnXOff;
BalancePort.ReadTimeout = 2000;


Here is the the write and read part:

BalancePort.Write(new byte[] { 0x1B, 0x50 }, 0, 2);
Thread.Sleep(5000);
string feedback = BalancePort.ReadExisting();

But it turns out every time it does not read a byte.

Any suggestions is highly appreciated.


ThanksP

Answers (1)