Hi folks,
I try to write to the LPT Port under win2000.
There for I use the CreateFile and WriteFile API-Functions.
I can open the Port but when I want to write to it, the programm is hanging. The amazing thing is .. when I use the COM1 port instead of LPT1 with the same Parameters, everything is working fine.
Is it possible that win2000 doesn't support LPT communication anymore???
Here's my little test-programm
//----------------------------------------------------------
#include "stdafx.h"
#include #include #include HANDLE hndDevice;
int initPort(void)
{
hndDevice = CreateFile( "LPT1", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_WRITE_THROUGH , NULL );
if (hndDevice == INVALID_HANDLE_VALUE)
{
printf("Port couldn't be opend: %li
",GetLastError() );
return (-1);
}
printf("Port has been opend...
");
return(1);
}
/**********************************************************************
* Write-Function
* Here's the Problem The Programm is hanging when trying to write
*******************************************************************/
int writePort(BYTE send_data)
{
unsigned int data; // daten to send
unsigned long bytesWritten; // number of bytes written
BOOL status;
data = send_data;
//char xData[3]; //testdaten
//xData[0]=1; //testdaten
//xData[1]=2; //testdaten
//xData[2]=3; //testdaten
status = WriteFile( hndDevice, &data, sizeof(data), &bytesWritten, NULL );
printf("Status : %d
", status);
printf("Number of Bytes written: %d
", bytesWritten);
if (status == 0)
{
printf("error while writing:%li
",GetLastError() );
}
return(1);
}
int closePort(void)
{
CloseHandle(hndDevice);
printf("Port has been closed...");
return(1);
}
int main(int argc, char* argv[])
{
initPort();
writePort(24);
closePort();
return 0;
}
Comments
I am not familiar with this function. Why is 0 there? My understanding
NULL really is the same as assigning 0.
Please let me know.
Thanks
Bryce
: Hi folks,
: I try to write to the LPT Port under win2000.
: There for I use the CreateFile and WriteFile API-Functions.
: I can open the Port but when I want to write to it, the programm is hanging. The amazing thing is .. when I use the COM1 port instead of LPT1 with the same Parameters, everything is working fine.
:
: Is it possible that win2000 doesn't support LPT communication anymore???
:
: Here's my little test-programm
:
: //----------------------------------------------------------
: #include "stdafx.h"
: #include
: #include
: #include
:
: HANDLE hndDevice;
:
: int initPort(void)
: {
: hndDevice = CreateFile( "LPT1", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_WRITE_THROUGH , NULL );
:
: if (hndDevice == INVALID_HANDLE_VALUE)
: {
: printf("Port couldn't be opend: %li
",GetLastError() );
: return (-1);
: }
:
: printf("Port has been opend...
");
: return(1);
: }
:
: /**********************************************************************
: * Write-Function
: * Here's the Problem The Programm is hanging when trying to write
: *******************************************************************/
: int writePort(BYTE send_data)
: {
: unsigned int data; // daten to send
: unsigned long bytesWritten; // number of bytes written
: BOOL status;
: data = send_data;
:
: //char xData[3]; //testdaten
: //xData[0]=1; //testdaten
: //xData[1]=2; //testdaten
: //xData[2]=3; //testdaten
:
: status = WriteFile( hndDevice, &data, sizeof(data), &bytesWritten, NULL );
:
: printf("Status : %d
", status);
: printf("Number of Bytes written: %d
", bytesWritten);
:
: if (status == 0)
: {
: printf("error while writing:%li
",GetLastError() );
: }
:
: return(1);
: }
:
: int closePort(void)
: {
: CloseHandle(hndDevice);
: printf("Port has been closed...");
: return(1);
: }
:
: int main(int argc, char* argv[])
: {
:
:
:
: initPort();
: writePort(24);
: closePort();
: return 0;
: }
:
:
:
:
:
I am not familiar with this function. Why is 0 there? My understanding
NULL really is the same as assigning 0.
Please let me know.
Thanks
Bryce
: Hi folks,
: I try to write to the LPT Port under win2000.
: There for I use the CreateFile and WriteFile API-Functions.
: I can open the Port but when I want to write to it, the programm is hanging. The amazing thing is .. when I use the COM1 port instead of LPT1 with the same Parameters, everything is working fine.
:
: Is it possible that win2000 doesn't support LPT communication anymore???
:
: Here's my little test-programm
:
: //----------------------------------------------------------
: #include "stdafx.h"
: #include
: #include
: #include
:
: HANDLE hndDevice;
:
: int initPort(void)
: {
: hndDevice = CreateFile( "LPT1", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_WRITE_THROUGH , NULL );
:
: if (hndDevice == INVALID_HANDLE_VALUE)
: {
: printf("Port couldn't be opend: %li
",GetLastError() );
: return (-1);
: }
:
: printf("Port has been opend...
");
: return(1);
: }
:
: /**********************************************************************
: * Write-Function
: * Here's the Problem The Programm is hanging when trying to write
: *******************************************************************/
: int writePort(BYTE send_data)
: {
: unsigned int data; // daten to send
: unsigned long bytesWritten; // number of bytes written
: BOOL status;
: data = send_data;
:
: //char xData[3]; //testdaten
: //xData[0]=1; //testdaten
: //xData[1]=2; //testdaten
: //xData[2]=3; //testdaten
:
: status = WriteFile( hndDevice, &data, sizeof(data), &bytesWritten, NULL );
:
: printf("Status : %d
", status);
: printf("Number of Bytes written: %d
", bytesWritten);
:
: if (status == 0)
: {
: printf("error while writing:%li
",GetLastError() );
: }
:
: return(1);
: }
:
: int closePort(void)
: {
: CloseHandle(hndDevice);
: printf("Port has been closed...");
: return(1);
: }
:
: int main(int argc, char* argv[])
: {
:
:
:
: initPort();
: writePort(24);
: closePort();
: return 0;
: }
:
:
:
:
: