# Determining when a serial connection is opened

I have a PIC24FJ MCU with an FT232RL USB to UART controller. My design has end users opening a serial connection to my MCU to set parameters and get debug information.

My question is: How can I tell when the end user has opened screen/PuTTY/etc to my device's COM port?

From what I have read, the DTR signal is not a good way to go about this as the OS decides when to raise DTR.

My use case is that I would like to display a banner with help commands as soon as the COM port is opened.

You are correct that DTR can be overridden by OS, but in practice, it is actually a pretty good indicator. And in Linux, it is pretty hard to disable [0].

If you have USB support in your chip, you can implement CDC class serial device natively. This usually does not require any drivers, and gives you full information, including when the port is open. Once very nice property in using on-chip CDC implementation (as opposed to external FTDI chip), is that you can ignore baudrate completely -- so user will be able to talk to your device no matter which speed they choose in putty settings.

• Thanks! I will give the DTR pin on the FT232RL a go. Unfortunately, I need the FT232 to interface with another IC on the board for which I have no other means of communication in order to upgrade it's firmware. – t3ddftw Oct 1 at 3:08
• @t3ddftw - if you implement USB directly in your MCU you could also implement a USB to serial bridge on behalf of that other target on the board. – Chris Stratton Oct 1 at 3:32
• @ChrisStratton - That's something I hadn't really put much thought into. I'll definitely have a look at that as it could save me a decent amount of parts on the BOM. Thanks! – t3ddftw Oct 1 at 15:14

I don't think you can rely on the handshaking lines to signal that a user is connected to a serial port. I don't think I've ever made a serial cable with more than RX, TX and GND. You will probably have to wait for the user to hit a key, then respond to that with your banner.

• OP does not have a serial port, they have FT232RL controller. So no serial cables are involved, and there is no opportunity for end user to omit any signals. – theamk Oct 1 at 1:59
• Regardless of wiring, the host's issuance of USB operations to set modem control signals, while typical, is not truly deterministic unless you control it's software stack. – Chris Stratton Oct 1 at 2:52

Use DTR that's what it's for!

All regular terminal software will raise DTR.

It's true that the OS (and even application software) can manipulate the DTR signal, but unless there is some vulnerability exposed by having them connected while DTR is not asserted there will be no motivation to de-assert DTR, an no problem caused by that ability.

Many terminal softwares can briefly disable DTR by pressing a hot-key (traditionally alt-h for "hang-up")