# but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with BrewPi. If not, see <http://www.gnu.org/licenses/>. from __future__ import print_function import sys from BrewPiUtil import printStdErr from BrewPiUtil import logMessage # Check needed software dependencies to nudge users to fix their setup if sys.version_info < (2, 7): printStdErr("Sorry, requires Python 2.7.") sys.exit(1) # standard libraries import time import socket import os import getopt from pprint import pprint import shutil import traceback import urllib from distutils.version import LooseVersion from serial import SerialException # brewometer code
# but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with BrewPi. If not, see <http://www.gnu.org/licenses/>. from __future__ import print_function import sys from BrewPiUtil import printStdErr from BrewPiUtil import logMessage # Check needed software dependencies to nudge users to fix their setup if sys.version_info < (2, 7): printStdErr("Sorry, requires Python 2.7.") sys.exit(1) # standard libraries import time import socket import os import getopt from pprint import pprint import shutil import traceback import urllib from distutils.version import LooseVersion from serial import SerialException # load non standard packages, exit when they are not installed
# remove extended ascii characters from string, because they can raise UnicodeDecodeError later def __asciiToUnicode(self, s): s = s.replace(chr(0xB0), '°') return unicode(s, 'ascii', 'ignore') if __name__ == '__main__': # some test code that requests data from serial and processes the response json import simplejson import time import BrewPiUtil as util config_file = util.addSlash(sys.path[0]) + 'settings/config.cfg' config = util.readCfgWithDefaults(config_file) ser = util.setupSerial(config, time_out=0) if not ser: printStdErr("Could not open Serial Port") exit() bg_ser = BackGroundSerial(ser) bg_ser.start() success = 0 fail = 0 for i in range(1, 5): # request control variables 4 times. This would overrun buffer if it was not read in a background thread # the json decode will then fail, because the message is clipped bg_ser.write('v') bg_ser.write('v') bg_ser.write('v') bg_ser.write('v') bg_ser.write('v')
def logError(*objs): global usedts if usedts: printStdErr(strftime("%Y-%m-%d %H:%M:%S "), *objs) else: printStdErr(*objs)