# printer port wrapper require "Win32API" class PrnPort class Error < StandardError end def initialize @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 @inout=0 # (0:out, 1:in) 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 :inout # (0:out, 1:in) # printer port address Adrs_data=0x378 Adrs_status=0x379 # 0 # 1 # 2 # 3 /error # 4 slct # 5 pe # 6 /ack # 7 -busy Adrs_cmnd=0x37a # 0 -/strobe # 1 -/autofxinit # 2 init # 3 -/slctin # 4 interupt # 5 in/out (0:out, 1:in) # 6 # 7 def status() d=inpbyte(Adrs_status) 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 end def command() d=@strobe+@autofxinit*2+@init*4+@slctin*8+@inout*32+0xc0 outpbyte(Adrs_cmnd,d) end def write(d=@data) @data=d outpbyte(Adrs_data,d) @inout=0 command() end def read() @inout=1 command() @data=inpbyte(Adrs_data)&0xff return @data end # WinAPI Inpbyte=Win32API.new("IOFUNC32.DLL","InpByte",["L"],"L") Inpword=Win32API.new("IOFUNC32.DLL","InpWord",["L"],"L") Inpdword=Win32API.new("IOFUNC32.DLL","InpDword",["L"],"L") Outpbyte=Win32API.new("IOFUNC32.DLL","OutpByte",["L","L"],"L") Outpword=Win32API.new("IOFUNC32.DLL","OutpWord",["L","L"],"L") Outpdword=Win32API.new("IOFUNC32.DLL","OutpDword",["L","L"],"L") # basic command def inpbyte(adrs) return Inpbyte.call(adrs) end def outpbyte(adrs,data) Outpbyte.call(adrs,data) end end #class