Again a solution for Windows hardware I/O

Share your advanced PureBasic knowledge/code with the community.
infratec
Always Here
Always Here
Posts: 7623
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Again a solution for Windows hardware I/O

Post by infratec »

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

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
And a small test program:

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
Maybe it is useful for someone.

Best regards,

Bernd
User avatar
utopiomania
Addict
Addict
Posts: 1655
Joined: Tue May 10, 2005 10:00 pm
Location: Norway

Post by utopiomania »

Thanks for the tip! Does this work correctly with USB-to-LPT/Serial converters as well?
kawasaki
Enthusiast
Enthusiast
Posts: 182
Joined: Thu Oct 16, 2003 8:09 pm

Post by kawasaki »

Already posted this about 2 years ago lol.

http://www.purebasic.fr/english/viewtop ... t=inpout32
infratec
Always Here
Always Here
Posts: 7623
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Post by infratec »

@utopiomania

No, it wiil not work with an USB 2 LPT adapter, since this adapters
have no real ports.

@kawasaki

Yes, you are right, but your topic was not in my search results.

But now I try to extend my small wrapper:

1. now I use Fast calls, which gives a speed increase of 25%
(If you write a programmer for SPI, than you can recognize this)
(already done)
2. I try to make the wrapper also compatible to Linux.

When I finished both tasks, I will update the code above.

Best regards,

Bernd or 'Moto Guzzi'
Post Reply