public ModbusServer(string ip, ushort port) { this.ip = ip; this.port = port; this.modbusMaster = new Master(ip, port); }
void modbusMaster_OnException(Master obj, ushort id, byte function, byte exception) { if (modbusMaster == obj) { Logger.Error("Ошибка при чтении данных " + CurrentServer.IP + ":" + CurrentServer.Port); if (OnError != null) { OnError(); } } }
void modbusMaster_OnResponseData(Master obj, ushort id, byte function, byte[] data) { if (modbusMaster == obj) { if (OnResponse != null) { OnResponse(id, function, data); } } }
public void Init() { if (this.modbusMaster != null) { this.modbusMaster.OnException -= exceptionEvent; this.modbusMaster.OnResponseData -= responseEvent; try { modbusMaster.disconnect(); } catch { } } this.modbusMaster = new Master(); this.modbusMaster.OnException += exceptionEvent; this.modbusMaster.OnResponseData += responseEvent; this.modbusMaster.timeout = 500; }