Search code examples
c#linuxmonoparallel-port

Control parallel port using C# Mono in Linux


As per the title, I want to control a parallel (LPT) port using C# in Ubuntu.

Are there any inbuilt libraries in Mono that will allow me to do this?

Can anyone give any code examples of making this work?


Solution

  • 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's follow up comment regarding P/Invoke did lead me down a path to finding the answer.

    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:

    • There appears to be no native library in C# Mono for accessing the parallel port
    • 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.
    • The C++ application essentially provides a wrapper round the io library outb function that I can call from 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.

    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.