What does opening a serial port do?

4

What does opening the standard PC serial port do, in electrical terms (i.e. what voltages on which pins)?

For example, the ancient VB6 program which controls an apparatus I am tasked with maintaining toggles .PortOpen to control some TTL. The connection only used 2 pins (bad solders fell apart), so which pins do I solder to?

The only labels / documentation refer to pins 7 and 9, saying 0V and 5V parenthetically, but does .PortOpen really just put 5V between RI and RTS?.

As a post script, this isn't the weirdest thing about the set up. The TTL I referred to above also connects to an instrument via a BNC to DB9 (!), with only 1 pin used. I guess there was an assumption about a common ground, since the BNC shielding isn't connected to the GND pin? The connection is to the instrument's 'foot pedal' pin, it was a way to remotely trigger the device.

Update

According to this page, the DTR and RTS pins can go high when the port is opened. If they were so configured, they will subsequently go low when the port is closed.

If DTR and RTS are not enabled, opening the port should set both to low (and keep them low).

reve_etrange

Posted 2011-06-23T06:41:49.843

Reputation: 173

TTL? Through-the-lens? Transistor-transistor-logic? – None – 2011-06-23T06:49:44.890

The latter. It's a pass through that is opened and closed by a flip-flop toggled by opening/closing the serial port. – reve_etrange – 2011-06-23T06:53:03.687

@reve_etrange: I was asking because serial ports aren't TTL level, so you can't connect them directly. I thought you meant something else. – None – 2011-06-23T06:56:24.853

@Federico Russo, in my embedded applications and debugging I often use TTL level UARTS without drivers. Doesn't everyone have one of these http://www.ftdichip.com/Products/Cables/USBTTLSerial.htm?

– kenny – 2011-06-23T12:47:12.630

@kenny: OP says he's on a PC, and there a serial port goes from -12V to +12V. – None – 2011-06-23T15:00:08.180

@Federico Russo, not necessarily, you can find a PC with built-in RS232 any longer. See the link I provided http://ftdichip.com/Products/Cables/USBTTLSerial.htm ?

– kenny – 2011-06-23T15:37:56.630

Answers

1

I disagree with @Stevenvh answer. For windows in particular. The "port open" and "port close" API calls, say in .NET or MSCOMM OCX will force DTR and RTS lines to change or not change their state electrically.

On port open, the DTR will be set to electrical state, corresponding to boolean property DTREnable, if it was set "true" before opening port. By default, it will stay "false", if user, never set DTREnable, then on "open port" DTR line will stay "false" as before opening port.

Same logic and defaults for line names "RTS" and property "RTSEnable". You choose "RTSEnable" before opening port, depending on communication party on other end of cable and amount of wires involved (hadware handshake vs software handshake vs no handshake).

  • Data carrier detect - is input, no effect
  • Receive data - is input, no effect
  • Transmit data - is output, will stay "SPACE" instead of "MARK"
  • Data terminal ready - will change to "TRUE" if property was set before "Port open"
  • Signal ground - no change
  • Data set ready - is input, no effect
  • Request to send - will change to "TRUE", if RTSEnable property was set before "Port Open"
  • Clear to send - is input, no effect
  • Ring indicator - is input, no effect

In reverse, when port is closed. The pins DTR and RTS will change to "FALSE" state, or stay in "FALSE" state, if they were not set through properties at opening time.

user27803

Posted 2011-06-23T06:41:49.843

Reputation:

How about the other pins (besides DTR and RTS)? – reve_etrange – 2011-06-30T04:44:25.727

The output data pin of PC will stay in "SPACE", not "MARK" state. Other pins are input pins, so they will not change (Ring Indicator, Carrier Detect, Clear To Send, Data Input). – None – 2011-06-30T14:46:28.113

Awesome, thanks! By "stay" SPACE/MARK do you mean that when the port is closed it will revert to some device dependent undefined state? – reve_etrange – 2011-07-01T00:57:04.393

Yes. But SPACE/MARK can be treated as "defined", I mean predictable voltage. Sya in TTL "SPACE" is "FALSE", is zero volts, or MARK is "TRUE" is +5 Volts. But in RS-232 SPACE is +12V and MARK is -12V. – None – 2011-07-01T13:15:01.430

"Transmit data - is output, will stay "SPACE" instead of "MARK"" - An idle RS-232 data line will be MARKing at a negative voltage. – sawdust – 2012-06-23T06:19:29.070

8

Opening the port doesn't do a thing in electrical terms. It just tells the OS that from that moment on the port is assigned to the application. The OS will deny other apps to access the port while yours has it open, and allow your app to access it.

stevenvh

Posted 2011-06-23T06:41:49.843

Reputation: 1 033

That makes sense. Both the serial communication and Windows programming aspects of this are outside my expertise. – reve_etrange – 2011-06-23T07:10:28.883

And on some OSes it can still be shared, but by programmer intention, however perhaps flawed the decision. – kenny – 2011-06-23T12:50:11.040

I unmarked the answer since it's clear that other things can happen when the port is open. Sorry for the rollercoaster. – reve_etrange – 2011-06-29T12:50:02.510

Is this definitely the behavior on non-Windows OSes? – reve_etrange – 2011-06-30T04:45:34.293

6

Opening a serial port will force all pins to a defined state (I don't remember which handshake lines default to marking or spacing, but it's standard). Until the serial port is opened, the state of the lines may be undefined. Unless Microsoft has changed things, closing a serial port would leave the lines in whatever state they were prior to closure, so if the last program one used left them in a weird state they would remain in that state until the next time they were opened. Also, I don't know whether this is still an issue under Windows, but under DOS there were some PC's that would set their serial ports to a goofy state on power-up. At least one brand of PC would set its serial port to transmit continuous long-break until instructed otherwise; this was memorable because it would wreak havoc on a certain embedded controller if it was plugged in before the vendor's software had started.

supercat

Posted 2011-06-23T06:41:49.843

Reputation: 1 649

Does it do anything besides set RTS and DTR to low/high depending on configuration? I.e. are all pins set low on open, do some transmit continuously, etc? – reve_etrange – 2011-06-29T12:48:58.640