#role = b"operator\x00" role = b"admin\x00\x00\x00\x00" roleNameAddr = 7473 msg = writeMultRegs(1, roleNameAddr, role) sockSend(msg, s) #passW = b"O!h11111" passW = b"Coriolis5700" tempPassAddr = 7466 msg = writeMultRegs(2, tempPassAddr, passW) sockSend(msg, s) sleep(0.250) loginStatusAddr = 7445 sessionStatusAddr = 7444 msg = readRegs(3, loginStatusAddr, 1) respMsg = sockSend(msg, s) if respMsg[7] != 0x83: if respMsg[10] == 0x00: print("WAITING") if respMsg[10] == 0x01: print("LOCKED_OUT") if respMsg[10] == 0x02: print("INVALID_CREDS") if respMsg[10] == 0x03: print("AUTHENTICATED") if respMsg[10] == 0x04: print("NO_SESSIONS_AVAIL") msg = readRegs(3, sessionStatusAddr, 1) respMsg = sockSend(msg, s)
from mbUtils import writeMultRegs, sockSend, readRegs, readCoils import socket import math from struct import * s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) mbReglist = ["0"] mbCoilList = ["0"] numScanRegs = 40 numScanCoils = 700 try: s.connect(("192.168.0.2", 502)) for x in range(1, numScanRegs): msg = readRegs(x, x, 1) respMsg = sockSend(msg, s) if respMsg[7] != 0x83: mbReglist.append(x) for x in range(1, numScanCoils): msg = readCoils(x, x, 1) respMsg = sockSend(msg, s) if respMsg[7] != 0x81: mbCoilList.append(x) print("Registers=") print(*mbReglist, sep=", ") print("Coils=") print(*mbCoilList, sep=", ") finally:
from mbUtils import writeMultRegs, sockSend, readRegs,readCoils, readDiscInput from time import sleep import socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: s.connect(("192.168.0.2", 502)) Addr = 527 msg = readRegs(3, Addr, 6) sockSend(msg, s) finally: print("end") s.close()