CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Feb 2005
    Posts
    64

    Lightbulb Parallel Port Programming

    Hello guys !

    Alright, let's go straight to the point from here.

    I am having trouble figuring out how to control the parallel port and whether c++ can do the job ? My purpose is pretty simple, that is just to have the ability to switch on and off for 8 LEDs through a PC's Parallel port with a form of buttons of my own designed in microsoft windows XP.

    I hope to get a thorough understanding of how many volt each tiny pin can produce or all about the parallel port.. Please guide me on where to start. And of course, the most importantly how to go about it. Thankyou

  2. #2
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: Parallel Port Programming

    The file input and output (I/O) functions ('CreateFile()', 'CloseHandle()', 'ReadFile()', 'ReadFileEx()', 'WriteFile()' and 'WriteFileEx()') provide the basic interface for opening and closing a communications resource handle and for performing read and write operations. Depending of what you are trying to do take also a look at the following functions...
    Code:
    // Parallel Device Callback Routines
    
    USHORT *DetermineIeeeModes(IN PDEVICE_EXTENSION Extension)
    
    NTSTATUS *IeeeFwdToRevMode(IN PDEVICE_EXTENSION Extension)
    
    NTSTATUS *IeeeRevToFwdMode(IN PDEVICE_EXTENSION Extension)
    
    NTSTATUS *NegotiateIeeeMode(IN PDEVICE_EXTENSION Extension,
                                IN USHORT ModeMaskFwd,
                                IN USHORT ModeMaskRev,
                                IN PARALLEL_SAFETY ModeSafety,
                                IN BOOLEAN IsForward)
    
    NTSTATUS *ParallelRead(IN PDEVICE_EXTENSION Extension,
                           IN PVOID Buffer,
                           IN ULONG NumBytesToRead,
                           OUT PULONG NumBytesRead,
                           IN UCHAR Channel)
    
    NTSTATUS *ParallelWrite(IN PDEVICE_EXTENSION Extension,
                            OUT PVOID Buffer,
                            IN ULONG NumBytesToWrite,
                            OUT PULONG NumBytesWritten,
                            IN UCHAR Channel)
    
    NTSTATUS *TerminateIeeeMode(IN PDEVICE_EXTENSION Extension)
    
    
    // Parallel Port Callback Routines
    
    NTSTATUS *ClearChipMode(IN PDEVICE_EXTENSION Extension, IN UCHAR ChipMode)
    
    NTSTATUS *DeselectDevice(IN PVOID Context, IN PVOID DeselectCommand)
    
    VOID *FreePort(IN PVOID Context)
    
    VOID *FreePortFromInterruptLevel(IN PVOID Context)
    
    ULONG *QueryNumWaiters(IN PVOID Extension)
    
    BOOLEAN *TryAllocatePort(IN PVOID Context)
    
    BOOLEAN *TryAllocatePortAtInterruptLevel(IN PVOID Context)
    
    NTSTATUS *TrySelectDevice(IN PVOID Context, IN PVOID TrySelectCommand)
    
    NTSTATUS *TrySetChipMode(IN PDEVICE_EXTENSION Extension, IN UCHAR ChipMode)
    All functions are coming from the Windows DDK (Driver Development Kit). For further information look within the MSDN (http:// msdn.microsoft.com)...

  3. #3
    Join Date
    Feb 2005
    Posts
    5

    Re: Parallel Port Programming

    Hi, this is my first post here, so hello everybody.
    I am having the same trouble, which I haven't been able to solve. I tried some drivers, but they only work if I have admin rights (Im using Win2k, and developing under Buidler C++). I can make the user to install my app with admin rights (just once), but then my app has to run without admin rigths. I dont know very much about Windows driver's programming, so I am looking for a easy solution (I think I can't write a driver by my own.) In fact, if I run my app as admin, then close session (not reboot) and run my app as user it works. It seems that the driver is loaded.
    The functions CreateFile(), WriteFile(), etc.. works fine if I specify \\\\.\\LPTx, but they try to print data!, while I just want to write/read some data to port.
    I would very very gratefull if someone can help me with a driver or something which can work both with or without admin rights.
    Thanks in advance!
    Greetings from Argentina...

    P/D: sorry about my english!

  4. #4
    Join Date
    Mar 2005
    Posts
    2

    Re: Parallel Port Programming

    The code to output voltage to the parallel port in C is:

    #include <conio.h>

    main
    {
    outp(0x378, 255);
    //or
    outportb(0x378, 255);
    }

    the binary of 255 is 11111111, which means pins 2-9 will output.
    you can turn them off with 0, or turn just pin 2 on with 1, or just pin 9 on with 128.

    You can use a 470 ohm resistor and led from pin 2 to 9, grounded to all pins 18 to 25.

    Search Parallel Port Programming in Google

  5. #5
    Join Date
    Feb 2005
    Posts
    5

    Re: Parallel Port Programming

    JRoger, your code only works under Win9X, but not any NT platform (NT, 2000, XP) as those Windows doesn't let you direct access to parallel ports (among other things).
    Regards,

  6. #6
    Join Date
    Mar 2004
    Location
    Bangalore,karnataka,India
    Posts
    13

    Arrow Re: Parallel Port Programming


  7. #7
    Join Date
    Apr 2006
    Posts
    2

    Re: Parallel Port Programming

    If you're still looking for a solution for Win2k \ WinXP I'm looking into it at the moment and hopefully will have a driver\dll\testapp.

  8. #8
    Join Date
    Nov 2005
    Posts
    32

    Re: Parallel Port Programming

    If You have some basic knowleges of w2k driver development, I think the example "PPort" from w2kdriverbook will help You:
    http://www.w2kdriverbook.com/downloads/Chap8/pport.zip

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured