WinXP: Error 1167 -- Device (LPT1) not connected

Posted by Thomas Matthews on Super User See other posts from Super User or by Thomas Matthews
Published on 2010-04-07T18:08:17Z Indexed on 2010/04/07 18:13 UTC
Read the original article Hit count: 1122

I am writing a program that opens LPT1 and writes a value to it. The WriteFile function is returning an error code of 1167, "The device is not connected".

The Device Manager shows that LPT1 is present. I have a cable connected between a development board and the PC. The cable converts JTAG pin signals to signals on the parallel port.

Power is applied and the cable is connected between the development board and the PC. The development board is powered on.

I am using: Windows XP MS Visual Studio 2008, C language, console application, debug environment.

Here is the relevant code fragments:

HANDLE  parallel_port_handle;

void
initializePort(void)
{
    TCHAR * port_name = TEXT("LPT1:");
    parallel_port_handle = CreateFile( port_name,
                    GENERIC_READ | GENERIC_WRITE,
                    0,    // must be opened with exclusive-access
                    NULL, // default security attributes
                    OPEN_EXISTING, // must use OPEN_EXISTING
                    0,    // not overlapped I/O
                    NULL  // hTemplate must be NULL for comm devices
                    );

   if (parallel_port_handle == INVALID_HANDLE_VALUE) 
   {
       // Handle the error.
       printf ("CreateFile failed with error %d.\n", GetLastError());
       Pause();
       exit(1);
   }

    return;
}

void writePort( unsigned char a_ucPins, unsigned char a_ucValue )
{
    DWORD       dwResult;

    if ( a_ucValue ) {
        g_siIspPins = (unsigned char) (a_ucPins | g_siIspPins);
    }
    else {
        g_siIspPins = (unsigned char) (~a_ucPins & g_siIspPins);
    }

        /* This is a sample code for Windows/DOS without Windows Driver. */
//  _outp( g_usOutPort, g_siIspPins );

    //----------------------------------------------------------------------
    //  For Windows XP and later
    //----------------------------------------------------------------------
    if(!WriteFile (parallel_port_handle, &g_siIspPins, 1, &dwResult, NULL))
    {
        printf("Could not write to LPT1 (error %d)\n", GetLastError());
        Pause();
        return;
    }
}

If you believe this should be posted on Stack Overflow, please migrate it over (thanks).

© Super User or respective owner

Related posts about windows-xp

Related posts about parallel-port