How to SET and RESET DTR line of COM port

0fdaeb6c6e513679f21b8f87c6266324
0
Radioengineer 101 Aug 25, 2005 at 05:32

Hi All !
Im an electronics engineer and im going to develop an aplication which will control external device. For this purpose i have to change a state of DTR line programmaticaly. I do all, But the state of line stands unchanged. I include my programm. Please hep me if you can.HANDLE hCom = CreateFile( “COM1:”,
GENERIC_READ | GENERIC_WRITE,
0, // must be opened with exclusive-access
NULL, // no security attributes
OPEN_EXISTING, // must use OPEN_EXISTING
0, // not overlapped I/O
NULL // hTemplate must be NULL for comm devices
);

if (hCom == INVALID_HANDLE_VALUE)
{
ShowMessage(“Port is not open !!!”);
}
else
{
ShowMessage(“Port open”);
}
DCB PortDCB;

PortDCB.DCBlength = sizeof (DCB);

// Get the default port setting information.
GetCommState (hCom, &PortDCB);

PortDCB.BaudRate = 9600; // Current baud
PortDCB.fDtrControl = DTR_CONTROL_ENABLE; // DTR flow control type
PortDCB.ByteSize = 8; // Number of bits/byte, 4-8
PortDCB.Parity = NOPARITY; // 0-4=no,odd,even,mark,space
PortDCB.StopBits = ONESTOPBIT; // 0,1,2 = 1, 1.5, 2

if (!SetCommState (hCom, &PortDCB))
{
ShowMessage(“Unable to configure the serial port”);

}
COMMTIMEOUTS cto;
cto.ReadIntervalTimeout = 0;
cto.ReadTotalTimeoutMultiplier = 0;
cto.ReadTotalTimeoutConstant = 0;
cto.WriteTotalTimeoutMultiplier = 0;
cto.WriteTotalTimeoutConstant = 0;
SetCommTimeouts (hCom, &cto);

//Then im trining to chanege potr state by the EscapeCommFunction
EscapeCommFunction(hCom, SETDTR); //To Set DTR
EscvapeCommFunction(hCom, CLRDTR); //To reset DTR
//Function returns true and i dont get any complier error. But port state remanis unchangeable. (always + 12 V)

//i close port by CloseHandle(hCom);

Thanks in advance !

0 Replies

Please log in or register to post a reply.

No replies have been made yet.