Solved

ReadFile Error code 1 for parallel port reading.

Posted on 2004-08-11
6
504 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
  • 3
  • 3
6 Comments
 
LVL 11

Expert Comment

by:lbertacco
Comment Utility
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
Comment Utility
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
Comment Utility
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:sakee
Comment Utility
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
Comment Utility
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 100 total points
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
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…

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now