diff --git a/BrewPiUtil.py b/BrewPiUtil.py index ae51185..97556a0 100644 --- a/BrewPiUtil.py +++ b/BrewPiUtil.py @@ -129,7 +129,7 @@ def setupSerial(config, baud_rate=57600, time_out=0.1): else: port = portSetting try: - ser = serial.Serial(port, baudrate=baud_rate, timeout=time_out, writeTimeout=0) + ser = serial.Serial(port, baudrate=baud_rate, timeout=time_out, write_timeout=0) if ser: break except (IOError, OSError, serial.SerialException) as e: diff --git a/backgroundserial.py b/backgroundserial.py index d96858b..60acdb6 100644 --- a/backgroundserial.py +++ b/backgroundserial.py @@ -20,7 +20,9 @@ def __init__(self, serial_port): # public interface only has 4 functions: start/stop/read_line/write def start(self): - self.ser.writeTimeout = 1 # makes sure an exception is raised when serial is lost + # write timeout will occur when there are problems with the serial port. + # without the timeout loosing the serial port goes undetected. + self.ser.write_timeout = 2 self.run = True if not self.thread: self.thread = threading.Thread(target=self.__listenThread) diff --git a/brewpi.py b/brewpi.py index 30ea24b..3f93cfb 100644 --- a/brewpi.py +++ b/brewpi.py @@ -41,15 +41,18 @@ # load non standard packages, exit when they are not installed try: import serial - if LooseVersion(serial.VERSION) < LooseVersion("2.7"): - printStdErr("BrewPi requires pyserial 2.7, you have version {0} installed.\n".format(serial.VERSION) + + if LooseVersion(serial.VERSION) < LooseVersion("3.0"): + printStdErr("BrewPi requires pyserial 3.0, you have version {0} installed.\n".format(serial.VERSION) + "Please upgrade pyserial via pip, by running:\n" + " sudo pip install pyserial --upgrade\n" + "If you do not have pip installed, install it with:\n" + " sudo apt-get install build-essential python-dev python-pip\n") sys.exit(1) except ImportError: - printStdErr("BrewPi requires PySerial to run, please install it with 'sudo apt-get install python-serial") + printStdErr("BrewPi requires PySerial to run, please install it via pip, by running:\n" + + " sudo pip install pyserial --upgrade\n" + + "If you do not have pip installed, install it with:\n" + + " sudo apt-get install build-essential python-dev python-pip\n") sys.exit(1) try: import simplejson as json diff --git a/brewpiVersion.py b/brewpiVersion.py index 9503791..8279628 100644 --- a/brewpiVersion.py +++ b/brewpiVersion.py @@ -29,7 +29,7 @@ def getVersionFromSerial(ser): if not ser.isOpen(): print "Cannot get version from serial port that is not open." - ser.setTimeout(1) + ser.timeout = 1 ser.write('n') # request version info while retries < 10: retry = True @@ -61,7 +61,7 @@ def getVersionFromSerial(ser): retries += 1 else: break - ser.setTimeout(oldTimeOut) # restore previous serial timeout value + ser.timeout = oldTimeOut # restore previous serial timeout value return version