Skip to content

Commit 37d7f20

Browse files
Python3_PhaseMatrixQuickSyn: Conversion to and from bytestrings on connection.write() and connection.readline()
1 parent a9fcd41 commit 37d7f20

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

PhaseMatrixQuickSyn.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,11 @@ def init(self):
216216
self.connection.readlines()
217217

218218
#check to see if the reference is set to external. If not, make it so! (should we ask the user about this?)
219-
self.connection.write('ROSC:SOUR?\r')
220-
response = self.connection.readline()
219+
self.connection.write(b'ROSC:SOUR?\r')
220+
response = self.connection.readline().decode('utf8')
221221
if response == 'INT\n':
222222
#ref was set to internal, let's change it to ext
223-
self.connection.write('ROSC:SOUR EXT\r')
223+
self.connection.write(b'ROSC:SOUR EXT\r')
224224

225225
def check_remote_values(self):
226226
# Get the currently output values:
@@ -230,12 +230,12 @@ def check_remote_values(self):
230230
count = 0
231231

232232

233-
self.connection.write('FREQ?\r')
234-
line = self.connection.readline()
233+
self.connection.write(b'FREQ?\r')
234+
line = self.connection.readline().decode('utf8')
235235

236236
if line == '':
237237
#try again
238-
line = self.connection.readline()
238+
line = self.connection.readline().decode('utf8')
239239
if line == '':
240240
raise Exception("Device didn't say what its frequncy was :(")
241241

@@ -244,8 +244,8 @@ def check_remote_values(self):
244244

245245
# wait a little while first, it doesn't like being asked things too quickly!
246246
time.sleep(0.05)
247-
self.connection.write('OUTP:STAT?\r')
248-
line = self.connection.readline()
247+
self.connection.write(b'OUTP:STAT?\r')
248+
line = self.connection.readline().decode('utf8')
249249
if line == '':
250250
raise Exception("Device didn't say what its status was :(")
251251
time.sleep(0.05)
@@ -260,8 +260,8 @@ def check_remote_values(self):
260260
def check_status(self):
261261
results = {}
262262
line = ''
263-
self.connection.write('STAT?\r')
264-
line = self.connection.readline()
263+
self.connection.write(b'STAT?\r')
264+
line = self.connection.readline().decode('utf8')
265265
if line == '':
266266
raise Exception("Device didn't say what its status was :(")
267267
time.sleep(0.05)
@@ -295,8 +295,8 @@ def check_status(self):
295295
results['lock_recovery'] = int(status[-8])
296296

297297
# now let's check it's temperature!
298-
self.connection.write('DIAG:MEAS? 21\r')
299-
results['temperature'] = float(self.connection.readline())
298+
self.connection.write(b'DIAG:MEAS? 21\r')
299+
results['temperature'] = float(self.connection.readline().decode('utf8'))
300300

301301
# check if the temperature is bad, if it is, raise an exception. Hopefully one day this will be sent to syslog,
302302
#at which point we'll add some extra magic to segregate into warning and critical temperatures.
@@ -312,15 +312,15 @@ def program_manual(self,front_panel_values):
312312
#program in millihertz:
313313
freq*=1e3
314314
command = 'FREQ %i\r'%freq
315-
self.connection.write(command)
315+
self.connection.write(command.encode('utf8'))
316316

317317
# add some sleep time here since the phasematrix gets grumpy
318318
time.sleep(0.05)
319319

320320

321321
gate = front_panel_values['dds 0']['gate']
322322
command = 'OUTP:STAT %i\r'%gate
323-
self.connection.write(command)
323+
self.connection.write(command.encode('utf8'))
324324

325325
return self.check_remote_values()
326326

@@ -345,9 +345,9 @@ def transition_to_buffered(self,device_name,h5file,initial_values,fresh):
345345
if 'STATIC_DATA' in group:
346346
data = group['STATIC_DATA'][:][0]
347347

348-
self.connection.write('FREQ %i\r'%(data['freq0']))
348+
self.connection.write(b'FREQ %i\r'%(data['freq0']))
349349
time.sleep(0.05)
350-
self.connection.write('OUTP:STAT 1')#%i'%(data['gate0']))
350+
self.connection.write(b'OUTP:STAT 1')#%i'%(data['gate0']))
351351

352352

353353
# Save these values into final_values so the GUI can

0 commit comments

Comments
 (0)