Skip to content
Permalink
Browse files

BF: Corrected Str to Byte in colorcal.py

Corrects str to byte conversions in colorcal for PY3
  • Loading branch information...
schofiaj committed Mar 11, 2019
1 parent 3bf1b7e commit d49f154a0e3a59494af74ab1c67d2b7d777a80fc
Showing with 4 additions and 8 deletions.
  1. +4 −8 psychopy/hardware/crs/colorcal.py
@@ -149,9 +149,6 @@ def sendMessage(self, message, timeout=0.1):
continue
else:
# line without any eol chars
#myLine=thisLine.encode('ascii')
#myLine=thisLine.rstrip(eol.encode('ascii'))
#lines.append(thisLine)
lines.append(thisLine.rstrip(eol.encode('ascii')))
nEmpty = 0

@@ -180,7 +177,7 @@ def measure(self):
"""
# use a long timeout for measurement:
val = self.sendMessage(b'MES', timeout=5)
valstrip=val.strip(b'\n\r>')
valstrip = val.strip(b'\n\r>')
vals = valstrip.split(b',')
ok = (vals[0] == 'OK00')
# transform raw x,y,z by calibration matrix
@@ -210,15 +207,14 @@ def getInfo(self):
"""
val = self.sendMessage(b'IDR')
valstrip=val.strip(b'\n\r>')
val=valstrip.split(b',')
valstrip = val.strip(b'\n\r>')
val = valstrip.split(b',')
ok = (val[0] == b'OK00')
if ok:
firmware = val[2]
serialNum = val[4]
firmBuild = val[-1]
else:
print('not ok')
firmware = 0
serialNum = 0
firmBuild = 0
@@ -290,7 +286,7 @@ def getCalibMatrix(self):
for rowN in range(3):
rowName = 'r0%i' % (rowN + 1)
val = self.sendMessage(rowName.encode('ascii'), timeout=1.0)
valstrip=val.strip(b'\n\r>')
valstrip = val.strip(b'\n\r>')
vals = valstrip.split(b',') # convert to list of values
if vals[0] == b'OK00' and len(vals) > 1:
# convert to numpy array

1 comment on commit d49f154

@peircej

This comment has been minimized.

Copy link
Member

commented on d49f154 Mar 26, 2019

You've ended up with a lot of encode/decode calls here and explicit statements of what type of string this should be each time you want to combine them (like b'\n' ).

Ideally the plan is to get into the desired formats just when we receive and send and then not have to think about if for the rest of the code. i.e. convert to unicode as soon as we read in from the port (maybe only if Python3) and convert to bytes just when we write to the port (maybe only if Python3), then everything else in the script can be left as natural strings.

Please sign in to comment.
You can’t perform that action at this time.