def main(): disp = Dispatcher() Tasklet.new(disp.loop)() host = Host(disp, "/dev/ttySP1") disp.add_host(host) while True: host.send([0x45])
def open_ports(self, port1, port2): host1 = Host(self, port1) host2 = Host(self, port2) self.add_host(host1) self.add_host(host2) ver1 = host1.version() if ver1 is None: raise HardwareError("No response on %s" % port1) ver2 = host2.version() if ver2 is None: raise HardwareError("No response on %s" % port2) if ver1 != 1 and ver1 != 2: raise HardwareError("Unknown device version %s" % ver1) if ver2 != 1 and ver2 != 2: raise HardwareError("Unknown device version %s" % ver2) if ver1 == ver2: raise HardwareError("Both devices have the same version %s" % ver1) if ver1 == 1: self.relayscontrol = host1 self.maincontrol = host2 else: self.maincontrol = host1 self.relayscontrol = host2