Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
447 changes: 236 additions & 211 deletions hardwarelibrary/communication/commands.py

Large diffs are not rendered by default.

11 changes: 7 additions & 4 deletions hardwarelibrary/echodevice.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from hardwarelibrary.physicaldevice import *
from hardwarelibrary.communication.communicationport import *
from hardwarelibrary.communication.serialport import *
from hardwarelibrary.communication.commands import DataCommand, TextCommand
from hardwarelibrary.communication.commands import DataCommand, DataDecoder, TextCommand
from hardwarelibrary.communication.debugport import TableDrivenDebugPort

import re
Expand All @@ -14,9 +14,12 @@
class EchoDevice(PhysicalDevice):
classIdProduct = 0x6001
classIdVendor = 0x0403
commands = {"ECHO1": TextCommand(name="ECHO1", text_format="someText", replyPattern="someText"),
"ECHO2": TextCommand(name="ECHO2", text_format="someOtherText", replyPattern="someOtherText"),
"ECHO3": DataCommand(name="ECHO3", data=b"someData", replyDataLength=len(b"someData"))}
commands = {
"ECHO1": TextCommand(name="ECHO1", requestEncoder="someText", replyDecoder="someText"),
"ECHO2": TextCommand(name="ECHO2", requestEncoder="someOtherText", replyDecoder="someOtherText"),
"ECHO3": DataCommand(name="ECHO3", data=b"someData",
replyDecoder=DataDecoder(length=len(b"someData"))),
}

def __init__(self, serialNumber='ftDXIKC4', idProduct=classIdProduct, idVendor=classIdVendor):
PhysicalDevice.__init__(self, serialNumber=serialNumber, idProduct=idProduct, idVendor=idVendor)
Expand Down
24 changes: 15 additions & 9 deletions hardwarelibrary/motion/intellidrivedevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,21 @@ class IntellidriveDevice(RotationDevice):
classIdProduct = 0x6001

commands = {
"SET_REGISTER": TextCommand(name="SET_REGISTER", text_format="s r{register} {value}\r",
matchPattern=r's r(?P<register>0x[0-9a-fA-F]+) (?P<value>-?\d+)[\r\n]',
replyPattern="ok", responseTemplate="ok\r"),
"GET_REGISTER": TextCommand(name="GET_REGISTER", text_format="g r{register}\n",
matchPattern=r'g r(?P<register>0x[0-9a-fA-F]+)[\r\n]',
replyPattern=r'v\s(-?\d+)', responseTemplate="v {value}\r"),
"TRAJECTORY": TextCommand(name="TRAJECTORY", text_format="t {mode}\n",
matchPattern=r't (?P<mode>\d+)[\r\n]',
replyPattern="ok", responseTemplate="ok\r"),
"SET_REGISTER": TextCommand(name="SET_REGISTER",
requestEncoder="s r{register} {value}\r",
requestDecoder=r's r(?P<register>0x[0-9a-fA-F]+) (?P<value>-?\d+)[\r\n]',
replyDecoder="ok",
replyEncoder="ok\r"),
"GET_REGISTER": TextCommand(name="GET_REGISTER",
requestEncoder="g r{register}\n",
requestDecoder=r'g r(?P<register>0x[0-9a-fA-F]+)[\r\n]',
replyDecoder=r'v\s(-?\d+)',
replyEncoder="v {value}\r"),
"TRAJECTORY": TextCommand(name="TRAJECTORY",
requestEncoder="t {mode}\n",
requestDecoder=r't (?P<mode>\d+)[\r\n]',
replyDecoder="ok",
replyEncoder="ok\r"),
}

def __init__(self, serialNumber):
Expand Down
43 changes: 23 additions & 20 deletions hardwarelibrary/motion/sutterdevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from hardwarelibrary.communication.communicationport import *
from hardwarelibrary.communication.usbport import USBPort
from hardwarelibrary.communication.serialport import SerialPort
from hardwarelibrary.communication.commands import DataCommand
from hardwarelibrary.communication.commands import DataCommand, DataEncoder, DataDecoder
from hardwarelibrary.communication.debugport import TableDrivenDebugPort

import re
Expand All @@ -17,23 +17,26 @@ class SutterDevice(LinearMotionDevice):
classIdProduct = 1

commands = {
"MOVE": DataCommand(name="MOVE", prefix=b'M',
sendFormat='<clllc',
sendFields=('header', 'x', 'y', 'z', 'terminator'),
sendDefaults={'header': b'M', 'terminator': b'\r'},
requestFormat='<xlllx', requestFields=('x', 'y', 'z'),
replyDataLength=1, unpackingMask='<c'),
"GET_POSITION": DataCommand(name="GET_POSITION", prefix=b'C',
data=pack('<cc', b'C', b'\r'),
replyDataLength=13, unpackingMask='<lllx',
responseFormat='<lllc',
responseFields=('x', 'y', 'z', 'terminator')),
"HOME": DataCommand(name="HOME", prefix=b'H',
data=pack('<cc', b'H', b'\r'),
replyDataLength=1, unpackingMask='<c'),
"WORK": DataCommand(name="WORK", prefix=b'Y',
data=pack('<cc', b'Y', b'\r'),
replyDataLength=1, unpackingMask='<c'),
"MOVE": DataCommand(name="MOVE",
requestEncoder=DataEncoder('<clllc',
('header', 'x', 'y', 'z', 'terminator'),
{'header': b'M', 'terminator': b'\r'}),
requestDecoder=DataDecoder('<xlllx', ('x', 'y', 'z'), prefix=b'M'),
replyDecoder=DataDecoder('<c', length=1),
),
"GET_POSITION": DataCommand(name="GET_POSITION",
data=pack('<cc', b'C', b'\r'),
replyDecoder=DataDecoder('<lllx', length=13),
replyEncoder=DataEncoder('<lllc', ('x', 'y', 'z', 'terminator')),
),
"HOME": DataCommand(name="HOME",
data=pack('<cc', b'H', b'\r'),
replyDecoder=DataDecoder('<c', length=1),
),
"WORK": DataCommand(name="WORK",
data=pack('<cc', b'Y', b'\r'),
replyDecoder=DataDecoder('<c', length=1),
),
}

def __init__(self, serialNumber: str = None):
Expand Down Expand Up @@ -119,8 +122,8 @@ def sendCommand(self, name, **params):
cmd = self.commands[name]
data = cmd.buildSendData(**params)
self.sendCommandBytes(data)
if cmd.replyDataLength > 0:
return self.readReply(cmd.replyDataLength, cmd.unpackingMask)
if cmd.replyDecoder is not None and cmd.replyDecoder.length > 0:
return self.readReply(cmd.replyDecoder.length, cmd.replyDecoder.format)
return None

def positionInMicrosteps(self) -> (int, int, int): # for compatibility
Expand Down
10 changes: 5 additions & 5 deletions hardwarelibrary/powermeters/integradevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ class IntegraDevice(PowerMeterDevice):
classIdProduct = 0x0300
classIdVendor = 0x1ad5
commands = {
"GETPOWER": TextCommand(name="GETPOWER", text_format="*CVU", replyPattern=r"(.+?)\r\n"),
"VERSION": TextCommand(name="VERSION", text_format="*VER", replyPattern=r"(.+?)\r\n"),
"STATUS": MultilineTextCommand(name="STATUS", text_format="*STS", replyPattern=r"(.+?)\r\n", lastLinePattern=":100000000"),
"GETWAVELENGTH": TextCommand(name="GETWAVELENGTH", text_format="*GWL", replyPattern=r"PWC\s*:\s*(.+?)\r\n"),
"SETWAVELENGTH": TextCommand(name="SETWAVELENGTH", text_format="*PWC{0:05d}")
"GETPOWER": TextCommand(name="GETPOWER", requestEncoder="*CVU", replyDecoder=r"(.+?)\r\n"),
"VERSION": TextCommand(name="VERSION", requestEncoder="*VER", replyDecoder=r"(.+?)\r\n"),
"STATUS": MultilineTextCommand(name="STATUS", requestEncoder="*STS", replyDecoder=r"(.+?)\r\n", lastLinePattern=":100000000"),
"GETWAVELENGTH": TextCommand(name="GETWAVELENGTH", requestEncoder="*GWL", replyDecoder=r"PWC\s*:\s*(.+?)\r\n"),
"SETWAVELENGTH": TextCommand(name="SETWAVELENGTH", requestEncoder="*PWC{0:05d}"),
}

def __init__(self, serialNumber:str = None, idProduct:int = 0x0300, idVendor:int = 0x1ad5):
Expand Down
111 changes: 50 additions & 61 deletions hardwarelibrary/sources/cobolt.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,67 +15,56 @@ class CoboltCantTurnOnWithAutostartOn(Exception):

class CoboltDevice(LaserSourceDevice):
commands = {
"GET_POWER": TextCommand(
name="GET_POWER",
text_format="pa?\r",
replyPattern=r"(\d+\.\d+)",
matchPattern=r"pa\?\r",
responseTemplate="{power:0.4f}\r\n"),
"GET_REQUESTED_POWER": TextCommand(
name="GET_REQUESTED_POWER",
text_format="p?\r",
replyPattern=r"(\d+\.\d+)",
matchPattern=r"p\?\r",
responseTemplate="{requestedPower:0.4f}\r\n"),
"SET_POWER": TextCommand(
name="SET_POWER",
text_format="p {0:0.3f}\r",
replyPattern=r"OK",
matchPattern=r"p (?P<value>\d+\.?\d+)\r"),
"GET_ON_OFF": TextCommand(
name="GET_ON_OFF",
text_format="l?\r",
replyPattern=r"(0|1)",
matchPattern=r"l\?\r",
responseTemplate="{isOn}\r\n"),
"TURN_ON": TextCommand(
name="TURN_ON",
text_format="l1\r",
replyPattern=r"OK",
matchPattern=r"l1\r"),
"TURN_OFF": TextCommand(
name="TURN_OFF",
text_format="l0\r",
replyPattern=r"OK",
matchPattern=r"l0\r"),
"GET_SERIAL_NUMBER": TextCommand(
name="GET_SERIAL_NUMBER",
text_format="sn?\r",
replyPattern=r"(\d+)",
matchPattern=r"sn\?\r",
responseTemplate="{serialNumber}\r\n"),
"TURN_AUTOSTART_ON": TextCommand(
name="TURN_AUTOSTART_ON",
text_format="@cobas 1\r",
replyPattern=r"OK",
matchPattern=r"@cobas 1\r"),
"TURN_AUTOSTART_OFF": TextCommand(
name="TURN_AUTOSTART_OFF",
text_format="@cobas 0\r",
replyPattern=r"OK",
matchPattern=r"@cobas 0\r"),
"GET_AUTOSTART": TextCommand(
name="GET_AUTOSTART",
text_format="@cobas?\r",
replyPattern=r"(0|1)",
matchPattern=r"@cobas\?\r",
responseTemplate="{autostart}\r\n"),
"GET_INTERLOCK": TextCommand(
name="GET_INTERLOCK",
text_format="ilk?\r",
replyPattern=r"(0|1)",
matchPattern=r"ilk\?\r",
responseTemplate="{interlock}\r\n"),
"GET_POWER": TextCommand(name="GET_POWER",
requestEncoder="pa?\r",
requestDecoder=r"pa\?\r",
replyDecoder=r"(\d+\.\d+)",
replyEncoder="{power:0.4f}\r\n"),
"GET_REQUESTED_POWER": TextCommand(name="GET_REQUESTED_POWER",
requestEncoder="p?\r",
requestDecoder=r"p\?\r",
replyDecoder=r"(\d+\.\d+)",
replyEncoder="{requestedPower:0.4f}\r\n"),
"SET_POWER": TextCommand(name="SET_POWER",
requestEncoder="p {0:0.3f}\r",
requestDecoder=r"p (?P<value>\d+\.?\d+)\r",
replyDecoder=r"OK"),
"GET_ON_OFF": TextCommand(name="GET_ON_OFF",
requestEncoder="l?\r",
requestDecoder=r"l\?\r",
replyDecoder=r"(0|1)",
replyEncoder="{isOn}\r\n"),
"TURN_ON": TextCommand(name="TURN_ON",
requestEncoder="l1\r",
requestDecoder=r"l1\r",
replyDecoder=r"OK"),
"TURN_OFF": TextCommand(name="TURN_OFF",
requestEncoder="l0\r",
requestDecoder=r"l0\r",
replyDecoder=r"OK"),
"GET_SERIAL_NUMBER": TextCommand(name="GET_SERIAL_NUMBER",
requestEncoder="sn?\r",
requestDecoder=r"sn\?\r",
replyDecoder=r"(\d+)",
replyEncoder="{serialNumber}\r\n"),
"TURN_AUTOSTART_ON": TextCommand(name="TURN_AUTOSTART_ON",
requestEncoder="@cobas 1\r",
requestDecoder=r"@cobas 1\r",
replyDecoder=r"OK"),
"TURN_AUTOSTART_OFF": TextCommand(name="TURN_AUTOSTART_OFF",
requestEncoder="@cobas 0\r",
requestDecoder=r"@cobas 0\r",
replyDecoder=r"OK"),
"GET_AUTOSTART": TextCommand(name="GET_AUTOSTART",
requestEncoder="@cobas?\r",
requestDecoder=r"@cobas\?\r",
replyDecoder=r"(0|1)",
replyEncoder="{autostart}\r\n"),
"GET_INTERLOCK": TextCommand(name="GET_INTERLOCK",
requestEncoder="ilk?\r",
requestDecoder=r"ilk\?\r",
replyDecoder=r"(0|1)",
replyEncoder="{interlock}\r\n"),
}

def __init__(self, bsdPath=None, portPath=None, serialNumber: str = None,
Expand Down
Loading