Skip to content

Commit

Permalink
Added Matisse Commander server option
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexShkarin committed May 2, 2024
1 parent 2d1ad0b commit 7862eff
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
9 changes: 8 additions & 1 deletion docs/devices/Sirah.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ The laser is identified by its VISA address, typically looking like ``"USB0::0x1
>> pll.list_backend_resources("visa")
('USB0::0x17E7::0x0102::01-01-10::INSTR',)
>> from pylablib.devices import Sirah
>> laser = Sirah.SirahMatisse("")
>> laser = Sirah.SirahMatisse("USB0::0x17E7::0x0102::01-01-10::INSTR")
>> laser.close()

Alternatively, one can use a network connection to the Matisse Commander server, if it is enabled in the Matisse Commander communication Options::

>> import pylablib as pll
>> from pylablib.devices import Sirah
>> laser = Sirah.SirahMatisse(("127.0.0.1",30000)) # local server on the default port 30000
>> laser.close()

Operation
Expand Down
36 changes: 30 additions & 6 deletions pylablib/devices/Sirah/Matisse.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from ...core.devio import SCPI, interface
from ...core.devio import SCPI, interface, comm_backend
from ...core.utils import py3, general
from .base import GenericSirahError, GenericSirahBackendError

import time
import collections
import warnings
import struct


TThinetCtlParameters=collections.namedtuple("TThinetCtlParameters",["setpoint","P","I","avg"])
Expand All @@ -22,12 +23,20 @@ class SirahMatisse(SCPI.SCPIDevice):
Args:
addr: device address (usually a VISA name).
use_mc_server: determines whether Matisse Commander server is used for the communication (it has somewhat different command format);
if ``"auto"``, assumed to be ``True`` for network connections and ``False`` otherwise
"""
Error=GenericSirahError
ReraiseError=GenericSirahBackendError
_bool_selector=("FALSE","TRUE")
def __init__(self, addr):
super().__init__(addr)
def __init__(self, addr, use_mc_server="auto"):
if use_mc_server=="auto":
use_mc_server=comm_backend.autodetect_backend(addr)=="network"
self._use_mc_server=use_mc_server
if self._use_mc_server:
super().__init__(addr,term_read=b"",term_write=b"",backend_params={"datatype":"bytes"})
else:
super().__init__(addr)
with self._close_on_error():
self.get_id()
self._add_scpi_parameter("diode_power","DPOW:DC")
Expand Down Expand Up @@ -111,15 +120,19 @@ def __init__(self, addr):
self._add_settings_variable("fastpiezo_ctl_status",self.get_fastpiezo_ctl_status,self.set_fastpiezo_ctl_status,ignore_error=GenericSirahError)
self._add_settings_variable("fastpiezo_ctl_params",self.get_fastpiezo_ctl_params,self.set_fastpiezo_ctl_params,ignore_error=GenericSirahError)
self._add_status_variable("refcell_position",self.get_refcell_position,ignore_error=GenericSirahError)
self._add_settings_variable("refcell_waveform_params",self.get_refcell_waveform_params,self.set_refcell_waveform_params,ignore_error=GenericSirahError)
self._add_settings_variable("refcell_waveform_params",self.get_refcell_waveform_params,self.set_refcell_waveform_params,ignore_error=(GenericSirahError,ValueError))
self._add_settings_variable("scan_status",self.get_scan_status,self.set_scan_status)
self._add_settings_variable("scan_position",self.get_scan_position,self.set_scan_position)
self._add_settings_variable("scan_params",self.get_scan_params,self.set_scan_params)

_id_comm="IDN?"
_float_fmt="{:.8f}"
def _instr_read(self, raw=False, size=None):
res=super()._instr_read(raw=raw,size=size)
if self._use_mc_server:
l,=struct.unpack(">I",self.instr.read(4))
res=self.instr.read(l)
else:
res=super()._instr_read(raw=raw,size=size)
if not raw:
res=res.strip()
if res.startswith(b":"):
Expand All @@ -128,6 +141,17 @@ def _instr_read(self, raw=False, size=None):
elif res.upper().startswith(b"!ERROR"):
raise GenericSirahError("device replied with an error: {}".format(py3.as_str(res[6:]).strip()))
return res
def _instr_write(self, msg):
if self._use_mc_server:
self.instr.write(struct.pack(">I",len(msg)))
return self.instr.write(py3.as_bytes(msg))
else:
return super()._instr_write(msg)
def close(self):
if self._use_mc_server and self.instr:
self.write(b"Close_Network_Connection")
time.sleep(0.5)
super().close()

_ask_err_ntries=3
_ask_err_delay=1.
Expand Down Expand Up @@ -294,7 +318,7 @@ def thinet_home(self, wait=True, wait_timeout=30.):
if wait:
self.thinet_wait_move(timeout=wait_timeout)

_p_lock_ctl_status=interface.EnumParameterClass("lock_ctl_status",[("run","RUN"),("run","RU"),("stop","STOP"),("stop","ST")])
_p_lock_ctl_status=interface.EnumParameterClass("lock_ctl_status",[("run","RUN"),("run","RU"),("run","TRUE"),("stop","STOP"),("stop","ST"),("stop","FALSE")])
def get_thinet_ctl_status(self):
"""Get thin etalon lock status (``"run"`` or ``"stop"``)"""
return self._get_scpi_parameter("thinet_ctl_status")
Expand Down

0 comments on commit 7862eff

Please sign in to comment.