protected override void Finished(string sid, string portName, string receivedData) { if (ModbusUtils.CRC("01", "02", "01 00").Equals(receivedData)) { this.handleResult(sid, portName, 0); return; } if (ModbusUtils.CRC("01", "02", "01 01").Equals(receivedData)) { this.handleResult(sid, portName, 1); return; } if (ModbusUtils.CRC("01", "02", "01 02").Equals(receivedData)) { this.handleResult(sid, portName, 2); return; } if (ModbusUtils.CRC("01", "02", "01 03").Equals(receivedData)) { this.handleResult(sid, portName, 3); return; } // TODO 记录异常日志 this.handleResult(sid, portName, -1); }
/// <summary> /// 入队一条指令(MODBUS协议) /// </summary> /// <param name="allowDiscard">是否允许丢弃该指令</param> /// <param name="cmdEventHandler">串口指令事件处理器</param> /// <param name="sendCMDTimeout">发送指令超时时长(毫秒)</param> /// <param name="reciveDataTimeout">接收数据超时时长(毫秒)</param> /// <param name="address">指令-地址码</param> /// <param name="func">指令-功能码</param> /// <param name="data">指令-数据</param> public void EnqueueModbus(Boolean allowDiscard, SerialPortCMDEventHandler cmdEventHandler, int sendCMDTimeout, int reciveDataTimeout, String address, String func, String data) { EnqueueHexString(allowDiscard, cmdEventHandler, sendCMDTimeout, reciveDataTimeout, ModbusUtils.CRC(address, func, data)); }
/// <summary> /// 写指令(MODBUS协议) /// </summary> /// <param name="address">指令-地址码</param> /// <param name="func">指令-功能码</param> /// <param name="data">指令-数据</param> public void WriteModbus(String address, String func, String data) { WriteHexString(ModbusUtils.CRC(address, func, data)); }