Again a solution for Windows hardware I/O
Posted: Sat Feb 14, 2009 10:43 pm
Hi together,
yes I know, this looks like a never ending story.
I'm often working with hardware access. Now also with PureBASIC.
Before I wrote something, I loooked arround.
But ABB-Klaus solution(which is good) is to overloaded for me.
All other solutions uses always the CallFunction() procedure directly.
For a better reading of the sourcecode that's not the best.
So here is my solution:
(It needs inpout32.dll in the same directory as the program)
InpOut32.pbi
And a small test program:
Maybe it is useful for someone.
Best regards,
Bernd
yes I know, this looks like a never ending story.
I'm often working with hardware access. Now also with PureBASIC.
Before I wrote something, I loooked arround.
But ABB-Klaus solution(which is good) is to overloaded for me.
All other solutions uses always the CallFunction() procedure directly.
For a better reading of the sourcecode that's not the best.
So here is my solution:
(It needs inpout32.dll in the same directory as the program)
InpOut32.pbi
Code: Select all
;
; Wrapper for the well known inpout32.dll
;
; http://logix4u.net
;
Global InpOut32Lib = #False
Procedure InitInpOut32()
InpOut32Lib = OpenLibrary(#PB_Any, "inpout32.dll")
ProcedureReturn InpOut32Lib
EndProcedure
Procedure CloseInpOut32()
If InpOut32Lib : CloseLibrary(InpOut32Lib) : EndIf
EndProcedure
Procedure Inp32(Port.w)
ProcedureReturn CallFunction(InpOut32Lib, "Inp32", Port) & $FFFF
EndProcedure
Procedure Out32(Port.w, Value.w)
CallFunction(InpOut32Lib, "Out32", Port, Value)
EndProcedure
Code: Select all
;
; A small test for InpOut32.pbi
;
; it simply switches all databits of LPT1 off and on again
; and between it reads the values back (depending of the mode of the LPT,
; this is only the value of the register and not the value of the port pin)
;
; For a fast test put a LED between pin 9 (D7) and pin 21 or 22 (GND)
; the pins direct below pin 9
; Best result, when you use a 2mA LED (low current LED)
;
; With a standard LPT, you have 12 outputs and 5 inputs:
;
; Baseaddress : 8 outputs (D0...D7) pin 2...9
;
; Baseaddress + 2 : 5 outputs D0 - STROBE pin 1
; D1 - AUTO pin 14
; D2 - INIT pin 16
; D3 - SELECT IN pin 17
;
; Baseaddress + 1 : 4 inputs D3 - ERROR pin 15
; D4 - SELECT pin 13
; D5 - PAPEREMPTY pin 12
; D6 - ACKNOWLEDGE pin 10
; D7 - BUSY pin 11
;
; GND pin 18...25
;
; Baseaddress : LPT1 = $378, LPT2 = $278, LPT1 = $3BC (old Hercules grafic cards :) )
;
IncludeFile "InpOut32.pbi"
If InitInpOut32()
Out32($378, $00)
Debug RSet(Hex(Inp32($378)), 4, "0")
Out32($378, $FF)
Debug RSet(Hex(Inp32($378)), 4, "0")
CloseInpOut32()
Else
MessageRequester("InpOut32", "Can not load inpout32.dll")
EndIf
Best regards,
Bernd