diff --git a/instruments/abstract_instruments/comm/serial_communicator.py b/instruments/abstract_instruments/comm/serial_communicator.py index 02b88f23c..1cdf31f5e 100644 --- a/instruments/abstract_instruments/comm/serial_communicator.py +++ b/instruments/abstract_instruments/comm/serial_communicator.py @@ -34,7 +34,13 @@ class SerialCommunicator(io.IOBase, AbstractCommunicator): def __init__(self, conn): super(SerialCommunicator, self).__init__(self) - if isinstance(conn, serial.Serial): + allowed_bases = (serial.Serial, ) + try: + allowed_bases += (serial.serialutil.SerialBase, ) + except AttributeError: + pass + + if isinstance(conn, allowed_bases): self._conn = conn self._terminator = "\n" self._debug = False @@ -172,8 +178,10 @@ def _sendcmd(self, msg): :param str msg: The command message to send to the instrument """ - msg += self._terminator - self.write(msg) + + message = msg.decode(encoding='UTF-8') + message += self._terminator + self.write(message) def _query(self, msg, size=-1): """ diff --git a/instruments/abstract_instruments/instrument.py b/instruments/abstract_instruments/instrument.py index 0e791142f..2e6b2b4ff 100644 --- a/instruments/abstract_instruments/instrument.py +++ b/instruments/abstract_instruments/instrument.py @@ -15,9 +15,10 @@ import os import collections import socket +import serial from builtins import map -from serial import SerialException +from serial import SerialException from serial.tools.list_ports import comports from future.standard_library import install_aliases @@ -41,7 +42,7 @@ class WindowsError(OSError): from instruments.abstract_instruments.comm import ( SocketCommunicator, USBCommunicator, VisaCommunicator, FileCommunicator, LoopbackCommunicator, GPIBCommunicator, AbstractCommunicator, - USBTMCCommunicator, VXI11Communicator, serial_manager + USBTMCCommunicator, VXI11Communicator, serial_manager, SerialCommunicator ) from instruments.errors import AcknowledgementError, PromptError @@ -524,6 +525,26 @@ def open_serial(cls, port=None, baud=9600, vid=None, pid=None, ) return cls(ser) + @classmethod + def open_serial_remote(cls, url=None, baud=115200, dsrdtr=False, rtscts=False, + xonxoff = True, timeout=3): + """ + This method follows updates in the API for PySerial so that IK can use the new + serial.serial_for_url constuctor for serial devices. + TODO: Finish me + """ + # baudrate=9600, bytesize=8, parity='N', stopbits=1, timeout=None, xonxoff=False, rtscts=False, dsrdtr=False + #Should put in parsing to check for valid URL? + ser = serial.serial_for_url( + url, + baudrate=baud, + timeout=timeout, + xonxoff=xonxoff, + rtscts=rtscts, + dsrdtr=dsrdtr + ) + return cls(SerialCommunicator(ser)) + @classmethod def open_gpibusb(cls, port, gpib_address, timeout=3, write_timeout=3): """ diff --git a/instruments/thorlabs/thorlabsapt.py b/instruments/thorlabs/thorlabsapt.py index d79ab01ad..06f24740d 100644 --- a/instruments/thorlabs/thorlabsapt.py +++ b/instruments/thorlabs/thorlabsapt.py @@ -474,7 +474,8 @@ class MotorChannel(ThorLabsAPT.APTChannel): 'DRV113': (pq.Quantity(20480, 'ct/mm'),) * 3, 'DRV114': (pq.Quantity(20480, 'ct/mm'),) * 3, 'FW103': (pq.Quantity(25600 / 360, 'ct/deg'),) * 3, - 'NR360': (pq.Quantity(25600 / 5.4546, 'ct/deg'),) * 3 + 'NR360': (pq.Quantity(25600 / 5.4546, 'ct/deg'),) * 3, + 'PRM1-Z8': (pq.Quantity(1919.64 / 360 ,'ct/deg'),) * 3 }, # TODO: add other tables here. }