4

I want to know if I put these in my code, does computer send any kind of signal to the device?

SerialPort myport = new SerialPort("COM1");

myport.DtrEnable = true;
myport.RtsEnable = true;

I'm required to send a signal on specific pins to the device. As I know Dtr and Rts use pins 4 and 7. So when I write the code above, will my computer send a signal on pins 4 and 7? Or is there a simple way to send a signal on a specific pin?

Mateen Ulhaq
  • 24,552
  • 19
  • 101
  • 135
jason
  • 6,962
  • 36
  • 117
  • 198

2 Answers2

9

Sure, these properties control the state of the handshake signals. Their use is not arbitrary, a properly designed serial port device pays attention to them. DTR is Data Terminal Ready, normally connected to DSR (Data Set Ready) on the device. The device assumes that your computer is simply not turned on or the cable is disconnected when DSR is off. It won't send anything and ignores anything you send to it when the signal is off.

RTS is Request To Send, normally connected to CTS (Clear To Send) on the device. Normally used for flow control, it prevents the device from sending too much data and overflow the receive buffer. A nasty problem that is very hard to recover from, the data is entirely lost.

You should normally set the SerialPort.Handshake property to HandShake.RequestToSend so the driver does this automatically. A very common bug is to leave it set to Handshake.None, now you have to turn on these signals yourself. And you'll risk buffer overflow of course, albeit that you'd have to write very slow code to ever get in the danger zone. It has been done.

These signals can be used in hobby projects to control, say, a reed relay. Do beware that the voltages on the signal lines are unpredictable (swings between +/- 5 to 24 Volts) and can't supply a lot of amps (usually 20 milliamps max). You need at least a diode, typically a transistor to switch a heavier load. Ask about it at electronics.stackexchange.com

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • Should HandshakeProperty be Handshake.RequestToSendXOnXOff? – jason Aug 22 '14 at 12:18
  • 1
    Very doubtful, xon/xoff handshaking doesn't get used that much. Of course it depends on the device, you can't just guess at it. Very easy to find out however, type Ctrl+S in a terminal emulator and if that stops the device from sending, and Ctrl+Q resumes it, then it is necessary. – Hans Passant Aug 22 '14 at 12:23
4

In theory: Yes. Whatever you have connected to your serial port will see something. It won't be data, but if it is checking its pin states, it will know that you have done something.

In practice: Maybe. Being able to accurately detect these pin states is heavily dependent on the cable being used. Here is a recent post that goes over the cable related issues with these pin states.

Community
  • 1
  • 1
Tremmors
  • 2,906
  • 17
  • 13