unit inpout_obj; { inpout32.dll Object oriented helper Allows to easily manipulation of local parallel port library available at http://logix4u.net Coded by Armagan Corlu aka Psy_chip root@psychip.net 2009 } interface uses windows, judithapi, classes, sysutils; type Tbit = record tag:string; active:boolean; end; var Out32:function(wAddr:word;bOut:byte):byte; stdcall; Inp32:function(wAddr:word):byte; stdcall; type Tinpout32 = class(TThread) bit: array [1..8] of Tbit; function read:byte; procedure write(data:byte); procedure initport(data:array of Tbit); procedure setbit(tag:string;status:Boolean); function getbit(tag:string):Boolean; published constructor create(const libpath:string='inpout32.dll';address:Word=$378); destructor free; private port:word; hande:Thandle; function calcvalue:Byte; procedure parsebyte(btmp:byte); end; implementation procedure Tinpout32.setbit(tag:string;status:boolean); var i:integer; begin for i:=1 to 8 do begin if self.bit[i].tag=tag then begin self.bit[i].active:=status; break; end; end; Self.write(self.calcvalue); end; function Tinpout32.getbit(tag:String):boolean; var i:integer; begin result:=False; self.parsebyte(self.read); for i:=1 to 8 do begin if self.bit[i].tag=tag then begin result:=self.bit[i].active; break; end; end; end; procedure Tinpout32.parsebyte(btmp:byte); var i:integer; binout,yorumlanasi:string; begin binout:=IntToBin(btmp,6); yorumlanasi:=ReverseString(binout); for i:=1 to 8 do begin self.bit[i].active:=strtobool(yorumlanasi[i]); end; end; function Tinpout32.calcvalue:Byte; var bTmp:byte; begin bTmp:=0; if self.bit[8].active then bTmp:=bTmp+128; if self.bit[7].active then bTmp:=bTmp+64; if self.bit[6].active then bTmp:=bTmp+16; if self.bit[5].active then bTmp:=bTmp+32; if self.bit[4].active then bTmp:=bTmp+8; if self.bit[3].active then bTmp:=bTmp+4; if self.bit[2].active then bTmp:=bTmp+2; if self.bit[1].active then bTmp:=bTmp+1; result:=bTmp; end; procedure Tinpout32.initport(data:array of Tbit); var i:integer; begin for i:=1 to High(data) do begin Self.bit[i]:=data[i]; end; self.write(self.calcValue); end; procedure Tinpout32.write(data:byte); begin Out32(self.port,data); end; function Tinpout32.read:byte; begin Result:=Inp32(self.port); end; constructor Tinpout32.create(const libpath:string='inpout32.dll';address:Word=$378); begin inherited Create(true); FreeOnTerminate := True; hande:=LoadLibrary(PChar(libpath)); if hande <> 0 then begin @Out32:=GetProcAddress(hande,PChar('Out32')); @Inp32:=GetProcAddress(hande,PChar('Inp32')); end; self.port:=address; end; destructor Tinpout32.free; var i:integer; begin for i:=1 to 8 do begin self.bit[i].active:=False; end; self.write(self.calcvalue); FreeLibrary(self.hande); inherited destroy; ZeroMemory(@self,SizeOf(self)); end; end.