已为modbusTCP ip启用思科交换机...
cisco#show scada modbus tcp server
Summary: enabled, running, process id 330
Conn Stats: listening on port 502, 5 max simultaneous connections
0 current client connections
6 total accepted connections, 0 accept connection errors
6 closed connections, 0 close connection errors
Send Stats: 7 tcp msgs sent, 63 tcp bytes sent, 0 tcp errors
0 responses sent, 7 exceptions sent, 0 send errors
Recv Stats: 7 tcp msgs received, 84 tcp bytes received, 0 tcp errors
7 requests received, 0 receive errors...but如果我读出一个寄存器--> https://www.cisco.com/c/en/us/td/docs/switches/lan/cisco_ie3X00/software/17_3/b_cip-modbus_17-3_iot_switch_cg/m_modbus.html ...get back NONE用于演示目的,我确实使用了全部3个methods...to检查,如果它们生成了不同的..
if __name__ == "__main__":
try:
#create new object
c = ModbusClient(host=SERVER_HOST, port=SERVER_PORT, debug=False, auto_open=True)
except ValueError:
#something went whrong...wrong ip, server port ?
print("Error with host or port params")
#start the while loop
while loop:
try:
#connection is open
if c.is_open():
#loop through the coils
print(f"Connected to {SERVER_HOST}:{SERVER_PORT}")
print(c.read_coils(1000,64))
print(c.read_holding_registers(1000,64))
print(c.read_input_registers(1000,64))
loop = False
else:
#connection is not open
print(f"Trying to connect to {SERVER_HOST}: SERVER_PORT}")
#try to open it again
c.open()
#give it some time
sleep(1)
#break loop if keyboard interrupt...
except KeyboardInterrupt:
#break在执行时
Trying to connect to 192.168.178.95:502
Connect to 192.168.178.95:502
None
None
None设置"debug=True“
Trying to connect to 192.168.178.95:502
Connected to 192.168.178.95:502
Tx
[B5 1D 00 00 00 06 01] 01 03 E8 00 40
Rx
[B5 1D 00 00 00 03 01] 81 01
except (code 1)
None
Tx
[B7 1A 00 00 00 06 01] 03 03 E8 00 40
Rx
[B7 1A 00 00 00 03 01] 83 02
except (code 2)
None
Tx
[8B 3A 00 00 00 06 01] 04 03 E8 00 40
Rx
[8B 3A 00 00 00 03 01] 84 01
except (code 1)
Noneam work ...what I am wrong...using functions...
发布于 2021-06-24 07:55:02
应该使用十六进制格式的....0x1000
print(f"Connected to {SERVER_HOST}:{SERVER_PORT}")
#print(c.read_coils(0x1000,64))
print(c.read_holding_registers(0x1000,64))
#print(c.read_input_registers(0x1000,64))现在我得到了以下内容...
Trying to connect to 192.168.178.95:502
Connected to 192.168.178.95:502
[18281, 26465, 25193, 29765, 29800, 25970, 28261, 29745, 12081, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]https://stackoverflow.com/questions/68108051
复制相似问题