使用 C# 的并行端口
我正在尝试使用 C# 程序将数据发送到 LPT1 端口,不幸的是没有成功。 我使用的是 Windows 7 x64。 我尝试了 x86 和 x64 (inpoutx64.dll) dll。
当我发送时使用 x64 dll:
Output(888, 255);
它只是继续程序,因为一切正常,但我在万用表上看不到任何东西(只有静态 0.02V)。我
还用C++尝试了以下方法:
int main () {
int val = 0;
printf("Enter a value\n");
scanf("%d", &val);
_outp(0x378, val);
getchar();
_outp(0x378, 0);
return 0; }
但它抛出了一个异常:
Unhandled exception at 0x01281428 in ppac.exe: 0xC0000096: Privileged instruction.
我记得有一次我在xp上做了类似的事情(C#而不是C++代码),我希望在win7上也可以.. 请帮我解决这个问题。
谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
_outp
使用的 IO 端口与您尝试使用并行端口执行的操作不同。 IO 端口是一种处理器级方式,用于对不同设备进行原始访问。 IO 端口与_outp
的使用应该是设备驱动程序所做的事情。因此,它在 任何版本中均享有特权(即仅限内核) Windows 足够现代,具有良好的内核/用户空间分离(即任何基于 Windows NT 的东西)。我几乎 100% 确定您从未让_outp
在 XP 上工作。要在高级代码中访问并行端口,只需像普通文件一样打开它,使用文件名
LPT1:
。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:
.