Skip to main content
Email Password   helpLost your password?

Sample Image

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

Modifying the resources

At this stage you will see dialog resource is opened in the window (AppWizard will do this as default). Now we will modify the dialog box resource as per our requirement.

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.

Now your list of Member Variables should look like this...
Control IDs:        Type        Member
IDC_PIN10            CButton        m_Pin10
IDC_PIN11            CButton        m_Pin11
IDC_PIN12            CButton        m_Pin12
IDC_PIN13            CButton        m_Pin13
IDC_PIN15            CButton        m_Pin15
80% Done. Save your work.

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.

void CPpscDlg::OnTimer(UINT nIDEvent) 
{
    // TODO: Add your message handler code here and/or call default

    
    in379=_inp(0x379);
    nPin10=in379 & 64;
    nPin11=in379 & 128;
    nPin12=in379 & 32;
    nPin13=in379 & 16;
    nPin15=in379 & 8;

    if(nPin10==0)
        m_Pin10.SetCheck(0);
    else if(nPin10==64)
        m_Pin10.SetCheck(1);

    if(nPin11==0)
        m_Pin11.SetCheck(0);
    else if(nPin11==128)
        m_Pin11.SetCheck(1);

    if(nPin12==0)
        m_Pin12.SetCheck(0);
    else if(nPin12==32)
        m_Pin12.SetCheck(1);

    if(nPin13==0)
        m_Pin13.SetCheck(0);
    else if(nPin13==16)
        m_Pin13.SetCheck(1);

    if(nPin15==0)
        m_Pin15.SetCheck(0);
    else if(nPin15==8)
        m_Pin15.SetCheck(1);

    CDialog::OnTimer(nIDEvent);
}

    // TODO: Add extra initialization here


    SetTimer(1,2,NULL);
    
    return TRUE;  // return TRUE  unless you set the focus to a control

}

// YourAppNameDlg.cpp : implementation file

//


#include "stdafx.h"

#include "YourAppName.h"

#include "YourAppNameDlg.h"


#include "conio.h"


#ifdef _DEBUG

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.

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
GeneralVC++ Pin
kunle isakin
2:26 9 Mar '09  
Generalcode doesnt work Pin
ndeshevans
23:32 28 Jul '08  
GeneralSerial port accesssing --Plzzz help me Pin
Member 4508922
19:14 20 Jul '08  
Questioni want ur help in my project Pin
aatish123
2:58 20 Jul '08  
AnswerRe: i want ur help in my project Pin
Eric Strain
12:22 24 Aug '09  
Generalhi....i want help Pin
aditya pareek
7:17 4 Jul '08  
Generalhi Pin
amalahema
2:33 30 May '08  
Questionproject proposals Pin
frieddy03
2:35 4 Apr '08  
Generalplzzzzzzzzzzz help Pin
vickyz
2:16 14 Feb '08  
Generalplz help me quite new Pin
vickyz
4:08 13 Feb '08  
QuestionProblem with adding members Pin
kingofwestern
7:40 26 Nov '07  
Questionhi Daygiri Pin
luixilva
14:03 10 Oct '07  
Questionwrite assemby code Pin
far_zad3212000
13:05 24 Feb '07  
QuestionHelp Required : USB Programming Pin
wahiajay
23:10 18 Sep '06  
AnswerRe: Help Required : USB Programming Pin
Danial Kahani
12:37 4 Feb '07  
Generalhow same can be done for serial port Pin
keenalex
21:44 5 Feb '06  
Questionreading the parallel port Pin
jama687
13:44 28 Oct '05  
Generalprogramming EEPROM in VC++ Pin
plknam2003
1:21 25 Oct '05  
Generalhow do I know whether a device is attached to my USB port or not Pin
Anonymous
5:20 3 Jun '05  
Generalaccess to database through VC++ Pin
Sugima
0:56 6 May '05  
GeneralIs It Possible Pin
Silent Warrior
11:32 31 Mar '05  
GeneralUSB again Pin
Shabayek
13:34 4 Nov '04  
GeneralProgram Crashes Pin
wicked_guy
6:22 30 Sep '04  
GeneralRe: Program Crashes Pin
Sreekanth Muralidharan
19:47 19 May '05  
GeneralRe: Program Crashes Pin
shibukv
20:32 26 Sep '05  


Last Updated 9 Jun 2002 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2009