def __init__(self): self.rawOutput = None # setting pimodel = getrpimodel.model pimodel_strict = getrpimodel.model_strict() if os.path.exists('/dev/serial0'): partial_serial_dev = 'serial0' elif pimodel == "3 Model B" or pimodel_strict == "Zero W": partial_serial_dev = 'ttyS0' else: partial_serial_dev = 'ttyAMA0' self.serial_dev = '/dev/%s' % partial_serial_dev self.ser = serial.Serial( port=self.serial_dev, #Replace ttyS0 with ttyAM0 for Pi1,Pi2,Pi0 baudrate=38400) #set the default units on probe self.ser.write(str.encode("D0" + '\r')) self.ser.write(str.encode("SC" + '\r'))
import sys import getrpimodel usage = 'Usage: python {} [--s]'.format(__file__) if len(sys.argv) == 1: print(getrpimodel.model()) elif len(sys.argv) == 2: if sys.argv[1] == '--s': print(getrpimodel.model_strict()) else: print usage else: print usage
import serial import time import subprocess import traceback import getrpimodel import struct import platform import argparse import sys import json import os.path # setting version = "2.6.1" pimodel = getrpimodel.model pimodel_strict = getrpimodel.model_strict() if os.path.exists('/dev/serial0'): partial_serial_dev = 'serial0' elif pimodel == "3 Model B" or pimodel_strict == "Zero W": partial_serial_dev = 'ttyS0' else: partial_serial_dev = 'ttyAMA0' serial_dev = '/dev/%s' % partial_serial_dev #stop_getty = 'sudo systemctl stop serial-getty@%s.service' % partial_serial_dev #start_getty = 'sudo systemctl start serial-getty@%s.service' % partial_serial_dev # major version of running python p_ver = platform.python_version_tuple()[0]