Aaron
Aaron

Reputation: 11

Serial communication

I am developing an application in C# that needs to communicate with a matrix switch through serial communication.

string value = "abc";
serialPort1.Open();
serialPort1.WriteTimeout = 500;
serialPort1.WriteLine(value);
serialPort1.Close();

The matrix box's state is supposed to change upon WriteLine(value).

Here is my problem. When I send the string value, the matrix box's state does not change. However, when I send the same string via Putty (through serial communication), the matrix box responds correctly. All serial properties are identical (BaudRate, DataBits, PortName, etc).

What are some possible solutions I should try?

Upvotes: 1

Views: 1762

Answers (3)

Alex F
Alex F

Reputation: 43331

Download PortMon http://technet.microsoft.com/en-us/sysinternals/bb896644.aspx and run successful serial communication using Putty, sniffing all data exchange between PC and device. Then execute your program and compare exchange logs. This should give you the answer, what is done incorrect in your program.

Upvotes: 2

Simon Fischer
Simon Fischer

Reputation: 3886

Can you post your code where you setup your SerialPort? You have to make sure all properties are as your matrix switch expects. For instance:

// Setup port
SerialPort serialPort = new SerialPort();
serialPort.PortName = portName; //eg. COM1
serialPort.BaudRate = 9600;
serialPort.StopBits = StopBits.One;
serialPort.Parity = Parity.None;
serialPort.DataBits = 8;
serialPort.Handshake = Handshake.None;
serialPort.NewLine = "\r\n";
serialPort.ReadTimeout = 2000;
serialPort.WriteTimeout = 1000;

After you have called Open() on your port you can check the open or closed status with the serialPort.IsOpen property.

Upvotes: 3

Bryan
Bryan

Reputation: 2791

I would check the Encoding property on the serial port. It looks like the default is ASCII. Maybe your device is expecting Unicode?

Upvotes: 1

Related Questions