![]() |
General Reading »
Hardware & System »
Hardware programming
Intermediate
Hardware Interface Programming in VC++ - Part I (Port Access)By JaygiriA simple port access tutorial for the hardware interface developer |
VC6, VC7Win2K, WinXP, MFC, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||

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 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.
IDC_PIN10, IDC_PIN11, IDC_PIN12, IDC_PIN13, IDC_PIN15 (note that we haven't use Pin 14 that is not for status port)
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.
CYourAppNameDlg
IDC_PIN10 to IDC_PIN15 and IDOK.
IDC_PIN11 to IDC_PIN15 (please forget pin 14) 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_Pin1580% Done. Save your work.
CYourAppNameDlg chose Add Member Variable...
int and Variable Name as in379 it would assign value of port 0x379. Keep Access type as it is.(Public)
int variable for each pin and name them as nPin10, nPin11, nPin12, nPin13, nPin15
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.
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); }
BOOL CPpscDlg::OnInitDialog() function.
// TODO: Add extra initialization here
SetTimer(1,2,NULL);
return TRUE; // return TRUE unless you set the focus to a control
}
error C2065: '_inp' : undeclared identifier
conio.h in YourAppNameDlg.cpp file as follows... // YourAppNameDlg.cpp : implementation file // #include "stdafx.h" #include "YourAppName.h" #include "YourAppNameDlg.h" #include "conio.h" #ifdef _DEBUG
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. ;)
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.
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 9 Jun 2002 Editor: Nishant Sivakumar |
Copyright 2002 by Jaygiri Everything else Copyright © CodeProject, 1999-2009 Web18 | Advertise on the Code Project |