def test_alreadyinuse(self): """Test 'already in use' warning""" GPIO.setwarnings(False) with open('/sys/class/gpio/export','wb') as f: f.write(str(LED_PIN_BCM).encode()) with open('/sys/class/gpio/gpio%s/direction'%LED_PIN_BCM,'wb') as f: f.write(b'out') with open('/sys/class/gpio/gpio%s/value'%LED_PIN_BCM,'wb') as f: f.write(b'1') with warnings.catch_warnings(record=True) as w: GPIO.setup(LED_PIN, GPIO.OUT) # generate 'already in use' warning self.assertEqual(len(w),0) # should be no warnings with open('/sys/class/gpio/unexport','wb') as f: f.write(str(LED_PIN_BCM).encode()) GPIO.cleanup() GPIO.setwarnings(True) with open('/sys/class/gpio/export','wb') as f: f.write(str(LED_PIN_BCM).encode()) with open('/sys/class/gpio/gpio%s/direction'%LED_PIN_BCM,'wb') as f: f.write(b'out') with open('/sys/class/gpio/gpio%s/value'%LED_PIN_BCM,'wb') as f: f.write(b'1') with warnings.catch_warnings(record=True) as w: GPIO.setup(LED_PIN, GPIO.OUT) # generate 'already in use' warning self.assertEqual(w[0].category, RuntimeWarning) with open('/sys/class/gpio/unexport','wb') as f: f.write(str(LED_PIN_BCM).encode()) GPIO.cleanup()
def init(self): GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(self.pin1,GPIO.OUT) GPIO.setup(self.pin2,GPIO.OUT) GPIO.setup(self.pin3,GPIO.OUT) GPIO.setup(self.pin4,GPIO.OUT) self.zeroPosition() return
def test_cleanupwarning(self): """Test initial GPIO.cleanup() produces warning""" GPIO.setwarnings(False) GPIO.setup(SWITCH_PIN, GPIO.IN) with warnings.catch_warnings(record=True) as w: GPIO.cleanup() self.assertEqual(len(w),0) # no warnings GPIO.cleanup() self.assertEqual(len(w),0) # no warnings GPIO.setwarnings(True) GPIO.setup(SWITCH_PIN, GPIO.IN) with warnings.catch_warnings(record=True) as w: GPIO.cleanup() self.assertEqual(len(w),0) # no warnings GPIO.cleanup() self.assertEqual(w[0].category, RuntimeWarning) # a warning
import datetime from Tkinter import Tk from array import array import LMK.GPIO as GPIO import step_motor as StepMotor import RTC_DS1307 import IOboard ver_BOARD = GPIO.LMK_REVISION if ver_BOARD == 2: import DHTreader2 as DHTreader if ver_BOARD == 3: import DHTreader3 as DHTreader GPIO.setmode(GPIO.BCM) GPIO.setwarnings(True) stepM1 = StepMotor.Motor(11,7,16,26) stepM2 = StepMotor.Motor(4,25,24,23) root = Tk() root.withdraw() Bus = smbus.SMBus(2) PORT = 42001 HOST = "localhost" Debug = False Connected = False Setup = False I2Csetup = False