Connecting to serial port activates DTR without asking

Windows specific forum
paulr
User
User
Posts: 68
Joined: Sat Sep 27, 2003 2:53 pm

Connecting to serial port activates DTR without asking

Post by paulr »

I'm seeing some strange behaviour while connecting to a serial port and want to see if anyone can help.

I'm working in Windows with an Arduino clone (RF-Nano type). Arduinos use a high-to-low transition of the DTR pin on their USB-TTL converters to reset them. So if I want to connect to an Arduino and immediately reset it, I can do this in PureBasic with:

Code: Select all

OpenSerialPort(0, "COM4", 9600, #PB_SerialPort_NoParity, 8, 1, #PB_SerialPort_NoHandshake, 32, 32)
SetSerialPortStatus(0, #PB_SerialPort_DTR, 1)
0=high and 1=low with serial ports, so setting DTR to 1 brings the DTR pin low, resetting the device.

Sometimes I want to be able to connect to the Arduino without resetting it. This should mean keeping the DTR pin high (DTR=0), by not calling SetSerialPortStatus at all.

However I've been getting mixed results. A freshly programmed Arduino responds exactly as expected - no SetSerialPortStatus, no reset. However if I unplug and reconnect the same Arduino, running OpenSerialPort alone sends the DTR pin low, resetting the Arduino. If I program it again with the IDE, all is fine.

Obviously I've tried:

Code: Select all

OpenSerialPort(0, "COM4", 9600, #PB_SerialPort_NoParity, 8, 1, #PB_SerialPort_NoHandshake, 32, 32)
SetSerialPortStatus(0, #PB_SerialPort_DTR, 0)
But the delay between the two commands is long enough to trigger a reset.

My best guess at what's happening is this: Physically connecting the device to the computer initialises the driver with DTR low. When PureBasic connects to the device, the DTR low is pushed to the device as it connects, resetting it. Programming the Arduino leaves the driver in the DTR high state, so PB can connect to it without the reset.

Is it possible in Purebasic to set the DTR state to high before connecting to the port?