Click to See Complete Forum and Search --> : COM Port


sammy1977
August 20th, 2007, 03:47 PM
I want to be able to set/reset the DTR signal on the serial port from C++. Has anyone done this before? I don't need to send any data just be able to turn on and off the DTR pin.

greve
August 24th, 2007, 06:20 AM
That's a member of a class I once have written to wrap RS232-functionality.
m_hdl is the HANDLE you retrieve from CreateFile.

Best Regards, Thomas


void CRS232::SwitchDTRLine(bool ToBeSwitchedOn)
{
DCB CurrDCB;

GetCommState(m_hdl, &CurrDCB);
CurrDCB.fDtrControl=
ToBeSwitchedOn
?
DTR_CONTROL_ENABLE
:
DTR_CONTROL_DISABLE
;
SetCommState(m_hdl, &CurrDCB);
}