Commit 8d125a60 authored by Tammo Jan Dijkema's avatar Tammo Jan Dijkema
Browse files

Make compatible with python3

parent 1f9c66e8
......@@ -2,6 +2,7 @@ import serial
import time
import re
import platform
import sys
class PortDevice(object):
......@@ -69,14 +70,20 @@ class PrologixGpibUsb(PortDevice):
if self._serialPort is None:
raise serial.SerialException("Cannot find port")
def _write_serial(self, commandString):
if sys.version_info >= (3,0):
self._serialPort.write(bytes(commandString, 'utf-8'))
else:
self._serialPort.write(commandString)
def _initialize_prologix_gpi(self):
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))
self._write_serial("++savecfg 0" + chr(10))
self._write_serial("++auto 0" + chr(10))
self._write_serial("++eoi 1" + chr(10))
self._write_serial("++eos 2" + chr(10))
self._write_serial("++eot_enable 0" + chr(10))
self._write_serial("++eot_char 0" + chr(10))
self._write_serial("++read_tmo_ms 500" + chr(10))
def _find_devices(self):
self._devices = []
......@@ -84,7 +91,7 @@ class PrologixGpibUsb(PortDevice):
commandStr = "++addr " + str(address) + chr(10) + \
"*idn?" + chr(10) + \
"++read" + chr(10)
self._serialPort.write(commandStr)
self._write_serial(commandStr)
returnStr = self._serialPort.readline()
if returnStr != "":
self._devices += [address, returnStr]
......@@ -94,7 +101,7 @@ class PrologixGpibUsb(PortDevice):
command = "++addr " + str(hpib_address) + chr(10) + command
self._hpib_address = hpib_address
self._serialPort.write(command + chr(10))
self._write_serial(command + chr(10))
def query(self, hpib_address, query, count=80):
if hpib_address != self._hpib_address:
......@@ -102,13 +109,13 @@ class PrologixGpibUsb(PortDevice):
self._hpib_address = hpib_address
query += chr(10) + "++read eoi" + chr(10)
self._serialPort.write(query)
self._write_serial(query)
line = self._serialPort.readline()
return line[:-1]
def set_local(self, hpib_address):
# self._commandStr = "++addr "+str(hpib_address)+chr(10)+"loc "+str(hpib_address)+chr(10)
# self._commandCount = self._serialPort.write(self._commandStr)
# self._commandCount = self._write_serial(self._commandStr)
return
def get_devices(self):
......@@ -126,22 +133,22 @@ class GPIB_232_485CT_A(PortDevice):
def command(self, hpib_address, command):
self._commandStr = "wr " + str(hpib_address) + chr(10) + command + chr(13)
self._commandCount = self._serialPort.write(self._commandStr)
self._commandCount = self._write_serial(self._commandStr)
def query(self, hpib_address, query, count=80):
# flushInput should not be necessary
# self._serialPort.flushInput()
self._commandStr = "wr " + str(hpib_address) + chr(10) + query + chr(13)
self._commandCount = self._serialPort.write(self._commandStr)
self._commandCount = self._write_serial(self._commandStr)
self._queryStr = "rd #"+str(count)+" "+str(hpib_address)+chr(13)
self._queryCount = self._serialPort.write(self._queryStr)
self._queryCount = self._write_serial(self._queryStr)
self._returnStr = self._serialPort.read(count)
self._returnCnt = int(self._serialPort.readline())
return self._returnStr[:self._returnCnt-1]
def set_local(self, hpib_address):
self._commandStr = "loc "+str(hpib_address)+chr(13)
self._commandCount = self._serialPort.write(self._commandStr)
self._commandCount = self._write_serial(self._commandStr)
class HpibDevice(object):
......
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