Hi all,
I just developed a console application, the codes are as follows. But when i
execute the application the parallel port pins are not set with the voltage,
is there anything wrong i am doing? I am measuring the voltage between the
data pins and ground, but no change in voltage level.
Pentium M, 82855gme, 82801dbm chipsets
Super i/o: W83627HF

Regards,
Sankarraj

#include "stdafx.h"
int write_byte(HANDLE);
int blink(HANDLE);

int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
HANDLE lpt_port_handle;
DWORD error_handle, no_of_bytes_to_write;
BYTE write_val;
int menu;
//write_val = 0x7F;
no_of_bytes_to_write=1;
lpt_port_handle = CreateFile(L"LPT1:",
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_SYSTEM,
NULL);
error_handle = GetLastError();
if (error_handle != 0){
printf("Error in opening an handle to LPT port\n");
return 0;
}
if ((DWORD)error_handle == (DWORD)INVALID_HANDLE_VALUE){
printf("Error INVALID_HANDLE_VALUE \n");
return 0;
}
while (1){
printf("Application to test Parallel port Data pins\n");
printf("1. Write a Byte in parallel port\n");
printf("2. Toggle a bit\n");
printf("3. Exit\n");
printf("Your choice:");
scanf("%d", &menu);
if (menu == 1)
write_byte(lpt_port_handle);
else if (menu == 2)
blink(lpt_port_handle);
else if (menu == 3){
CloseHandle(lpt_port_handle);
return 0;
}
else
printf("Invalid selection try again\n");
}
return 0;


}


int write_byte(HANDLE lpt_port_handle)
{
DWORD no_bytes_written;
BYTE write_val;
int write_val_int,j;
BOOL error_val;
//write_val = 0x7F;
//no_of_bytes_to_write=1;

printf("\nEnter an hexa value to write in Parallel port:");
scanf("%X", &write_val_int);
printf("\nThe value that has been write on the parallel port is
%X\n",write_val_int);
if (write_val_int>0xff){
printf("Invalid value entered-Enter below 0xff\n");
return 0;
}
write_val=(BYTE) write_val_int;

error_val = WriteFile(lpt_port_handle,
&write_val,
1,
&no_bytes_written,
NULL);

printf("\nerror_val %d\n",error_val);
printf("\nThe value that has been write is %d\n",write_val_int);

for (j=0;j<8;j++){
if (write_val_int % 2 == 0)
printf("LED%d=0\n",j);
else
printf("LED%d=1\n",j);

write_val_int=write_val_int/2;
}


Sleep(900);
CloseHandle(lpt_port_handle);
return 0;
}

int blink(HANDLE lpt_port_handle)
{
DWORD no_bytes_written;
BYTE write_val, temp=0;
int data_bit,j,i;
printf("\nEnter the data pin to be toggled in parallel port(0 to 7):");
scanf("%X", &data_bit);
if (data_bit>7){
printf("Invalid value entered-Enter below 8\n");
return 0;
}
//write_val=(BYTE) write_val_int;
write_val = 1 << data_bit;
for (i=0;i<50;i++){
if (i%2 == 0){
WriteFile(lpt_port_handle,
&write_val,
1,
&no_bytes_written,
NULL);

Sleep(250);
}
else{
WriteFile(lpt_port_handle,
&temp,
1,
&no_bytes_written,
NULL);

Sleep(250);
}
}

CloseHandle(lpt_port_handle);
return 0;
}

Re: parallel port testing by Valter

Valter
Wed Feb 06 03:29:13 PST 2008

=?Utf-8?B?U2Fua2FycmFq?= <Sankarraj@discussions.microsoft.com> wrote
in news:53FF0159-508A-4DDA-8DE9-F91E157B30C2@microsoft.com:

> Hi all,
> I just developed a console application, the codes are as follows.
> But when i execute the application the parallel port pins are not
> set with the voltage, is there anything wrong i am doing? I am
> measuring the voltage between the data pins and ground, but no
> change in voltage level. Pentium M, 82855gme, 82801dbm chipsets
> Super i/o: W83627HF

You test the error in a wrong way.
Check that the returned handle is valid (!=INVALID_HANDLE_VALUE) and
then call GetLastError to know the error code.

--
Valter Minute
www.fortechembeddedlabs.it
Training, support and development for Windows CE
(the reply address of this message is invalid)

Re: parallel port testing by Sankarraj

Sankarraj
Thu Feb 07 04:06:00 PST 2008

Hi Valter,
I tested as per you suggested, there is no error in opening the handle to
the lpt1 port, if i gave lpt2 or something like that, i am getting invalid
handle error.
I looked into the parallel port driver it seems that it is talking to the
printer, so is that the reason that the application is failing?
I tested the parallel port with printer too, it is working fine, i wanted to
develop an application for testing parallel port, is it possible?

"Valter Minute" wrote:

> =?Utf-8?B?U2Fua2FycmFq?= <Sankarraj@discussions.microsoft.com> wrote
> in news:53FF0159-508A-4DDA-8DE9-F91E157B30C2@microsoft.com:
>
> > Hi all,
> > I just developed a console application, the codes are as follows.
> > But when i execute the application the parallel port pins are not
> > set with the voltage, is there anything wrong i am doing? I am
> > measuring the voltage between the data pins and ground, but no
> > change in voltage level. Pentium M, 82855gme, 82801dbm chipsets
> > Super i/o: W83627HF
>
> You test the error in a wrong way.
> Check that the returned handle is valid (!=INVALID_HANDLE_VALUE) and
> then call GetLastError to know the error code.
>
> --
> Valter Minute
> www.fortechembeddedlabs.it
> Training, support and development for Windows CE
> (the reply address of this message is invalid)
>