Skip to content

Commit

Permalink
Updated pyserial dependency to 3.0 and fixed API changes that made th…
Browse files Browse the repository at this point in the history
…e script crash after pyserial was updated.
  • Loading branch information
elcojacobs committed Dec 31, 2015
1 parent d8f043c commit a49bd74
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion BrewPiUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion backgroundserial.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 6 additions & 3 deletions brewpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions brewpiVersion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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


Expand Down

0 comments on commit a49bd74

Please sign in to comment.