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;
}

Re: (Parallel Port) Why cannot output data to LPT port ? by Luca

Luca
Thu May 15 22:56:09 PDT 2008

Since you are setting all the (write) timeouts to 0, WriteFile will exit
with TRUE only when it writes the # of bytes you requested;
Looks likeyou are telling WriteFile to write 0 bytes...

--

Luca Calligaris
www.eurotech.it

"dirw" <dirwdirw.tw@yahoo.com.tw> ha scritto nel messaggio
news:5f1c8d53-4823-4c08-973a-025f2615b38f@d19g2000prm.googlegroups.com...
> 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;
> }



Re: (Parallel Port) Why cannot output data to LPT port ? by dirw

dirw
Tue May 20 03:23:37 PDT 2008

Dear Sir,

I already modify my source code to update following.

MyCommTimeouts.ReadIntervalTimeout = 1000;
MyCommTimeouts.ReadTotalTimeoutConstant = 1000;
MyCommTimeouts.ReadTotalTimeoutMultiplier = 1000;
MyCommTimeouts.WriteTotalTimeoutConstant = 1000;
MyCommTimeouts.WriteTotalTimeoutMultiplier = 1000;

But the result is the same.

Do you have any suggestion ?

BR,
Wiles

Error Message :
==========================
Open LPT port OK
GetCommState OK
SetCommState OK
GetCommTimeouts OK
SetCommState OK
WriteFile OK
WriteFile --> 0 Byte