开发者

Parallel port with C#

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开发者_JS百科++:

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.


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:.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜