Commit 41c9cd81 authored by Tammo Jan Dijkema's avatar Tammo Jan Dijkema

Add HPIB files from Harm

parents
import serial
import time
import re
import platform
class PROLOGIX_GPIB_USB():
def __init__(self, \
port="", timeout=1, \
portFormat="%d", maxDeviceNum=9, verbose=False, \
findDevices=False):
if port == "":
if platform.system() == "Linux":
port = "/dev/ttyUSB0"
portFormat = "%d"
maxDeviceNum = 99
elif platform.system() == "Darwin":
port = "/dev/ttys000"
portFormat = "%03d"
maxDeviceNum = 999
if verbose:
print "Looking for ports such as %s in range %d on %s" % \
( port, maxDeviceNum, platform.system() )
self._rematch=re.search(r"(/dev/tty.*[^0-9])([0-9]+$)",port)
self._serialPort = None
while int(self._rematch.group(2)) < maxDeviceNum:
if verbose:
print "trying ", port
try:
self._serialPort = serial.Serial(port,timeout=timeout)
break
except serial.SerialException:
port=self._rematch.group(1) +\
(portFormat % (int(self._rematch.group(2))+1))
self._rematch=re.search("(/dev/tty.*[^0-9])([0-9]+$)",port)
if port==None:
raise serial.SerialException("Cannot find port")
self._serialPort.write("++savecfg 0" + chr(10))
self._serialPort.write("++auto 0" + chr(10))
self._serialPort.write("++eoi 1" + chr(10))
self._serialPort.write("++eos 2" + chr(10))
self._serialPort.write("++eot_enable 0" + chr(10))
self._serialPort.write("++eot_char 0" + chr(10))
self._serialPort.write("++read_tmo_ms 500" + chr(10))
if findDevices:
self._devices = []
for self._hpib_address in range(0, 31):
self._commandStr = "++addr " + str(self._hpib_address) + chr(10) + \
"*idn?" + chr(10) + \
"++read" + chr(10)
self._serialPort.write(self._commandStr)
self._returnStr = self._serialPort.readline()
if self._returnStr != "":
self._devices += [self._hpib_address, self._returnStr]
else:
self._devices = "Not scanned."
self._hpib_address = -1
def command(self, hpib_address, commandStr):
if hpib_address != self._hpib_address:
self._commandStr = "++addr " + str(hpib_address)+chr(10)
self._hpib_address = hpib_address
else:
self._commandStr = ""
self._commandStr += commandStr+chr(10)
self._commandCount = self._serialPort.write(self._commandStr)
def query(self, hpib_address, queryStr, count=80):
if hpib_address != self._hpib_address:
self._commandStr = "++addr " + str(hpib_address)+chr(10)
self._hpib_address = hpib_address
else:
self._commandStr = ""
self._commandStr += queryStr + chr(10) + "++read eoi" + chr(10)
self._commandCount = self._serialPort.write(self._commandStr)
self._returnStr = self._serialPort.readline()
return self._returnStr[:-1]
def setLocal(self, hpib_address):
#self._commandStr = "++addr "+str(hpib_address)+chr(10)+"loc "+str(hpib_address)+chr(10)
#self._commandCount = self._serialPort.write(self._commandStr)
return
def getDevices(self):
return self._devices
class GPIB_232_485CT_A():
def __init__(self, \
port="/dev/ttyS0", \
baudrate=9600, bytesize=serial.EIGHTBITS, \
parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, \
interCharTimeout=None, pause=0, timeout=10):
self._serialPort = serial.Serial(port, \
baudrate, bytesize, \
parity, stopbits, \
interCharTimeout, timeout)
self._serialPort.flushInput()
self._pause = pause
def command(self, hpib_address, commandStr):
self._commandStr = "wr "+str(hpib_address)+chr(10)+commandStr+chr(13)
self._commandCount = self._serialPort.write(self._commandStr)
def query(self, hpib_address, queryStr, count=80):
# flushInput should not be necessary
# self._serialPort.flushInput()
self._commandStr = "wr "+str(hpib_address)+chr(10)+queryStr+chr(13)
self._commandCount = self._serialPort.write(self._commandStr)
self._queryStr = "rd #"+str(count)+" "+str(hpib_address)+chr(13)
self._queryCount = self._serialPort.write(self._queryStr)
self._returnStr = self._serialPort.read(count)
self._returnCnt = int(self._serialPort.readline())
return self._returnStr[:self._returnCnt-1]
def setLocal(self, hpib_address):
self._commandStr = "loc "+str(hpib_address)+chr(13)
self._commandCount = self._serialPort.write(self._commandStr)
class hpib_device():
def __init__(self, hpib_address, port, keepLocal=False,pause=0):
self._hpib_address = hpib_address
self._port = port
self._keepLocal = keepLocal
self._pause = pause
def keepRemote(this, keepRemote=False):
self._keepLocal = not keepRemote
def setLocal(self, set2Local=True):
if set2Local:
self._port.setLocal(self._hpib_address)
def command(self, commandStr):
self._port.command(self._hpib_address, commandStr)
self.setLocal(self._keepLocal)
time.sleep(self._pause)
def query(self, queryStr):
self._answerStr = self._port.query(self._hpib_address, queryStr)
self.setLocal(self._keepLocal)
return self._answerStr
def getDevices(self):
return ["Not implemented"]
#!/usr/bin/env python
import hpib
import subprocess
import telescope
import math
import time
##import kapteyn
p=hpib.PROLOGIX_GPIB_USB()
sml=hpib.hpib_device(28,p)
smx=hpib.hpib_device(14,p)
esmc=hpib.hpib_device(1,p)
DT=telescope.telescope(math.radians(52.812019), math.radians(6.396169), 25.0,connect=True)
print sml.query("*IDN?")
print esmc.query("*IDN?")
print smx.query("*IDN?")
freq=1420.405751
def stepoverrange(start=0,end=360,delay=1):
for rastep in range(start,end):
ra=math.radians(rastep)
#ra=0
argString = str(ra)+" 0 2000 "+str(time.time())+" "+str(DT.lat())+" "+str(DT.long())+" 25 "
vlsrStr="vlsr " + argString
dopplerStr="doppler " + argString + str(freq)
speed=subprocess.Popen(vlsrStr, stdout=subprocess.PIPE, shell=True).stdout.read()
dfreq=1000.0+freq-float(subprocess.Popen(dopplerStr, stdout=subprocess.PIPE, shell=True).stdout.read())
sml.command("freq "+str(dfreq)+" MHz")
qfreq=sml.query("freq?")
print str(time.time()), dfreq, qfreq
time.sleep(delay)
#mset=subprocess.Popen(msStr, stdout=subprocess.PIPE, shell=True).stdout.read()
def doforever(delay=1):
while 1:
#ra=math.radians(rastep)
ra=0
argString = str(ra)+" 0 2000 "+str(time.time())+" "+str(DT.lat())+" "+str(DT.long())+" 25 "
vlsrStr="vlsr " + argString
dopplerStr="doppler " + argString + str(freq)
speed=subprocess.Popen(vlsrStr, stdout=subprocess.PIPE, shell=True).stdout.read()
dfreq=1000.0+freq-float(subprocess.Popen(dopplerStr, stdout=subprocess.PIPE, shell=True).stdout.read())
sml.command("freq "+str(dfreq)+" MHz")
qfreq=sml.query("freq?")
print str(time.time()), dfreq, qfreq
time.sleep(delay)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment