def start_tx(self, device): if self.__fr is None or self.__fw is None: self.open_for_bus(self.__bus) Lock.acquire(self.__class__.__name__, self.__LOCK_TIMEOUT) fcntl.ioctl(self.__fr, self.__I2C_SLAVE, device) fcntl.ioctl(self.__fw, self.__I2C_SLAVE, device)
def open(self, lock_timeout, comms_timeout): # lock... Lock.acquire(self.__lock_name, lock_timeout) # port... self._ser = serial.Serial(port=self.device_identifier, baudrate=self._baud_rate, timeout=comms_timeout) time.sleep(0.5) # as GE910 - 0.3
def start_tx(cls, device): if cls.__FR is None or cls.__FW is None: raise RuntimeError("I2C.start_tx: bus is not open.") Lock.acquire(cls.__name__, 1.0) fcntl.ioctl(cls.__FR, I2C.__I2C_SLAVE, device) fcntl.ioctl(cls.__FW, I2C.__I2C_SLAVE, device)
def open(self, lock_timeout, comms_timeout): # lock... Lock.acquire(self.__lock_name, lock_timeout) # serial... self._ser = serial.Serial(port=self.port, baudrate=self._baud_rate, timeout=comms_timeout, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS)
def open(self, lock_timeout, comms_timeout): # lock... Lock.acquire(self.__lock_name, lock_timeout) # port... self._ser = serial.Serial(port=self._device_identifier, baudrate=self._baud_rate, timeout=comms_timeout, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS) time.sleep(0.5) # as GE910 - 0.3
def __get_output(self, mask): if self.__device is None: return None Lock.acquire(IO.__lock_name(IO.__LOCK), IO.__LOCK_TIMEOUT) try: byte = self.__device.state.byte return bool(byte & mask) finally: Lock.release(IO.__lock_name(IO.__LOCK))
def __set_output(self, mask, level): if self.__device is None: return Lock.acquire(IO.__lock_name(IO.__LOCK), IO.__LOCK_TIMEOUT) try: byte = self.__device.state.byte if level: byte |= mask else: byte &= ~mask self.__device.write(byte) self.__device.state = byte finally: Lock.release(IO.__lock_name(IO.__LOCK))
def obtain_lock(self): Lock.acquire(self.__class__.__name__, MCP342X.__LOCK_TIMEOUT)
def obtain_lock(cls): Lock.acquire(cls.__name__, SPINDIRx1.__LOCK_TIMEOUT)
def obtain_lock(self): Lock.acquire(self.lock_name, self.lock_timeout())
def obtain_lock(self): Lock.acquire(self.__lock_name, ADS1115.__LOCK_TIMEOUT)
def obtain_lock(cls): Lock.acquire(cls.__name__, OPCN2.__LOCK_TIMEOUT)
#!/usr/bin/env python3 """ Created on 17 Mar 2017 @author: Bruno Beloff ([email protected]) """ import os from scs_host.lock.lock import Lock # -------------------------------------------------------------------------------------------------------------------- resource = "test" print("resource: %s" % resource) print("pid: %s" % os.getpid()) # -------------------------------------------------------------------------------------------------------------------- print("attempt 1...") Lock.acquire(resource, 2) print("OK") print("-") print("attempt 2...") Lock.acquire(resource, 2) print("OK") print("-")
def acquire_lock(self): Lock.acquire(self.__lock_name, SPI.__LOCK_TIMEOUT)
def obtain_lock(cls): Lock.acquire(cls.__lock_name(), DS1338.__LOCK_TIMEOUT)
def start_tx(self): Lock.acquire(self.__lock_name(GE910.__LOCK_TX), GE910.__LOCK_TIMEOUT)
def start_tx(self): Lock.acquire(self.__lock_name(Modem.__LOCK_PWR), Modem.__LOCK_TIMEOUT)
# -------------------------------------------------------------------------------------------------------------------- name = "TestLock" exists = Lock.exists(name) print("exists: %s" % exists) pid = Lock.pid(name) print("pid: %s" % str(pid)) print("-") # -------------------------------------------------------------------------------------------------------------------- Lock.acquire(name, 4.0) print("locked...") try: exists = Lock.exists(name) print("exists: %s" % exists) pid = Lock.pid(name) print("pid: %s" % str(pid)) print("-") while True: time.sleep(1)