Klaus Peterka Programmieren INPOUT32.DLL pcnews@pcnews.at http://pcnews.at/ins/pcn/57/inpout/inpout.htm Da VisualBasic 4.0/5.0 serienmäßig keinen Zugriff auf die parallele Schnittstelle bietet, muß man sich diesen mittels einer DLL-Datei verschaffen. Fündig wurde ich im Internet, wo ich auf der Homepage von Jan Axelson’s Lakeview Research die Datei INPOUT32.DLL fand. Mit dieser Datei ist es leicht möglich, die parallele Schnittstelle unter Visual Basic anzusprechen. Ob Version 4 oder 5 ist gleichgültig, wichtig ist nur, daß es eine 32-bit Version ist. 1 Verwendung 1.1 Kopieren Sie die Datei INPOUT32.DLL in eines der drei folgenden Verzeichnisse Stammverzeichnis von Windows (z.B.: \Windows), Systemverzeichnis von Windows (z.B.: \Windows\System), Arbeitsverzeichnis der Applikation 1.2 Fügen Sie die Datei INPOUT32.BAS zu Ihrem vorhandenen Projekt hinzu. VB 4.0: (Menü) VERSION(7), COLUMNS(5), DIMENSION(TM), COLWIDTHS(196793,E1,E1,E1,42334), KEEP(OFF), ABOVE(42333), BELOW(42333), HGUTTER(14111), VGUTTER(14111), , RULE(NONE,R1C2..R2C2), L1(R0C0..R0C1), L1(R0C1..R0C2), L1(R0C2..R0C3), L1(R0C3..R0C4), L1(R0C4..R0C5), L1(R2C0..R2C1), L0(R2C1..R2C2), L0(R2C2..R2C3), L0(R2C3..R2C4), L0(R2C4..R2C5), L1(R0C0..R1C0), L1(R1C0..R2C0), L0(R0C2..R1C2), L0(R1C5..R2C5), L1(R1C0..R1C1), L1(R1C1..R1C2), L1(R1C2..R1C3), L1(R1C3..R1C4), L1(R1C4..R1C5), L1(R0C5..R1C5), L1(R1C1..R2C1) File HJOINED HJOINED HJOINED HJOINED ... Add File ... HJOINED HJOINED HJOINED VB 5.0: (Menü) VERSION(7), COLUMNS(3), DIMENSION(TM), COLWIDTHS(E1,196793,E1), KEEP(OFF), ABOVE(42333), BELOW(42333), HGUTTER(14111), VGUTTER(14111), , RULE(NONE,R1C3..R2C3), L1(R0C1..R0C2), L1(R0C2..R0C3), L1(R2C1..R2C2), L0(R2C2..R2C3), L1(R0C1..R1C1), L1(R1C1..R2C1), L1(R0C3..R1C3), L1(R1C1..R1C2), L1(R1C2..R1C3), L1(R1C2..R2C2), L1(R0C0..R0C1), L1(R1C0..R1C1), L1(R0C0..R1C0) Project HJOINED File HJOINED ... Add Module ... Dieses Basic-Modul enthält die Visual-Basic-Deklarationen für die neuen Befehle Inp und Out. 1.3 Nach Ausführung dieser beiden Schritte, können Sie auf zwei neue Befehle zurückgreifen VERSION(7), COLUMNS(2), DIMENSION(TM), COLWIDTHS(138477,E1), KEEP(OFF), ABOVE(42333), BELOW(42333), HGUTTER(14111), VGUTTER(14111), BOX(Double), HGRID(Single), VGRID(Single) OUT Schreibt einen Wert auf einen Port der parallelen Schnittstelle Syntax: OUT PortAdress, ValueToWrite Beispiel: OUT &h378, &h55 Schreibt 55h auf den DataPort von LPT 1 VERSION(7), COLUMNS(2), DIMENSION(TM), COLWIDTHS(159686,E1), KEEP(OFF), ABOVE(42333), BELOW(42333), HGUTTER(14111), VGUTTER(14111), BOX(Double), HGRID(Single), VGRID(Single) INP Liest einen Wert von einem Port der parallel Schnittstelle ein Syntax: ValueToRead = INP(PortAddress) Beispiel: I = INP (&h379) Weist der Variablen I den vom StatusPort eingelesenen Wert zu Anmerkung Die hier in den Beispielen verwendeten Portadressen können in verschiedenen Installationen differieren. Hier eine kleine Aufstellung von typischen Portadressen: VERSION(7), COLUMNS(4), DIMENSION(TM), COLWIDTHS(E1,E1,E1,E1), KEEP(OFF), BOX(Double), HGRID(Single), VGRID(Single) Printer Data Port Status Port Control Port LPT 1 0x0378 0x0379 0x037a LPT 2 0x0278 0x0279 0x027a Bemerkung 8 output pins 5 input pins 4 output pins 2 INPOUT32.BAS ‘Inp and Out declarations for direct ‘port I/O in 32-bit Visual Basic 4 programs. Public Declare Function Inp Lib _ “inpout32.dll“ Alias “Inp32” _ (ByVal PortAddress As Integer)_ As Integer Public Declare Sub Out Lib _ “inpout32.dll“ Alias “Out32" _ (ByVal PortAddress As Integer, _ ByVal Value As Integer) 3 INPOUT32.DLL {Source code for inpout32.dll. Enables 32-bit Visual Basic programs to do direct port I/O (Inp and Out) under Windows 95. To be compiled with Borland’s Delphi 2.0. } library inpout32; uses SysUtils; procedure Out32(PortAddress:smallint;Value:smallint); stdcall;export; var ByteValue:Byte; begin ByteValue:=Byte(Value); asm push dx mov dx,PortAddress mov al, ByteValue out dx,al pop dx end; end; function Inp32(PortAddress:smallint) :smallint;stdcall;export; var ByteValue:byte; begin asm push dx mov dx, PortAddress in al,dx mov ByteValue,al pop dx end; Inp32:=smallint(ByteValue) and $00FF; end; Exports Inp32, Out32; begin end. 4 Quellen Hier nun einige nützliche Links zum Thema parallele Schnittstelle: Jan Axelson’s Lakeview Research http://www.lvr.com/ Warp Nine Engineering http://www.fapo.com/ Interfacing to the IBM-PC Parallel Printer Port http://www.doc.ic.ac.uk/~ich/doc/par/ Use of a PC printer port for control and data acquisition http://et.nmsu.edu/~etti/fall96/computer/printer/printer.html