def __init__(self, name):
"""If possible, connect to serial port"""
# Try to establish connection to serial port
try:
self.serial_connection = serial.Serial(name, 9600)
self.serial_connection_established = True
# If it fails because there is no device, use virtual serial port
except serial.SerialException:
# Create virtual serial port
self.master, self.slave = pty.openpty()
self.vPort = os.ttyname(self.slave)
# Create instance
self.serial_connection = serial.Serial(self.vPort, 9600)
self.serial_connection_established = True
logging.warn("Trigger device not found -> Using virtual device")
# Create events
self.trigger_event = threading.Event()
self.eventProgramEnd = threading.Event()
# Store current time
self.last_trigger_time = time.time()
self.firstRun = True
# Call initialization of thread class
threading.Thread.__init__(self)
评论列表
文章目录