Ko=1024 LENGTH=8*Ko #TDS210 2500 #TDS1002 import os,time from numarray import * try: from gpib82357A import * print "Module gpib82357A Found!" except: print "No Module gpib82357A installed!" try: from serial import * print "Module serial Found!" except: print "No Module serial installed!" class TDS200: def __init__(self,name="COM1"): self.DeviceName="TDSxxx" self.YINC=".0" self.XINC=".0" self.XREF=".0" self.YREF="128" self.XORG=".0" self.Y1ORG=".0" self.Y2ORG=".0" self.POINTS="2500" self.XDIV ="100E-3" self.Y1DIV="1.0" self.Y2DIV="1.0" if (name=="GPIB"): self.TDS=0 try: self.GPIB=gpib82357A(name) except: self.DeviceName="-1" return else: self.TDS=1 n=int (name[3])-1 try: self.SERIAL=Serial(n,19200,EIGHTBITS,PARITY_NONE,STOPBITS_ONE,1,0,0) except: self.DeviceName="-1" return self.DeviceName=self.GetID() self.Write("HEAD OFF\n") self.Write("VERBOSE OFF\n") def GetDeviceName(self): return self.DeviceName def Write(self,cmd): if (self.TDS==1): self.SERIAL.flushInput() self.command(cmd) else: self.GPIB.write(cmd) #PB 19200bps No Protocol necessary, sending commands must be # slow => def command(self,st) def command(self,st): length=4 i=len(st) while (i>0): self.SERIAL.write(st[:length]) st=st[length:] time.sleep(0.01) i-=length def Read(self,n=10): if (self.TDS==1): st=self.SERIAL.read(n) pos=st.find('\r') st=st[:pos] else: st=self.GPIB.read() return st def Readbyte(self,n=10): if (self.TDS==1): st=self.SERIAL.read(n) else: st=self.GPIB.readbyte(n) return st # system command #***************** def Reset(self): # preset s to its default settings self.Write("*RST\n") def Stop(self): # stops acquire self.Write("ACQU:STATE STOP\n") def SetLocal(self): # sets instrument in local mode self.Write("UNL\n") def Autoscale(self): pass def View(self,str) : # compatibility with HP54111D et pyGPIBscope if (str=='1'): self.Write("SELECT:CH1 ON\n") else: self.Write("SELECT:CH2 ON\n") def GetStatus(self) : #return byte self.Write("STB?\n") st=self.Read() return st def IsStopped(self) : self.Write("TRIG:STATE?\n") st=self.Read(10) # ARMed REAdy TRIGger AUTO SAVE SCAn if (st=="SAV"): return 1 else: return -1 def GetID(self) : self.SERIAL.write("ID?\n") ch=self.SERIAL.read(100) id=ch[:6] if id=="ID TEK": pos=ch.find('/')+1 id=ch[pos:] pos=id.find(',') return id[:pos] else: return "" #channel subsystem #***************** def GetSensitivity(self,str) : # '1' to '4' if (str=='1'): return self.Y1DIV else: return self.Y2DIV def SetSensitivity(self, ch, str) : # '1' "0.01" if (ch>'0') and (ch<'5'): msg = "CH%s:VOLTS %s\n" %(ch, str) self.Write(msg) def GetOffset(self,str): return self.YREF def SetOffset(self, ch, str): if (ch>'0') and (ch<'5'): msg = "WFMP:YOF %s\n" %(ch, str) self.Write(msg) st=self.Read() return st else: return "error channel" # Timbase subsystem #***************** def GetTimebase(self): return self.XDIV def SetTimebase(self,str): msg = "HOR:MAI:SCA %s\n" %(str) self.Write(msg) def GetDelay(self): self.Write("HOR:DEL:POS?\n") st=self.Read(20) return st def SetDelay(self, str): msg = "HOR:DEL:POS %s\n" %(str) self.Write(msg) st=self.Read(20) return st def GetReference(self): pass def SetReference(self, str): # 'LEFT' 'CENTER' 'RIGHT' pass # Waveform subsystem #***************** def GetXref(self): #0 return self.XREF def GetYref(self): #128 return self.YREF self.Write("WFMP:YOF?\n") if (self.TDS==1): st=self.SERIAL.read(50) st="128" else: st=self.GPIB.read() return st def GetXinc(self): #real return self.XINC def GetYinc(self): #real return self.YINC def GetYorg(self,str): #real if (str=='1'): return self.Y1ORG else: return self.Y2ORG def GetXorg(self): #real return self.XORG def WaveForm (self): self.Write("WAV?\n") st=self.Read() return st def GetPreamble (self): self.Write("HEAD ON\n") self.Write("DAT:SOU CH1\n") self.Write('WFMP?\n') time.sleep(2.000) st=self.Read(280) #print st pos=st.find('NR_P ')+5 id=st[pos:] pos=id.find(';') self.POINTS=id[:pos] st=id pos=st.find('coupling,')+10 id=st[pos:] pos=id.find(' V') self.Y1DIV=id[:pos] st=id pos=st.find('V/div, ')+7 id=st[pos:] pos=id.find(' s') self.XDIV=id[:pos] st=id pos=st.find('XIN ')+4 id=st[pos:] pos=id.find(';') self.XINC=id[:pos] st=id pos=st.find('PT_O ')+5 id=st[pos:] pos=id.find(';') self.XREF=id[:pos] st=id pos=st.find('XZE ')+4 id=st[pos:] pos=id.find(';') self.XORG=id[:pos] st=id pos=st.find('YMU ')+4 id=st[pos:] pos=id.find(';') self.YINC=id[:pos] st=id pos=st.find('YOF ')+4 id=st[pos:] pos=id.find(';') self.YREF=str( int(float(id[:pos])) ) self.YREF="128" self.Write("HEAD OFF\n") self.Write("CH2:VOL?\n") self.Y2DIV=self.Read(20) self.Write("CH1:POS?\n") st=self.Read(20) self.Y1ORG=str(-float(self.Y1DIV)*float(st)) self.Write("CH2:POS?\n") st=self.Read(20) self.Y2ORG=str(-float(self.Y2DIV)*float(st)*float(self.Y1DIV)/float(self.Y2DIV)) #print 'self.POINTS=%s\nself.Y1DIV=%s\nself.XDIV=%s\nself.XINC=%s\nself.XREF=%s\n'\ # 'self.XORG=%s\nself.YINC=%s\nself.YREF=%s\nself.Y2DIV=%s\nself.Y1ORG=%s\n'\ # 'self.Y2ORG=%s'\ # %(self.POINTS,self.Y1DIV,self.XDIV,self.XINC,self.XREF,self.XORG,self.YINC,\ # self.YREF,self.Y2DIV,self.Y1ORG,self.Y2ORG) def GetCoupling(self,str): if (str>'0') and (str<'5'): msg = "CH%s:COUP?\n" %(str) self.Write(msg) st=self.Read(20) return st def SetCoupling(self,str): # 'DC' 'AC' 'GND' if (str>'0') and (str<'5'): msg = "CH%s:COUP %s\n" %(str) self.Write(msg) st=self.Read() return st def GetValid(self): #0 self.Write("WAV VALID?\n") st=self.Read(20) return st def GetData(self,str,len=8*Ko): msg = "DAT:SOU CH%s\n" %(str) self.Write(msg) self.Write("DAT:ENC SRP\n") self.Write("DAT:WID 1\n") self.Write("CURV?\n") self.Readbyte(6) time.sleep(len*2E-3) YP=self.Readbyte(len) data= zeros (len, Float) yref=float(self.YREF) yinc=float(self.YINC) yorg=float(self.GetYorg(str)) #print yref,yinc,yorg for XP in range (0,len,1): data[XP]= (ord(YP[XP]) - yref)*yinc + yorg return data # Acquire subsystem #***************** def Acquire (self,str): msg='ACQ:STATE RUN\n' self.Write(msg) def Digitize(self,str): self.Write("ACQ:STATE ON\n") def GetPoints(self): return self.POINTS def GetReference(self): return "LEFT " def SetReference(self, str): # 'LEFT ' 'CENTER' 'RIGH ' pass # HardCopy subsystem #***************** def Hardcopy(self,str="plot.hpgl"): pass def close(self): pass