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 !
How to SET and RESET DTR line of COM port
Started by Radioengineer, Aug 25 2005 05:32 AM
No replies to this topic
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











