RS485_UART = (1, 25, 21) # TX,RX IIC_PORTA = (26, 32) # I2C for 16BV demo unit.PORTA = ( 26, 32 ) # seems used in the unit init!unit.get(unit.RFID, unit.PORTA) # fit ATOM? #i2c0 = i2c_bus.easyI2C((25, 21), 0x28) print('< Intelligent 16-BV connector with RS485 modbus & NFC program v0.7 >' + "\r\n") print('< Author: Ling.Zell, [email protected], 27.July.2020 >' + "\r\n") print('#-->:i2c_bus.easyI2C(PORTA, 0x28, freq=100000)') print('#-->:RS485_UART: TX_G25,RX_G21@ 115200') #print('#-->: i2c_bus.easyI2C(i2c_bus.PORTA, 0x28, freq=400000)') i2c0 = i2c_bus.easyI2C(IIC_PORTA, 0x28, freq=100000) RFID_ID_pre = '00000000' modbus_s.init_function(4, 1, 100, ModbusSlave.METHOD_WRITE) modbus_s.init_function(3, 1, 100, ModbusSlave.METHOD_READ) def calc_crc(data): crc = 0xFFFF for pos in data: crc ^= pos for i in range(8): if ((crc & 1) != 0): crc >>= 1 crc ^= 0xA001 else: crc >>= 1 return crc
Slave_add = None RTU_funct = None value_rx_tmp = None REG_0 = None def modbus_recv_cb(x): global Slave_add, RTU_funct, value_rx_tmp, REG_0 Slave_add, RTU_funct, value_rx_tmp = x.read() label_Slave_add.setText(str(Slave_add)) Funct.setText(str(RTU_funct)) Data.setText(str(value_rx_tmp)) pass modbus.set_recv_cb(modbus_recv_cb) def buttonA_wasPressed(): global Slave_add, RTU_funct, value_rx_tmp, REG_0 modbus_s.send(Slave_add, RTU_funct, REG_0, 1234) pass btnA.wasPressed(buttonA_wasPressed) Slave_add = 1 modbus_s.init_function(RTU_funct, REG_0, 101, ModbusSlave.METHOD_READ) rgb.setColorAll(0x33ff33)