Problem in communicating with the serial printer

Hi all,

I have connected my printer in com port(com1), and create a handle
to the com port using createfile function to which the printer is
connected.I checked the handle returned by CreateFile() for
INVALID_HANDLE_VALUE,it is ok.But the function GetCommState(hCOM,
&dcb),Setcommtimeouts are failing.
But once I disable and enable the com ports in the device manager
manually,the functions GetCommState(hCOM, &dcb),Setcommtimeouts are
getting succeded. T his also works until I delete the printer driver /
restart the system,if
I install again, I need to disable and enable the com ports in device
manager manually.
One more observation I found is, when I change to other com
ports(filename) in createfile in which the printer is not connected,the
functions GetCommState(hCOM, &dcb),Setcommtimeouts are getting succeded.

How can I solve this problem? It should work fine when I install the
printer.(no disable and enable should be there).

I m doing these things to get some information from printer . In my
printer I can set the baud rate,data bits etc… in the printer ,now I
need to query the printer about the baud rate and data bits set in the
printer and need to display it in the User interface.

My code for createfile and getcommstate()

DWORD dwError,dwEr1 ;

hCOM = CreateFile( lpFileName, //PrinterPort
0, //Share Mode
NULL, //Security Handle
OPEN_EXISTING, //Open the existing
dwError = GetLastError();

DWORD dwError = GetLastError();
TRACE(“Open failed, error code %d\n”, dwError);
return FALSE;
CommTimeOuts.ReadIntervalTimeout = 0xFFFFFFFF;
CommTimeOuts.ReadTotalTimeoutMultiplier = 0;
CommTimeOuts.ReadTotalTimeoutConstant = 0;
CommTimeOuts.WriteTotalTimeoutMultiplier = 0;
CommTimeOuts.WriteTotalTimeoutConstant = 5000; dwError =
SetCommTimeouts( hCOM, &CommTimeOuts ); dwError = GetLastError();

if (!GetCommState(hCOM, &dcb))
TRACE(“Open failed, error code %d\n”, dwError);

Questions? First check the Kernel Driver FAQ at

To unsubscribe, visit the List Server section of OSR Online at