since no one gave me a reply, I thought that no one knows the solution.
Here is it.
A small library (for windows a wrapper) for hardware I/O.
As written, the same commands works in Windows and in Linux.
(Sorry, I don't know MACs)
The only disadvantage for Linux:
You need root rights for I/O access.
So compile the program and run it as root or use sudo.
Here is the code:
save the code as InpOut.pbi
Code: Select all
;
; Wrapper for the well known inpout32.dll
;
; http://logix4u.net
;
; and an implementation for Linux
;
Global InpOutLib = #False
Global *Inp
Global *Out
Procedure InitInpOut()
Result = #False
CompilerIf #PB_Compiler_OS = #PB_OS_Linux
InpOutLib = OpenLibrary(#PB_Any, "libc.so.6")
If InpOutLib
*iopl = GetFunction(InpOutLib, "iopl")
Result = CallCFunctionFast(*iopl, 3)
If Result = 0 : Result = #True : EndIf
EndIf
CompilerElse
InpOutLib = OpenLibrary(#PB_Any, "inpout32.dll")
If InpOutLib
*Inp = GetFunction(InpOutLib, "Inp32")
*Out = GetFunction(InpOutLib, "Out32")
Result = #True
EndIf
CompilerEndIf
ProcedureReturn Result
EndProcedure
Procedure CloseInpOut()
If InpOutLib : CloseLibrary(InpOutLib) : EndIf
EndProcedure
Procedure Inp(Port.w)
CompilerIf #PB_Compiler_OS = #PB_OS_Linux
EnableASM
mov dx, Port
in ax, dx
DisableASM
ProcedureReturn
CompilerElse
ProcedureReturn CallFunctionFast(*Inp, Port)
CompilerEndIf
EndProcedure
Procedure Out(Port.w, Value.w)
CompilerIf #PB_Compiler_OS = #PB_OS_Linux
EnableASM
mov dx, Port
mov ax, Value
out dx, ax
DisableASM
CompilerElse
CallFunctionFast(*Out, Port, Value)
CompilerEndIf
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 "InpOut.pbi"
If OpenConsole()
If InitInpOut()
StartTime = ElapsedMilliseconds()
BlinkTime = StartTime
For i = 0 To 100000
Out($378, $00)
If Inp($379) & $10 : PrintN("Off") : Delay(500) : EndIf
Out($378, $FF)
If Inp($379) & $10 : PrintN("On") : Delay(500) : EndIf
Next i
EndTime = ElapsedMilliseconds()
PrintN ("Time: " + Str(EndTime - StartTime))
CloseInpOut()
Else
PrintN("Init of the IO library failed")
EndIf
EndIf
CloseConsole()
If you connect SELECT (latest pin in the top row of the connector)
to GND, than you can meassure the time for the loop.
Best regards,
Bernd