@@ -38,12 +38,16 @@ def close(self):
38
38
async def _ser_read (self , fixed_length = None ):
39
39
""" strings returned by firmware are zero-terminated or fixed length
40
40
"""
41
- c = (await self .port .read (1 )).decode ()
42
- r = c
43
- while len (c ) > 0 and ord (c ) != 0 and not len (r ) == fixed_length :
41
+ r = ""
42
+ if self .simulation :
43
+ logger .info ("simulation _ser_read()" )
44
+ else :
44
45
c = (await self .port .read (1 )).decode ()
45
- r += c
46
- logger .debug ("_read %s: " , r )
46
+ r = c
47
+ while len (c ) > 0 and ord (c ) != 0 and not len (r ) == fixed_length :
48
+ c = (await self .port .read (1 )).decode ().rstrip ('\0 ' )
49
+ r += c
50
+ logger .debug ("_read %s: " , r )
47
51
return r
48
52
49
53
async def _ser_write (self , cmd ):
@@ -106,21 +110,19 @@ async def set_i(self, v):
106
110
107
111
async def get_i (self ):
108
112
"""Request the current as set by the user. """
109
-
110
- # ISET1? replies with a sixth byte on many models (all?)
111
- # which is the sixth character from *IDN?
112
- # reply if *IDN? was queried before (during same power cycle) .
113
- # This byte is read and discarded.
113
+ # Expected behavior of ISET1? is to return 5 bytes.
114
+ # However, if *IDN? has been previously called, ISET1? replies
115
+ # with a sixth byte 'K' which should be discarded. For consistency,
116
+ # always call *IDN? before calling ISET1? .
117
+ self . get_id ()
114
118
await self ._ser_write ("ISET1?" )
115
- r = await self ._ser_read (fixed_length = 5 )
116
- if r [0 ] == "K" :
117
- r = r [1 :- 1 ]
119
+ r = (await self ._ser_read (fixed_length = 6 )).rstrip ('K' )
118
120
return float (r )
119
121
120
122
async def measure_i (self ):
121
123
"""Request the actual output current."""
122
124
await self ._ser_write ("IOUT1?" )
123
- r = await self ._ser_read (fixed_length = 6 )
125
+ r = await self ._ser_read (fixed_length = 5 )
124
126
if r [0 ] == "K" :
125
127
r = r [1 :- 1 ]
126
128
return float (r )
0 commit comments