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 ?
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).