Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions PyExpLabSys/drivers/mks_g_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
import time
import logging
import serial
import sys

from PyExpLabSys.common.supported_versions import python2_and_3
LOGGER = logging.getLogger(__name__)
LOGGER.addHandler(logging.NullHandler())
python2_and_3(__file__)


class MksGSeries():
""" Driver for G-series flow controllers from MKS """
def __init__(self, port='/dev/ttyUSB0'):
Expand All @@ -35,7 +38,10 @@ def comm(self, command, addr):
self.ser.write(com_string)
time.sleep(0.1)
reply = self.ser.read(self.ser.inWaiting())
reply = reply.decode()
try: #some MFC communication gives UnicodeDecodeError
reply = reply.decode()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to this PR, but the default behavior of decode() without arguments has changed from 'ascii' to 'utf-8'. Most likely, the intention is that it should be ascii and getting bytes that cannot be decoded as ascii is a communications error. So trying to decode as utf-8 might in principle allow scrambled message to be decoded and the fault will appear somewhere else. I suggest to explicitely add the 'ascii' argument to decode.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing from ascii to utf-8 was actually the first thing I tried. I changed, a few lines above in the same function,
com_string = com_string.encode('ascii')
to
com_string = com_string.encode('utf-8')
Gave the same error message. But of course in hindsight that makes sense, after I figured out it was the returning message that gave the error.
Strangely, though, this wasn't a problem before updating the rest of the drive to Robert's version. It's not a py2 vs py3 thing since I tried both...

I'll try your suggestion, and make a new pull request if it works, next time I have down time between experiments at my setup. It's a kind of tedious process to edit in on the rasppi (a requirement so that I can test it) and then copy it over to my fork to pull request it, but I think it's worth it for now so you can suggest changes just like this.

except UnicodeDecodeError:
return 'could not decode reply'
if len(reply) == 0:
LOGGER.warning('No such device')
else:
Expand Down Expand Up @@ -100,8 +106,9 @@ def purge(self, t=1, addr=254):
self.comm(command1, addr)
print('PURGING')
time.sleep(abs(t))
self.comm(command2, addr)
print('DONE PURGING')
self.comm(command2, addr)
print('NORMAL MODE')

def read_flow(self, addr=254):
""" Read the flow """
Expand Down
4 changes: 2 additions & 2 deletions machines/rasppi89/socket_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def run(self):
#print qsize
while qsize > 0:
element = self.pushsocket.queue.get()
mfc = element.keys()[0]
mfc = list(element.keys())[0]
print(element[mfc])
print('Queue: ' + str(qsize))
value, addr = element[mfc], self.mfcs[mfc]
Expand Down Expand Up @@ -57,7 +57,7 @@ def run(self):

i = 0
MFCs = {}
MKS = mks.Mks_G_Series(port=port)
MKS = mks.MksGSeries(port=port)
for i in range(1, 8):
time.sleep(2)
print('!')
Expand Down