-
May 4th, 2004, 10:09 AM
#1
There is nothing plugged on com1....???
Hi,
I have to check if in the port Com1 is puggled some device.
I had use this code and if the device is plugged it is work correctly but if there is nothing it don' t return nothing
Some advice???
....
hCom = CreateFile( port,
GENERIC_READ | GENERIC_WRITE,
0, // comm devices must be opened w/exclusive-access
NULL, // no security attributes
OPEN_EXISTING, // comm devices must use OPEN_EXISTING
0, // not overlapped I/O
NULL // hTemplate must be NULL for comm devices
);
if (hCom == INVALID_HANDLE_VALUE) {
dwError = GetLastError();
return E_OPENING;
}
...
-
May 4th, 2004, 01:31 PM
#2
If the device when connected to the Com1 port brings up Carrier (DCD), then you can check for it.
// Code example
BOOL CheckCarrier()
{
DWORD dwModemStatus = 0;
BOOL fDeviceCarrier = FALSE;
dwModemStatus = EV_RLSD;
// No DCD from Device
if((m_hComm==NULL) || (m_hComm==INVALID_HANDLE_VALUE))
{
return FALSE;
}
if(!GetCommModemStatus(m_hComm, &dwModemStatus))
{
// DCD still low;
}
else
{
// DCD is high from device
fDeviceCarrier = MS_RLSD_ON & dwModemStatus;
return fDeviceCarrier;
}
return FALSE;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|