Link to home
Start Free TrialLog in
Avatar of sakee
sakee

asked on

ReadFile Error code 1 for parallel port reading.

I am trying to run a program to read from the parallel port. The following is the beginning of the program, and when I try to do the ReadFile( ) function, there is an error message of code 1. Anyone know why is it so?

=============================================
      hDevice =
            CreateFile("\\\\.\\LPT1",
                              GENERIC_READ | GENERIC_WRITE,
                              0,            // share mode none
                              NULL,      // no security
                              OPEN_EXISTING,
                              FILE_ATTRIBUTE_NORMAL,
                              NULL );            // no template
      printf("Attempting to read from device...\n");
      char inBuffer[80];
      DWORD inCount = sizeof(inBuffer);
      DWORD bR;
      status = ReadFile(hDevice, inBuffer, inCount, &bR, NULL);
      if (status==0) {
            printf("Failed on call to ReadFile - error: %d\n",
                  GetLastError() );
            return 4;
      }
=============================================
Avatar of lbertacco
lbertacco

Despite the fact that SPP/EPP/ECP parallel ports support bidirectional communication, I don't think that just accessing them via the LPT device supports bidir communication and you are limited to unidirectional (output only) communication (I'm not sure about WinXP).

For lower level access to the parallel port you should refere to the Windows DDK. Have a look at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/parallel/hh/parallel/sspd_73eda256-542a-4967-8b5f-183f45723b1d.xml.asp
and
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/parallel/hh/parallel/cisspd_a108ba77-8f01-436e-bc7a-48a74f80ac75.xml.asp

Or use third party drivers (http://www.fapo.com/1284tkit.htm)
Avatar of sakee

ASKER

Thanks lbertacco for replying.

I am using the sample codes from the book "Windows® 2000 Device Driver Book: A Guide for Programmers, Second Edition, By Art Baker, Jerry Lozano" to learn about the parallel port communication and develop a usbale application. So I assume it should be working well.

Now I am disappointed with the book, so I would llike to learn about the parallel port access recommended by the msdn site but I am wondering how much time will it take. Have you any idea on the learning curve and implementation?

Well if the book is about device drivers , it probably covers the DDK. Anyway I'm not sure you can't do what you are doing. Bidir parallel communication was not supported by the OS some years ago (when I have programmed them a bit), but now things may have changed, so if that book says it's possibile, I guess it is.
It may fail for other reasons too: e.g. are you using a recent enough version of windows (Win2k/XP)? Do you have an ECP parallel port and have you configured it in ECP mode (in the BIOS)?
Avatar of sakee

ASKER

Just tried all the available parallel port mode in the BIOS (ECP, EPP, PS/2, AT). All give the same error message. There is not much detail regarding this in the book. Think I am stuck.

Any other suggestions?

Avatar of sakee

ASKER

One thing is that it is difficult to learn to use the DDK for this. There is no examples available.
ASKER CERTIFIED SOLUTION
Avatar of lbertacco
lbertacco

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial