Dear Sir,
I use WINCE 5.0/6.0 ro develop my project which have a parallel port.
I reference http://support.microsoft.com/default.aspx?scid=kb;EN-US;823179
to develop a program to output data to LPT port.
But system always cannot output data.
Error Message :
==========================
Open LPT port OK
GetCommState OK
SetCommState OK
GetCommTimeouts OK
SetCommState OK
WriteFile OK
WriteFile --> 0 Byte
Do anyone have idea about this issue ?
BR,
Wiles
The following is my source code.
//----------------------------------------------------------
#include "stdafx.h"
#include "resource.h"
#include <windows.h>
#include <stdio.h>
#include <string.h>
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
HANDLE hParallelPort = NULL;;
DCB MyDCB;
COMMTIMEOUTS MyCommTimeouts;
char String_data = 'A';
DWORD BytesWritten = 0;
DWORD dwRead = 0;
char buf[] = "Test";
char new_buf[] = "";
RETAILMSG(1, (_T("==========================\r\n")));
// hParallelPort = CreateFile(TEXT("LPT1:"), GENERIC_READ Or
GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
hParallelPort = CreateFile(TEXT("LPT1:"),GENERIC_READ | GENERIC_WRITE,
0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
if(hParallelPort == NULL)
{
RETAILMSG(1, (_T("Open LPT port Fail\r\n")));
}
else
{
RETAILMSG(1, (_T("Open LPT port OK\r\n")));
}
if(!GetCommState(hParallelPort, &MyDCB))
{
RETAILMSG(1, (_T("GetCommState Fail\r\n")));
}
else
{
RETAILMSG(1, (_T("GetCommState OK\r\n")));
}
MyDCB.BaudRate = 9600;
MyDCB.ByteSize = 8;
MyDCB.Parity = NOPARITY;
MyDCB.StopBits = ONESTOPBIT ;
if(!SetCommState(hParallelPort, &MyDCB))
{
RETAILMSG(1, (_T("SetCommState Fail\r\n")));
}
else
{
RETAILMSG(1, (_T("SetCommState OK\r\n")));
}
if(!GetCommTimeouts(hParallelPort, &MyCommTimeouts))
{
RETAILMSG(1, (_T("GetCommTimeouts Fail\r\n")));
}
else
{
RETAILMSG(1, (_T("GetCommTimeouts OK\r\n")));
}
MyCommTimeouts.ReadIntervalTimeout = 0;
MyCommTimeouts.ReadTotalTimeoutConstant = 0;
MyCommTimeouts.ReadTotalTimeoutMultiplier = 0;
MyCommTimeouts.WriteTotalTimeoutConstant = 0;
MyCommTimeouts.WriteTotalTimeoutMultiplier = 0;
if(!SetCommTimeouts(hParallelPort, &MyCommTimeouts))
{
RETAILMSG(1, (_T("SetCommState Fail\r\n")));
}
else
{
RETAILMSG(1, (_T("SetCommState OK\r\n")));
}
if(!WriteFile(hParallelPort, buf, strlen(buf), &BytesWritten, 0))
{
RETAILMSG(1, (_T("WriteFile Fail\r\n")));
}
else
{
RETAILMSG(1, (_T("WriteFile OK\r\n")));
}
RETAILMSG(1, (_T("WriteFile --> %dByte\r\n"),BytesWritten));
CloseHandle(hParallelPort);
return 0;
}