Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ReadFile Error code 1 for parallel port reading.

Posted on 2004-08-11
6
Medium Priority
?
525 Views
Last Modified: 2011-09-20
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;
      }
=============================================
0
Comment
Question by:sakee
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 11

Expert Comment

by:lbertacco
ID: 11770791
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)
0
 

Author Comment

by:sakee
ID: 11790159
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?

0
 
LVL 11

Expert Comment

by:lbertacco
ID: 11790615
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)?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:sakee
ID: 11807179
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?

0
 

Author Comment

by:sakee
ID: 11807185
One thing is that it is difficult to learn to use the DDK for this. There is no examples available.
0
 
LVL 11

Accepted Solution

by:
lbertacco earned 200 total points
ID: 11807374
If the book clearly says that that should work and provides source code try asking confirmation to the author (I still don't belive it can possibily work). I'm not an expert with DDK, so I can't help you with that.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Starting up a Project

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question