Link to home
Start Free TrialLog in
Avatar of pigeonbr
pigeonbr

asked on

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?

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!
Avatar of pigeonbr
pigeonbr

ASKER

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.
Ooops...another detail...i want this to work under windows 2000. Thanks!
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
}
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!
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.
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.
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.
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?
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:

https://www.experts-exchange.com/questions/21815648/Paralle-port-programming-VC-6-0-W2K-turning-on-off-LED's-on-data-out-pins-D0-D7.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!
ASKER CERTIFIED SOLUTION
Avatar of AlexFM
AlexFM

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
My test 2 minites ago: I successfully installed DlPortIo on WinXP professional, test application is working.
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.
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. :)