def __init__(self, port, addr): self.addr = addr # 485地址 self.switch_mode = 0 # 干接点模式 1:长触模式,0:短触模式 self.switch_status = [0, 0, 0] # 干接点状态 self.relay_status = [0, 0, 0] # 继电器状态 self.id = [] self.baudrate = int(cf.get("serial", "baudrate")) self.bytesize = int(cf.get("serial", "bytesize")) self.parity = int(cf.get("serial", "parity")) self.stop = int(cf.get("serial", "stop")) ModbusWindows.__init__(self, PORT=port, BAUDR=BAUD_LIST[self.baudrate - 1], BSIZE=BYTE_LIST[self.bytesize - 1], PAR=PARITY_LIST[self.parity - 1], BSTOP=STOP_LIST[self.stop - 1], TIMEOUT=1000)
def __init__(self, port, addr): self.addr = addr # 485地址 self.switch_mode = 0 # 干接点模式 1:长触模式,0:短触模式 self.switch_status = [0, 0, 0] # 干接点状态 self.relay_status = [0, 0, 0] # 继电器状态 self.id = [] self.baudrate = int(cf.get("serial", "baudrate")) self.bytesize = int(cf.get("serial", "bytesize")) self.parity = int(cf.get("serial", "parity")) self.stop = int(cf.get("serial", "stop")) ModbusWindows.__init__( self, PORT=port, BAUDR=BAUD_LIST[self.baudrate - 1], BSIZE=BYTE_LIST[self.bytesize - 1], PAR=PARITY_LIST[self.parity - 1], BSTOP=STOP_LIST[self.stop - 1], TIMEOUT=1000, )
def read(self, length): read_raw = ModbusWindows.read(self, length) return list(unpack('B' * len(read_raw), str(bytearray(read_raw))))
def write(self, cmd): ModbusWindows.write(self, List2Ascii(cmd))
def read(self, length): read_raw = ModbusWindows.read(self, length) return list(unpack("B" * len(read_raw), str(bytearray(read_raw))))