-
December 14th, 2008, 11:17 AM
#1
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.
-
December 14th, 2008, 01:16 PM
#2
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
Last edited by Codeplug; December 15th, 2008 at 01:54 PM.
Reason: fixed logical OR to bitwise OR - thnx krmed
-
December 14th, 2008, 04:12 PM
#3
Re: how to write to parallel port?
Best regards,
Igor
-
December 15th, 2008, 11:00 AM
#4
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
-
December 15th, 2008, 11:19 AM
#5
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
-
December 15th, 2008, 12:58 PM
#6
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.
Be sure to rate those who help!
-------------------------------------------------------------
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
-
December 15th, 2008, 02:08 PM
#7
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
-
December 16th, 2008, 08:15 AM
#8
Re: how to write to parallel port?
-
December 16th, 2008, 10:17 AM
#9
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
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|