class ParPort # parallel port for Linux-i386 # version 2007.6.1 # ppdev commands # 2bit; 0:no, 4:write, 8:read # 14bit; 1:char, 4:int, ... # 16bit; 70xx:type PPSETMODE = 0x40047080 #int PPRSTATUS = 0x80017081 #unsighed char #PPWSTATUS OBSOLETE__IOW(PP_IOCTL, 0x82, unsigned char) PPRCONTROL = 0x80017083 #unsighed char PPWCONTROL = 0x40017084 #unsighed char PPRDATA = 0x80017085 #unsighed char PPWDATA = 0x40017086 #unsighed char #PPRECONTROL OBSOLETE__IOR(PP_IOCTL, 0x87, unsigned char) #PPWECONTROL OBSOLETE__IOW(PP_IOCTL, 0x88, unsigned char) #PPRFIFO OBSOLETE__IOR(PP_IOCTL, 0x89, unsigned char) #PPWFIFO OBSOLETE__IOW(PP_IOCTL, 0x8a, unsigned char) PPCLAIM = 0x0000708b PPRELEASE = 0x0000708c PPYIELD = 0x0000708d #PPFCONTROL = 0x400?708e PPEXCL = 0x0000708f PPDATADIR = 0x40047090 #int PPNEGOT = 0x40047091 #int PPWCTLONIRQ = 0x40017092 #unsighed char PPCLRIRQ = 0x80047093 #int PPSETPHASE = 0x40047094 #int #PPGETTIME = 0x800?7095 #PPSETTIME = 0x400?7096 PPGETMODES = 0x80047097 #unsigned int PPGETMODE = 0x80047098 #int PPGETPHASE = 0x80047099 #int PPGETFLAGS = 0x8004709a #int PPSETFLAGS = 0x4004709b #int #PAR=open("/dev/parport0","a+b") def initialize() @par=open("/dev/parport0","a+b") @par.ioctl(PPEXCL) @par.ioctl(PPCLAIM) @strobe=0 # No.1, output, reverce @data=0 # No.2-9, in/out @ack=0 # No.10, input, reverse @busy=0 # No.11, input, non-reverse @pe=0 # No.12, input, non-reverse @slct=0 # No.13, input, non-reverse @autofxinit=0 # No.14, output, reverse @error=0 # No.15, input, reverse @init=0 # No.16, output, non-reverse @slctin=0 # No.17, output, reverse @lock=false end attr_accessor :strobe # No.1, output, reverse attr_accessor :data # No.2-9, in/out attr_reader :ack # No.10, input, reverse attr_reader :busy # No.11, input, non-reverse attr_reader :pe # No.12, input, non-reverse attr_reader :slct # No.13, input, non-reverse attr_accessor :autofxinit # No.14, output, reverse attr_reader :error # No.15, input, reverse attr_accessor :init # No.16, output, non-reverse attr_accessor :slctin # No.17, output, reverse #GND No.18-25 attr_accessor :lock # to avoid double access def close() @par.ioctl(PPRELEASE) @par.close end def status() d=[0].pack("C") @par.ioctl(PPRSTATUS,d) d=d.unpack("C")[0] d=d/8 @error=d%2; d/=2 @slct=d%2; d/=2 @pe=d%2; d/=2 @ack=d%2; d/=2 @busy=d%2; d/=2 return [@error,@slct,@pe,@ack,@busy] end def command() d=@strobe+@autofxinit*2+@init*4+@slctin*8+0xc0 @par.ioctl(PPWCONTROL,[d].pack("C")) return [@strobe,@autofxinit,@init,@slctin,@inout] end def command?() d=[0].pack("C") @par.ioctl(PPRCONTROL,d) d=d.unpack("C")[0] @strobe=(d & 1); d>>=1 @autofxinit=d & 1; d>>=1 @init=d & 1; d>>=1 @slsctin=d & 1; d>>=1 return [@strobe,@autofxinit,@init,@slctin] end def write(d=@data) @par.ioctl(PPDATADIR,[0].pack("i")) @par.ioctl(PPWDATA,[d].pack("C")) end def read() @par.ioctl(PPDATADIR,[1].pack("i")) d=[0].pack("C") @par.ioctl(PPRDATA,d) d=d.unpack("C")[0] return d end end