Пример #1
0
        protected override void Decode(IChannelHandlerContext context, IByteBuffer input, List <object> output)
        {
            //Transaction Identifier + Protocol Identifier + Length + Unit Identifier + Function Code
            if (input.Capacity < 2 + 2 + 2 + 1 + 1)
            {
                return;
            }

            ModbusHeader   header       = new ModbusHeader(input);
            short          functionCode = input.ReadByte();
            ModbusFunction function     = null;

            if (Enum.IsDefined(typeof(ModbusCommand), functionCode))
            {
                var command = Enum.GetName(typeof(ModbusCommand), functionCode);

                function = (ModbusFunction)Activator.CreateInstance(Type.GetType(string.Format(typeName, isServerMode ? "Request" : "Response", command)));
            }


            if (functionCode >= maxFunctionCode)
            {
                function = new ExceptionFunction(functionCode);
            }
            else if (function == null)
            {
                function = new ExceptionFunction(functionCode, 0x01);
            }

            function.Decode(input);
            ModbusFrame frame = new ModbusFrame(header, function);

            output.Add(frame);
        }
Пример #2
0
        public OneWireException(ExceptionFunction function, Identifier deviceId)
        {
            // Store the exception function
            Function = function;

            // Store the device ID
            DeviceId = deviceId;
        }
Пример #3
0
        public OneWireException(ExceptionFunction function, int number)
        {
            // Store the exception function
            Function = function;

            // Store the exception number
            Number = number;
        }
Пример #4
0
        public OneWireException(ExceptionFunction function, Identifier deviceId, int number)
        {
            // Store the exception function
            Function = function;

            // Store the device ID
            DeviceId = deviceId;

            // Store the exception number
            Number = number;
        }