how to write to parallel port?
i'm working on a project for school and i'm stuck at this point. i've searched the web using various libraries i've found but none are working work...
my goal is to write to the parallel port on my pc( which does not have one but i have a usb to parallel converter) and i've tried -
_outp(port, whatToWrite)
and i get a priveledge violation of course so i'm wondering if there is a way to write to the port directly. any links or info is appreciated
my project is to use http://www.electronickits.com/kit/co...lec/ck1601.htm that board. it will activate 8 different solenoids and it will play a game(guitar hero type game). once i get them actually working the coding shouldnt be that bad.
Re: how to write to parallel port?
http://www.eee.deu.edu.tr/~ozkurt/co.../inwindows.htm'
Tie pins 11 and 12 to ground, then this should work:
Code:
int main()
{
ofstream lpt1("lpt1", ios::out | ios::binary);
if (!lpt1)
{
cerr << "Failed to open lpt1" << endl;
return 1;
}//if
char b = 0x11; // 00010001, turn on relays 1 & 5
if (!lpt1.write(&b, 1))
cerr << "Write failed" << endl;
return 0;
}
gg
Re: how to write to parallel port?
Re: how to write to parallel port?
i've tried both your methods maybe i'm doing something wrong.
codeplug i used your code but it always fails to open lpt1
and what exactly does
Code:
"ofstream lpt1("lpt1", ios::out || ios::binary)"
do?
creates an ofstream named lpt 1 but the second parameter has me confused
and Igor i tried using the stuff you gave me the program just runs and nothing happens.
any other information you provide is appreciated, trying to learn this stuff and its frustrating
Re: how to write to parallel port?
>> i have a usb to parallel converter
When you plug it in, does the OS create a new virtual LPT port? Look in Device Manager under "Ports (COM and LPT)". If you see an "LPT4", for example, that corresponds to your USB to LPT converter - then you'll want to open "LPT4", not 1.
If you are more comfortable with C file I/O (fopen, fwrite, etc) then use that. The "file" you want to open is the DOS device "LPTx", where x is the number assigned to your USB to LPT device.
gg
Re: how to write to parallel port?
One small change to Codeplug's code is needed (I believe). Change
Code:
ofstream lpt1("lpt1", ios::out || ios::binary);
to
Code:
ofstream lpt1("lpt1", ios::out | ios::binary);
You need to bitwise OR the values, not a logical OR.
Good luck.
Re: how to write to parallel port?
Good catch! Fixed in post.
Try the new code. Change "1" to the number assigned to your device. Ensure pins 11 and 12 are low.
gg
Re: how to write to parallel port?
Re: how to write to parallel port?
Yes - there's 10 different DLL's that give a user-mode process permission to use the IN and OUT instructions - allowing you to do x86 port I/O.
Under windows, there is typically already an LPT driver doing this for you. Having a user-mode application fiddling with port registers under the driver's nose isn't exactly ideal. Not to mention that this is for IBM-style LPT hardware. I highly doubt port I/O is going to affect a USB->LPT converter. You will have to use the driver that comes with that device.
gg