简体   繁体   English

在Linux中使用C#Mono控制并行端口

[英]Control parallel port using C# Mono in Linux

As per the title, I want to control a parallel (LPT) port using C# in Ubuntu. 按照标题,我想在Ubuntu中使用C#控制并行(LPT)端口。

Are there any inbuilt libraries in Mono that will allow me to do this? Mono中是否有任何内置库可以帮助我做到这一点?

Can anyone give any code examples of making this work? 谁能给出实现此功能的任何代码示例?

Guide with basics, and c# code for use of inpout driver and api: http://www.codeproject.com/KB/cs/csppleds.aspx 基本指南以及用于inpout驱动程序和api的c#代码指南: http : //www.codeproject.com/KB/cs/csppleds.aspx

More general collection of links, both technical as well as software related to the parallel port: http://www.lvr.com/parport.htm 与并行端口相关的技术和软件方面的链接的更一般集合: http : //www.lvr.com/parport.htm

I spend quite some time researching this, and never found a native mono library. 我花了很多时间对此进行研究,但从未找到本地的Mono库。 It's easier for Serial Ports btw. 串行端口顺便说一句。

While I acknowledge Jesper's contribution, I felt his answer was incomplete and the initial answer gave only references to Windows code as pointed out by Dai. 在我承认Jesper的贡献的同时,我感到他的答案是不完整的,最初的答案仅引用了Dai指出的Windows代码。 Jesper's follow up comment regarding P/Invoke did lead me down a path to finding the answer. Jesper关于P / Invoke的后续评论确实使我走上了寻找答案的道路。

I have documented my complete solution, including code samples here: http://www.iaincarlin.com/ylsned/controlling-the-parallel-port-using-ubuntu-mono-and-c/ however, in a nutshell: 我已经记录了完整的解决方案,其中包括代码示例: http ://www.iaincarlin.com/ylsned/controlling-the-parallel-port-using-ubuntu-mono-and-c/简而言之:

  • There appears to be no native library in C# Mono for accessing the parallel port C#Mono中似乎没有用于访问并行端口的本机库
  • P/invoke is required and I had to create a native C++ application that I could invoke with DLLImport in order to access the LPT1 port. 需要P / invoke,并且我必须创建一个本机C ++应用程序,可以使用DLLImport调用它以访问LPT1端口。
  • The C++ application essentially provides a wrapper round the io library outb function that I can call from C# C ++应用程序本质上提供了io库outb函数的包装器,我可以从C#调用它

My blog post above contains more details regarding the background to what I was doing. 我上面的博客文章包含有关我正在做的事情的背景的更多详细信息。 I could have used native C++ to do the same thing (in fact it would have been easier to port my existing Dos code over to Linux), but I wanted to experiment with Mono and this was a practical way to do so. 我本可以使用本机C ++来做同样的事情(实际上将现有的Dos代码移植到Linux上会更容易),但是我想尝试使用Mono,这是一种实用的方法。

I need to acknowledge the post here: http://www.moythreads.com/wordpress/2008/02/04/pinvoke-how-to-call-c-from-c/ that provided the most helpful in getting this to work. 我需要在此处确认该帖子: http : //www.moythreads.com/wordpress/2008/02/04/pinvoke-how-to-call-c-from-c/ ,它对使此功能发挥最大作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM