I have written a simple c# app having functionality of serial
communication. I am using it to read and write to a device. The device
recognizes string commands. I am successfuly able to read from device
using this app. But peoblem is in writing(sending) commands to device.
I am simply using
if (serialPort.IsOpen == true)
{
serialPort.Write("Command1");
}
But my device does not respondes to it.
To check, I tried sending same command using hyperterminal to my
device and my device recognizes it and works perfectly.
Can anybody guide me whats the accurate way to write or what
needs to be make sure for writing to serial port in c#. Is this encoding issue…
(Serial Read using this same app is working pretty fine !!)
Thank you for your time.
Moreover, there is no exception or error and in debug mode
this line executes.
This is a very common problem and invariably caused by leaving the Handshake property set to None. Serial port devices almost always pay attention to the handshake signals and ignore anything you send if the DTR signal isn’t turned on. Which indicates that you are powered up and the data it receives isn’t noise. Setting DtrEnable to true will be required, that’s what HyperTerminal does as well.
And it won’t send anything back when it thinks you are not ready to receive anything because the RTS signal isn’t turned on. Setting RtsEnable to true will be required, that’s what HyperTerminal does as well. Or just set the Handshake property correctly, Handshake.RequestToSend is the common requirement.
If you still have trouble then you can use SysInternals’ PortMon to compare the serial port driver commands your program issues against the ones issued by HyperTerminal.