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