Skip to content

Commit

Permalink
work around firmware bug in KA3005P that impacts get_i()
Browse files Browse the repository at this point in the history
Joe Britton authored and sbourdeauducq committed Dec 30, 2016
1 parent 010ce01 commit 2dd72fb
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions artiq/devices/korad_ka3005p/driver.py
Original file line number Diff line number Diff line change
@@ -38,12 +38,16 @@ def close(self):
async def _ser_read(self, fixed_length=None):
""" strings returned by firmware are zero-terminated or fixed length
"""
c = (await self.port.read(1)).decode()
r = c
while len(c) > 0 and ord(c) != 0 and not len(r) == fixed_length:
r = ""
if self.simulation:
logger.info("simulation _ser_read()")
else:
c = (await self.port.read(1)).decode()
r += c
logger.debug("_read %s: ", r)
r = c
while len(c) > 0 and ord(c) != 0 and not len(r) == fixed_length:
c = (await self.port.read(1)).decode().rstrip('\0')
r += c
logger.debug("_read %s: ", r)
return r

async def _ser_write(self, cmd):
@@ -106,21 +110,19 @@ async def set_i(self, v):

async def get_i(self):
"""Request the current as set by the user. """

# ISET1? replies with a sixth byte on many models (all?)
# which is the sixth character from *IDN?
# reply if *IDN? was queried before (during same power cycle).
# This byte is read and discarded.
# Expected behavior of ISET1? is to return 5 bytes.
# However, if *IDN? has been previously called, ISET1? replies
# with a sixth byte 'K' which should be discarded. For consistency,
# always call *IDN? before calling ISET1?.
self.get_id()
await self._ser_write("ISET1?")
r = await self._ser_read(fixed_length=5)
if r[0] == "K":
r = r[1:-1]
r = (await self._ser_read(fixed_length=6)).rstrip('K')
return float(r)

async def measure_i(self):
"""Request the actual output current."""
await self._ser_write("IOUT1?")
r = await self._ser_read(fixed_length=6)
r = await self._ser_read(fixed_length=5)
if r[0] == "K":
r = r[1:-1]
return float(r)

0 comments on commit 2dd72fb

Please sign in to comment.