0

How to Control USB to Parallel Port using C#?

USB to Parallel Port: IEEE-1284 (36Pins)

IEEE-1284 Pin Configuration Image:

https://i.stack.imgur.com/b75Z5.png

OS(Operating System): Windows 7 x64

Programming Language: C#

My Code:

private void button1_Click(object sender, EventArgs e)
{
     try
     {
          int address = System.Convert.ToInt16(textBox1.Text);
          int value = System.Convert.ToInt16(textBox2.Text);

          AccessPort.output(address, value);
      }
      catch(Exception ex)
      {
          MessageBox.Show("Error: " + ex.ToString());
      }
}

AccessPort Class:

static class AccessPort
{
    [DllImport("inpout32.dll", EntryPoint = "Out32")]
    public static extern void output(int address, int value);

    [DllImport("inpout32.dll", EntryPoint = "Inp32")]
    public static extern int input(int adress);
}

I have LED(Light Emitting Diode) Connected to D0. When I Set Address to 1 and Value to 1 and Click Button it dont gives Error but LED wont Light UP because inpout32.dll is library for real Parallel Port but I have USB to Parallel Port or My Address and Value is Incorrect for USB to Parallel Port.

How to Light Up LED with USB to Parallel Port(LPT) using C# Programming Language ?

Gigi10012
  • 9
  • 2
  • 4
  • Have You tried your code running Visual Studio as an administrator? Just to check if there is a Security issue. – Frode Aug 05 '13 at 15:18
  • Yes I tried but it dont gives any error. I think problem is in Library I'm Using USB to Parallel Port and i think inpout.dll works only with real Parallel Port or problem is in address: USB has Another address – Gigi10012 Aug 05 '13 at 15:42

1 Answers1

0

What is wrong there is that the port adress isn't 1. To check the port adress go to device manager, expand ports(COM & LPT), double click the lpt port(parallel port) that you want and go to the tab resources and get this value(see the link below)

https://i.stack.imgur.com/wiTV3.png

then, you must change how you convert the address to a int, because the port address will be in hexadecimal: int address = System.Convert.ToInt16(textBox1.Text, 16);

then in the address textbox just put that value(in my case it's 0378).

Miguel71
  • 68
  • 5
  • Ok But I cant See my IEEE-1284 in Driver Manager - ports(COM & LPT). I can see IEEE-1284 in Devices and Printers tab in ControlPanel. in Devices and Printers tab i Clicked IEEE-1284 Properties it said: Location: Port_#0002.Hub_#0003 – Gigi10012 Aug 05 '13 at 17:58
  • humm, im'm not sure how to get the port address that way, try the one that it showed to me, sometimes they are the same – Miguel71 Aug 05 '13 at 18:03
  • oh, i see, since the port is connected trought usb it doesnt show up in ports, i'mnot sure how to get the port address trough a usb adapter. Maybe it doesn't have an address at all. I'm afraid i cant help you on that. – Miguel71 Aug 05 '13 at 18:24
  • 1
    @Gigi10012 typically you cannot directly manipulate a USB-LTP port in the same way as a hardware LPT port. A hardware LPT port is a special port that lives in Memory-Mapped-IO - there is a special section of low level RAM that is devoted to representing the state of its bits. Setting those bits with `inpout.dll` is what makes operating the LPT port manually like this work - you cannot do it with a USB-LPT port without getting access to the manufacturer's DLL files (if it supports direct bit manipulation - not likely) or writing your own driver for the hardware. – J... Aug 08 '13 at 20:50