Sha-1 : 0976B8161468507304BC1B0F1FFF79263C71E10E
Introduction
This is very simple application for data register out control with C#. When I interested control external electronical device I was looking such as application but I couldn't find any working properly and I wrote it. This article is about controlling data registers of parallel port (LPT port) with C#.net 2.0 and using inpout32.dll/inpout32.lib out32 function.
You can use this simple application for testing external electronic projects, tesing your parallel port's data registers, understand how they works.
1.How Inpout32.dll Works ?
Source code inpout32.dll http://code.google.com/p/stimqt/downloads/detail?name=inpout32.dll
The outstanding feature of Inpout32.dll is , it can work with all the windows versions without any modification in user code or the DLL itself. The Dll will check the operating system version when functions are called, and if the operating system is Win9X, the DLL will use _inp()
and _outp
functions for reading/writing the parallel port. On the other hand, if the operating system is WinNT, 2000 or XP, it will install a kernel mode driver and talk to parallel port through that driver. The user code will not be aware of the OS version on which it is running. This DLL can be used in WinNT clone operating systems as if it is Win9X. The flow chart of the program is given below.
Look for 64 bit support Inpoutx64.dll.
Flowchart of inpout32.dll functions.
In this project used Out32
function from library.
namespace ParallelPortControl
{
class PortControl
{
[DllImport("inpout32.dll", EntryPoint = "Out32")]
public static extern void Output(int address, int value);
}
public partial class Form1 : Form
{
int decData = 0;
int decAdd = 888;
PortControl.Output(decAdd, decData);
}
}
2.How to Learn Parallel Port Address on Windows ?
You can find you parallel port's address easly on Windows Operating Systems. Right click computer on Desktop, Manage > Device manager > Ports > LPT1 or LPT2.
IEEE 1284 standard port addresses
| Data Register
| Status Register
| Control Register
|
Range1
| 3BCh
| 3BDh
| 3BEh
|
Range2
| 378h
| 379h
| 37Ah
|
Range3
| 278h
| 279h
| 27Ah
|
3.Using Decimal Input
128 64 32 16 8 4 2 1
D7 D6 D5 D4 D3 D2 D1 D0
If you want send 10010100 (1 is logic high voltage, 0 is logic low voltage) just add the decimal value which one is high(1) 128 + 16 + 4 = 148.
4.References
- logix4u.net
- Microsoft Developer Network
6.Contact
http://blog.armanasci.com.