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).

3 Answers3

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
  • 1,199
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
  • 1,819
  • 10
  • 8
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.