For the students of electronics...

As a student of electronics I find that students in colleges don't have much time to learn the windows programming because they just manage to test their devices with small DOS based programs coded in C or C++ and concentrates on the electronics of their hardware. [Other reasons are also there ;) ] But after completing the hardware part they want to give it professional look by programming window based software for their hardware.

Students developing hardware can not get much help on programming side by their teacher (they both are just expert in electronics). The electronics magazines publishing such hardware projects also uses C and C++.

So, this article is for the hardware developer who have knowledge of C and C++ and who want to switch over to window based application for their device.

In this first part...

In this first part of HIPIVC++ we will see how to check the port continuously using timers. We will build a simple (and sample) dialog based application to check whether the Pin No. 10, 11, 12, 13, and 15 of LPT1 is high or low. I think it is a good starting point.

Start with Application Wizard

To Skip this section:

Just generate dialog based application with all default option if you are familiar with AppWizard or follow the procedure

From Control tool bar create five check box and caption them as Pin 10, Pin 11, Pin 12, Pin 13 and Pin 15. Also change IDs to IDC_PIN10, IDC_PIN11, IDC_PIN12, IDC_PIN13, IDC_PIN15 (note that we haven't use Pin 14 that is not for status port)

Size the dialog box if you need! You may also insert static text like "LPT 1" or "Status Port: 0x379" or your name.

Don't forget to save your work. The final dialog box should be as the screen shot given at top.

Add member variables

Now we will add member variables to check boxes which then changes their value according to high or low value of status pins of parallel port.

right click on any check box and click on ClassWizard... the class wizard dialog box will appear.

Select Member Variables tab if not. Project should be YourAppName and Class name should be CYourAppNameDlg

Final Coding

Here you will insert your code to input form the port and update the check box view according to the status of parallel port pins.

Click Class View tab on Workspace window, you will see YourAppName classes.

Right click on CYourAppNameDlg chose Add Member Variable...

Enter Variable Type as int and Variable Name as in379 it would assign value of port 0x379. Keep Access type as it is.(Public)

Same way add more five int variable for each pin and name them as nPin10, nPin11, nPin12, nPin13, nPin15

Now right click on CYourAppNameDlg class and chose Add Windows Message Handler... then from New windows messages/events list select WM_TIMER and click Add Handler button. The WM_TIMER will be inserted in Existing message/event handlers, select it there if not and click Edit Existing button.

Paste the code given below the bold part is generated automatically by Wizard but they can help you to find the proper place for pasting the code.

Complete. Now you may build and run the Parallel Port Status Check Version 1.0 (I am using the name PPSC for short)

How it works

This is very simple program which just inputs from the port. The _inp(unsigned short) function returns the value at the port whose number is passed to it. The SetTimer() is used to generate a timer event at every 2 millisecond. The OnTimer() catches the timer event and updates the check box. Initially (when the printer is not connected or DB-25 is open) the parallel port status pins should be at high logic except Pin 11 which is hardware inverted. So initially all check boxes except for Pin 11 should be checked.

You can see that in my screenshot image of PPSC, the Pin 10 is also at logic low it is because I have damaged this pin during developing some parallel port device. By the way I have found the fault and the solution for preventing other pins, but discussion of such problem is out of scope of this site. It is just for the hobbies who have chance to damage their parallel port. ;)

I will continue if you want...

It is all upon your feedback...

In next part I want to cover parallel port fully, and than I want to write for the serial port and USB. But again it is all upon your feedback...

See you in next part, Take care.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

Comments and Discussions

If you came to this article from Google because you are looking for a way to measure digital signals via parallel port then have a look at the following article: 17 Channel Logic Analyzer!

* Digital Oscilloscope / Logic Analyzer with up to 17 input lines* Uses the parallel (printer) port for input.* While Logic Analyzers normally are very expensive, this one is for zero cost* Written in speed optimized C++ to get the maximum possible sample rates* The program is a stand alone single EXE file which neither needs any additional DLLs nor any framework. It runs out of the box* Runs on all Windows platforms (95, 98, ME, NT, 2000, XP, 2003, Vista, 2008, Windows 7, 2008 R2)* Runs on 32 Bit Windows and 64 Bit Windows* When first run, installs a driver to access hardware IO ports on all NT platforms* Plays a sound via PC speaker to prove that the driver works correctly* Shows the actual state of the input lines life in the LED's of the GUI* Captures up to 500.000 samples / second (depending on your hardware and OS)* Captures to memory (rather than disk) for maximum speed* Capturing runs always with the maximum frequency that the hardware allows* Memory saving capture technology stores only the changes of the input lines rather than storing all lines with each sample that is taken* The capture process is independent of data analyzing so you can try various settings to display the captured data in the best way* The analyzer generates coloured oscilloscope diagrams with a raster grid* The output is written into an HTML file and one or multiple GIF files* So the analyzer results can easily be shared with other people who must not install any program to view a proprietary binary format* You can write an individual heading into each analyzer output to distinguish them later in a multitude of files* When analyzing data, you can choose to delete old analyzer output or keep the old files* The time axis shows absolute or relative time with microsecond precision (Performance Counter)* Automatic detection of inactive input lines shows only the channels that have activity* Automatic detection of idle time cuts out long phases of inactivity* Automatic detection of input frequency chooses the adequate raster unit like on a real oscilloscope (10 µs, 20 µs, 25 µs, 50 µs, 100 µs, etc..)* Automatic detection of context switches of the operating system* Decoding of serial protocols like I2C Bus, PS/2 Bus, SMBus, ModBus, SPI Bus, Asynchronous (RS232, RS422, RS485), Infrared Remote Controls, Smartcards is partially already implemented or may be added by you.* Decoded serial data (Start Bit, Parity, Acknowledge, Stop Bit) and the Byte that they represent is written into the diagram* Very cleanly written source code with a proper error handling and plenty of comments

I am working on on project. in that software works properly on win98 but the same program compiled in xp but not working or execut hole project as it execute in win98.what is the region behind it.Is this of problem of including prots in it becuse in that project we have to out through ports.And geting input from port. so please help me. give me region and solution of this.

Hi In Windows XP, 2000 and other 'recent' microsoft operating systems you have to hack the windows IO sub-system in order to access the ports. I found this out the hard way when I was working on a robotics project. MS seems to think that the public has no reason to directly control their own hardware... Try googling for something like 'hardware port access on XP' or something, that may be helpful

hi, i do project to control the led(light emiting diode) in the circuit. I expect to switch on the particular light at clicking the particular check box. The light is switched off when I take out off the tick mark from the particular check box .If I click the check box 1 and 4 means then they are only staying in the on condition.If I take out the 4th Ticks means then the remaining bulb 1 must be remaining in the on position.

This is the normal codings for check box.it is not worked .if anybody knows please send me

haloz! am a computer and electronics student.I have got no idea about the kinds of projects that I can design. Any body with ideas or websites which can help with insights about projects can feel free to help.

hi daygiri me quite new member.i belongs to A.K.Infact i m working on p[roject of home automation in order to design a device that controls the voltage level and developing its software as well.will u help me during my project? Also i have tried program for accessing parallel port but it gives runtime error....... me anxiously waiting for ur reply.

Thanks for the explanation. You explained how to enter the class wizard but I don't seem to get, what do you exactly mean by right click of check boxes? I can't find the option of entering the class wizard. Any further details will be very helpful. Thanks again.

i need to replace a printer for another computer to send the "output" of the lpt1 to a file.

I have some problems to read the data, status and control ports, I mean, i can't manage the busy and acknowledge in the second computer, in fact, i can't read what the first computer is sending to the printer. Could you please help me? or telling me what can i do for solve my problem?

Just few days back I got an opportunity to develop a tool in MFC which will fetch data from USB device(mouse,keyboard,dongles) and display it on the GUI.I am required to use windows HID class for the same.

Please help me out if you have any idea about this stuff.In case there is any specific set of APIs which are required to be invoked then please help me out.

Hi, I can read the input data from the parallel port. I have a thread that is reading continously the parallel port and updating a variable with the data.

I want to know if there is a better way to do it, because I need a quick response in my application (software side).

I have two push buttons connected to the parallel port (parallel port is already configured as bi-direccional) so, I want to detect the order in which I press the buttons, if the combination is correct it will display a message.

I'm facig a problem. One application is developed where we are taking a person's photograph programetically using a webcam. Now the problem is if the clients computer does not have a webcam it is showing an error. so my requirement is I want to write a code through which it will detect whether a device is attached to USB or not. I want to write it in VC++.

HelloI doubt the program would work gracefully. Windows will not allow user programs to access the hardware using Rin0 system calls like _inp(). This can be used only if the libraries which allow such Ring0 access are loaded while the system boots.

This program gives out a run-time error as and when it starts. I have tried the same in WinXP where levels of access are still more complex.Regards

The program crashes even if the dll specified by Anonymous in his/her post.click on the link below and save to C:\windowsafter that the program should workwww.handydan.pwp.blueyonder.co.uk/impout32.dll If my memory is correct, we can not just directly access the port through the functions. The program may work in Dos machines or Win.98 machines atleast.

:(i try to send any data to LPT port and I use createFile function and it doesn't work properly-I working on Win Xp. I heard that I need special function or library (some dll's)-it is true? please help...

hi iliyastry to download the demo version present in the website www.thesycon.com. it works. once u understand it u will be able to develop ur own application.do u have any device attached to ur usb port?

the WriteFile returns TRUE, but the data don't be sent actualy, until i close the parallel port using CloseHandle(hParallel), It seems WriteFile only send the data to transmitt buffer.Does sombody know the reason?

As I don't have enough time to investigate at the moment I've found a very useful dll Inpout32.dll (it's free, it works, and there's the source code as well!). It's not usual to find such a documentation so I was lucky.Please see link below.

http://www.logix4u.net/inpout32.htm

If anybody finds the solution about the CreateFile(...) under VC++, please let me know.

I have also been trying to send data to parallel port for quite some time. I was able to use createfile and writefile but i am not able to use readfile. the application simply hangs when i try to do a read operation on parallel port. I also tried with the dll you mentioned. But we can only send a byte of data at once using INPout32.dll, right? But if we want to send\receive a large chunk of data using those dll`s, How can we do it? I am really tired trying to find out a solution for this. So any help or clue on this subject would be highly appreciated.

thanks this is most helpful yet I wish to gain better controlon the issue . can anybody advice for a way to do it without binary files (I am searching for the source ofthe driver/library to get a minimalfootprint on my system).

I am new in vc++.I tried to run the demo version in windows XP.But there was some access violation.....Could any one tell me whats wrong.Some one told me to install driver for parallel port.But I did not get it.Please tell me detail

The producers of LPT port chips, are lieing us!The standard say that using ECP/EPP bidirectional port You can take power from LPT up to 10mA from each pin, but this is done only in old constructions, So be carefull when conecting home made pherifery to your port, you can damage it just for a seccond!Use maximum 1-2mA from each pin. Use isolation chips.