Problem in communicating with the serial printer

Discussion in 'Windows Vista Drivers' started by hari, Feb 23, 2007.

  1. hari

    hari Guest

    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()




    HANDLE hCOM;
    DWORD dwError,dwEr1 ;

    hCOM = CreateFile( lpFileName, //PrinterPort
    GENERIC_READ | GENERIC_WRITE, //Read &
    write
    0, //Share Mode
    NULL, //Security Handle
    OPEN_EXISTING, //Open the existing
    0,//FILE_ATTRIBUTE_NORMAL| FILE_FLAG_OVERLAPPED, //
    Overlapped
    NULL );
    dwError = GetLastError();

    if (hCOM == INVALID_HANDLE_VALUE)
    {
    DWORD dwError = GetLastError();
    TRACE("Open failed, error code %d\n", dwError);
    return FALSE;
    }
    COMMTIMEOUTS CommTimeOuts;
    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);
    AfxMessageBox("fail");
    }
     
    hari, Feb 23, 2007
    #1
    1. Advertisements

  2. I m doing these things to get some information from printer . In my
    Serial-attached device cannot be queried for this information, since, if this
    information is not known on the host side, the communication will fail.

    So, the idea is to start with a well-known config - like 9600-8N1 - and then
    design the commands to tweak the serial speed up. The device will tweak it up
    due to the command, the host - by itself, then - re-handshake on raised speed.
     
    Maxim S. Shatskih, Feb 23, 2007
    #2
    1. Advertisements

  3. hari

    hari Guest

    hi
    What you are saying is that, the configure port settings in my
    driver and printer settings should match.the configure port settings
    in my driver and printer settings are sam baud rate 9600 ,8,n,1.
    But why it is working when I enable and disable the com
    ports in the device manager.
     
    hari, Feb 23, 2007
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.