Skip to content

Commit a49bd74

Browse files
committed
Updated pyserial dependency to 3.0 and fixed API changes that made the script crash after pyserial was updated.
1 parent d8f043c commit a49bd74

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

BrewPiUtil.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def setupSerial(config, baud_rate=57600, time_out=0.1):
129129
else:
130130
port = portSetting
131131
try:
132-
ser = serial.Serial(port, baudrate=baud_rate, timeout=time_out, writeTimeout=0)
132+
ser = serial.Serial(port, baudrate=baud_rate, timeout=time_out, write_timeout=0)
133133
if ser:
134134
break
135135
except (IOError, OSError, serial.SerialException) as e:

backgroundserial.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ def __init__(self, serial_port):
2020

2121
# public interface only has 4 functions: start/stop/read_line/write
2222
def start(self):
23-
self.ser.writeTimeout = 1 # makes sure an exception is raised when serial is lost
23+
# write timeout will occur when there are problems with the serial port.
24+
# without the timeout loosing the serial port goes undetected.
25+
self.ser.write_timeout = 2
2426
self.run = True
2527
if not self.thread:
2628
self.thread = threading.Thread(target=self.__listenThread)

brewpi.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,18 @@
4141
# load non standard packages, exit when they are not installed
4242
try:
4343
import serial
44-
if LooseVersion(serial.VERSION) < LooseVersion("2.7"):
45-
printStdErr("BrewPi requires pyserial 2.7, you have version {0} installed.\n".format(serial.VERSION) +
44+
if LooseVersion(serial.VERSION) < LooseVersion("3.0"):
45+
printStdErr("BrewPi requires pyserial 3.0, you have version {0} installed.\n".format(serial.VERSION) +
4646
"Please upgrade pyserial via pip, by running:\n" +
4747
" sudo pip install pyserial --upgrade\n" +
4848
"If you do not have pip installed, install it with:\n" +
4949
" sudo apt-get install build-essential python-dev python-pip\n")
5050
sys.exit(1)
5151
except ImportError:
52-
printStdErr("BrewPi requires PySerial to run, please install it with 'sudo apt-get install python-serial")
52+
printStdErr("BrewPi requires PySerial to run, please install it via pip, by running:\n" +
53+
" sudo pip install pyserial --upgrade\n" +
54+
"If you do not have pip installed, install it with:\n" +
55+
" sudo apt-get install build-essential python-dev python-pip\n")
5356
sys.exit(1)
5457
try:
5558
import simplejson as json

brewpiVersion.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def getVersionFromSerial(ser):
2929
if not ser.isOpen():
3030
print "Cannot get version from serial port that is not open."
3131

32-
ser.setTimeout(1)
32+
ser.timeout = 1
3333
ser.write('n') # request version info
3434
while retries < 10:
3535
retry = True
@@ -61,7 +61,7 @@ def getVersionFromSerial(ser):
6161
retries += 1
6262
else:
6363
break
64-
ser.setTimeout(oldTimeOut) # restore previous serial timeout value
64+
ser.timeout = oldTimeOut # restore previous serial timeout value
6565
return version
6666

6767

0 commit comments

Comments
 (0)