views:

322

answers:

1

Hello, I am trying to send data to LPT1 port with a C# program, unfortunately with no success.. I am using windows 7 x64. I tried both x86 and x64 (inpoutx64.dll) dll's..

With the x64 dll when I send:

Output(888, 255);

It just continues the program as everything went ok, but i can't see anything on my multimeter (only the static 0.02V)..

I also tried the following with C++:

int main () {
int val = 0;
printf("Enter a value\n");
scanf("%d", &val);
_outp(0x378, val);
getchar();
_outp(0x378, 0);
return 0; }

But it throws an exception:

Unhandled exception at 0x01281428 in ppac.exe: 0xC0000096: Privileged instruction.

I remember once I made something like this work on xp (C# not the C++ code), I hope it's possible on win7 too.. Please help me with this.

Thanks.

+4  A: 

An IO port in the sense used by _outp isn't the same as what you're trying to do with a parallel port. An IO port is a processor-level way to get raw access to different devices. The use of IO ports with _outp is supposed to be the kind of thing device drivers do. It is therefore privileged (i.e. kernel only) in any version of windows that's modern enough to have good kernel/userspace separation (namely anything based on Windows NT). I'm almost 100% certain you never got _outp to work on XP.

To access the parallel port in high-level code, just open it like a normal file, using the filename LPT1:.

Ken Bloom
It was possible under XP but only after installing a device driver (that opened all ports IIRC).
Henk Holterman
I meant the C# version was working.. it wasn't really clear.. edited now.Accessing it as a file - doesn't really work for me.. C# says:FileStream will not open Win32 devices such as disk partitions and tape drives. Avoid use of "\\.\" in the path.
Michael S.
@Michael: `inpoutx64.dll` has a kernel-mode driver embedded inside it that exposes the raw port interface to user-mode programs. (See http://logix4u.net/Legacy_Ports/Parallel_Port/How_Inpout32.dll_works_.html). That's why your C# program worked on XP.
Ken Bloom
So can you suggest another way of doing this? Which will work on win7?
Michael S.