Skip to content

Commit

Permalink
devices/thorlabs_tcube: improve debug logging
Browse files Browse the repository at this point in the history
sbourdeauducq committed Nov 25, 2015
1 parent 3c0efb3 commit 178f3cd
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion artiq/devices/thorlabs_tcube/driver.py
Original file line number Diff line number Diff line change
@@ -142,6 +142,12 @@ def __init__(self, id, param1=0, param2=0, dest=0x50, src=0x01,
self.src = src
self.data = data

def __str__(self):
return ("<Message {} p1=0x{:02x} p2=0x{:02x} "
"dest=0x{:02x} src=0x{:02x}>".format(
self.id, self.param1, self.param2,
self.dest, self.src))

@staticmethod
def unpack(data):
id, param1, param2, dest, src = st.unpack("<HBBBB", data[:6])
@@ -163,16 +169,20 @@ def pack(self):
self.param1, self.param2, self.dest, self.src)

def send(self, port):
logger.debug("sending: %s", self)
port.write(self.pack())

@classmethod
def recv(cls, port):
(header, ) = st.unpack("6s", port.read(6))
logger.debug("received header: %s", header)
data = b""
if header[4] & 0x80:
(length, ) = st.unpack("<H", header[2:4])
data = port.read(length)
return cls.unpack(header + data)
r = cls.unpack(header + data)
logger.debug("receiving: %s", r)
return r

@property
def has_data(self):

0 comments on commit 178f3cd

Please sign in to comment.