示例#1
0
        public static ModbusError Create(byte slaveId, byte functionCode, ModbusErrorCode errorCode)
        {
            ModbusError request = new ModbusError()
            {
                SlaveAddress = slaveId,
                FunctionCode = functionCode,
                ErrorCode    = errorCode,
                Protocol     = ProtocolType.RTU
            };

            byte[] encoded = request.Encode();
            return(ModbusError.Decode(encoded));
        }
示例#2
0
        public static ModbusError Create(byte unitId, ushort transactionId, ushort protocolId, byte functionCode, ModbusErrorCode errorCode)
        {
            ModbusError request = new ModbusError()
            {
                Header = new MbapHeader()
                {
                    ProtocolId = protocolId, TransactionId = transactionId, UnitId = unitId
                },
                SlaveAddress = unitId,
                FunctionCode = functionCode,
                ErrorCode    = errorCode,
                Protocol     = ProtocolType.TCP
            };

            byte[] rtuEncoded = request.Encode();
            return(ModbusError.Decode(rtuEncoded));
        }