# GPIB interface for printer port wrapper require "prnprtLX" #require "prnprt95" class Gpib # cable connections # D-sub 25pin to amphenol 24pin # No. printer i/o GPIB No. +/- # 1 /STROBE O -DAV 6 - # 2 DATA0 IO DIO1 1 + # 3 DATA1 IO DIO2 2 + # 4 DATA2 IO DIO3 3 + # 5 DATA3 IO DIO4 4 + # 6 DATA4 IO DIO5 13 + # 7 DATA5 IO DIO6 14 + # 8 DATA6 IO DIO7 15 + # 9 DATA7 IO EOI 5 + # 10 /ACK I SRQ 10 + # 11 BUSY I NRFD 7 - # 12 PE I NDAC 8 + # 13 SLCT I DAV 6 + # 14 /AUTOFXINIT O ATN 11 - # 15 /ERROR I ? # 16 /INIT O -NRFD 7 + # 17 /SLCTIN O -NDAC 8 - # 18-25 GND - GND 18-24 # NC IFC 9 # GND REN 17 # NC DIO8 16 # shield 12 # for DAV, NDAC, and NRFD, connect as follows # I ---C---signal # O ---B # GND--E # C,B,E are pins of NPN type transistor (for example C945) class Error < StandardError end def initialize @dev,@pad,@sad,@tmo = -1,-1,-1,-1 @p=PrnPort::new set end attr_accessor :pad attr_accessor :sad attr_accessor :tmo #commands GTL=0x01; SDC=0x04; PPC=0x05; GET=0x08; TCT=0x09 LLO=0x11; DCL=0x14; PPU=0x15; SPE=0x18; SPD=0x19 MLA=0x20; UNL=0x3f MTA=0x40; UNT=0x5f #Timeout values and meanings TNONE = 0 # Infinite timeout (disabled) T10us = 1; T30us = 2; T100us = 3; T300us = 4 # 10-300 us (ideal) T1ms = 5; T3ms = 6; T10ms = 7; T30ms = 8 # 1-30 ms (ideal) T100ms = 9; T300ms =10; T1s =11; T3s =12 # 0.1-3 s (ideal) T10s =13; T30s =14; T100s =15; T300s =16 # 10-300 s (ideal) T1000s =17 # 1000 s (ideal) def set() dav(0); atn(0); nrfd(0); ndac(0); write_data(0) end # in def srq(n=nil) @p.status() (@p.ack-1).abs end # out def atn(n=nil) @p.autofxinit=n @p.command() end # in/out def dav(n=nil) if n!=nil @p.strobe=(n-1).abs @p.command() else @p.status() (@p.slct-1).abs end end def nrfd(n=nil) if n!=nil @p.init=n @p.command() else @p.status() @p.busy end end def ndac(n=nil) if n!=nil @p.slctin=(n-1).abs @p.command() else @p.status() (@p.pe-1).abs end end # data def write_data(d) @p.write(d^0xff) end def read_data() @p.read()^0xff end # handshake def talk(d) dav(0) if nrfd()==0 and ndac()==0 print "error\n" else write_data(d) until nrfd()==0 do end dav(1) until ndac()==0 do end dav(0) end end def listen() nrfd(1) ndac(1) nrfd(0) until dav()==1 do end nrfd(1) r=read_data() ndac(0) until dav()==0 do end ndac(1) # nrfd(0) return r end def command(a) atn(1) for d in a do talk(d) end atn(0) end # initialize def interfaceClear() end def deviceClear() command([DCL]) end def selectedDeviceClear(adrs=@pad) command([UNL,MLA+adrs,SDC]) end # remote/local def remoteEnable() end def goToLocal(adrs=@pad) command([UNL,MLA+adrs,GTL]) end def localLockOut(adrs=@pad) command([LLO]) end # trigger def groupExecuteTrigger(adrs=@pad) command([UNL,MLA+adrs,GET]) end # serial pole # paralel pole # functions def open(bd=0,pad=@pad,sad=@sad,tmo=@tmo,eot=1,eos=0) @pad,@sad,@tmo=pad,sad,tmo end def write(data) set() command([UNL,MLA+@pad]) a=data.unpack("C*") a.push(a.pop|0x80) for d in a do talk(d) end set() end def read(n=1024) set() @p.read() command([UNL,MTA+@pad]) a=[] for i in 0...n a.push(listen()) break if a.last&0x80!=0 end a.push(a.pop&0x7f) set() return a.pack("C*") end def rsp() set() command([SPE,MTA+@pad]) r=listen() command([SPD]) return end def ibclr() interfaceClear() end end #class