?
Solved

Turning LED's on Parallel port on/off in VC++ 6.0/MFC...it works in a console app, what about a dialog based app?

Posted on 2006-04-22
13
Medium Priority
?
602 Views
Last Modified: 2008-03-03
Hi,

jkr was helpful in getting me started programming the parallel port (turning LED'S D0-D8) on /off in a console app in my last question. But now, to get this working in VC++ 6.0/MFC Dialog based app where you enter a data value in an edit box and press a button to send the data (Ex: data = 1 to turn on D0) to the port (888) , can someone point me in the right directon? I don't think there are MFC functions for this. Thanks!
0
Comment
Question by:pigeonbr
  • 7
  • 5
13 Comments
 

Author Comment

by:pigeonbr
ID: 16514985
Just thinking...if there is no way to do it from VC++ 6.0/MFC, is there a way I could pass the data to my console app which does work (without the console window appearing), and come seamlessly back to my dialog box, then enter another data number , send it by using the data send button, etc....? Any ideas to get me started? Thanks very much.
0
 

Author Comment

by:pigeonbr
ID: 16515032
Ooops...another detail...i want this to work under windows 2000. Thanks!
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 16515136
Create dialog-based application using MFC Application Wizard, add button and edit box to the dialog. Double-click button in the dialog editor, it creates button handler. Fill it by the following way:

void CMyDialog::OnButtonSend()
{
    int n = 0;
    TCHAR buffer[100];

    // get text from edit box
    GetDlgItem(IDS_EDIT1)->GetWindowText(buffer, 100);   // IDS_EDIT1 is edit box ID

    // Convert string to integer
    _stscanf(buffer, _T("%d"), &n);

   // Send data to the port
   Send(n);                                // set here your existing function
}
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:pigeonbr
ID: 16515692
Hi AlexFM,
  The Send() command gives me an undeclared identifier compile error, and I have no function in my program to send anything to. The console.exe program that works is just that...an .exe console program...

I was trying the same sort of thing you suggest....get the value from the edit box variable, then use code from the console program to send the data, but that doesn't work because the commands only work in DOS...here is what I tried:

void CPortApp1Dlg::OnSendDataButton()
{
      UpdateData(TRUE);//gets the data in the edit box and puts it in the edit box variable m_PortData, which is already  
                                    //an int so I don't have to convert anything.
      _outp(888,m_PortData);//send data in edit box to LPT1, but _outp doesn't work in dialog based app and gives a   compile error.


}
******
Could you be a little more specific? Thanks!
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 16515918
Well, to compile _outp you must include <conio.h>, but this will not work at runtime.

The problem is not difference between console and MFC application. _outp will not work under Windows in any case, it works only in DOS and Windows 95/98. In WinNT or later you need driver to talk with parallel port.
This is simple solution which is used in many applications:
http://www.driverlinx.com/DownLoad/DlPortIO.htm

It is not 100% correct because it uses port address as parameter and doesn't detect port address in the kernel mode. However, it is very simple and allows to get application working.
0
 

Author Comment

by:pigeonbr
ID: 16516540
AlexFM
This driver is 16 bit and will not work with my W2k. As you correctly stated the _outp must include the conio.h header, but only works in a console (DOS) app. If you have any other ideas, please feel free. Thanks for the comment.
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 16517810
This driver is working in my application running under Windows XP professional.
It is called DriverLinx Port I/O driver, it contains kernel mode driver, lib and h files for VC++ developer.

If you don't like it, there is another product which works exactly by the same way:
http://www.logix4u.net/inpout32.htm

Both products are free.
0
 
LVL 9

Expert Comment

by:jhshukla
ID: 16518006
so your problem is sending data from a 32bit app to a 16bit app? could you provide a link to previous question where jkr helped you out?
0
 

Author Comment

by:pigeonbr
ID: 16518786
The problem I have with the link AlexFM gave:
http://www.driverlinx.com/DownLoad/DlPortIO.htm
is that in my W2K at the end of the install, i get a window that says it is not compatible with win32 bit applications.

I had the link already to http://www.logix4u.net/inpout32.htm  ...this a link which helped get me going in DOS (console app). Here is a link to my question jkr helped with, which is now working as I said under console app in DOS:

http://www.experts-exchange.com/Programming/Programming_Languages/Cplusplus/Q_21815648.html

SO, the problem I face now as I said is getting the port to resond in VC++ 6.0/MFC under W2k somehow. The two critical files that allow me to have control of the port under the console app in DOS are the following:
hwinterface.sys and inpout32.dll, which both go in the system32 folder. These made the difference.

If there is no command to directly control the port in MFC or VC++, is there another way, or can I somehow transfer the data I input from my dialog based app to the console app already created that would get the job done. Thanks for your comments!
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 2000 total points
ID: 16518821
The only thing I can say about this, that I worked with both applications on Windows XP. In DOS you don't need any drivers, simple _outp is enough. For Windows you must use drivers, and these programs are working.
Maybe if somebody else will post the same links you will agree that they are working, I don't see any reason to continue this discussion.
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 16518844
My test 2 minites ago: I successfully installed DlPortIo on WinXP professional, test application is working.
0
 

Author Comment

by:pigeonbr
ID: 16520320
AlexFM
Thanks for your time and effort. I am only letting you know that on my W2K, SP 4, I get an error when I install the driver from the link you posted. If it is as easy as you say, I will attemp to find the problem. It is not a question of me not liking your solution. I appreciate your help. I will try to work this out on my own and find waht it going wrong. Thanks.
0
 

Author Comment

by:pigeonbr
ID: 16521242
AlexFM

Just another comment I would like to add. As I last stated I am running w2k(French language) SP4 on PC...I just tried the DriverLinx Port I/O driver on my server (W2Kserver), English, with SP2 and it installs fine. I have in the past seen apps that don't work on SP4 because of some bugs, but will work on previous SP's. This is probably why it is not working on my PC i use for developping. I'll see if I can solve this problem. So, your answer was correct, but really doesn't work on my specific machine. Just thought it would make you feel better, as it made me feel better as well :) I did award you the points. Thanks. I will try to work around my problem. At least I know it works as well on your XP Pro. :)
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

750 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