예제 #1
0
        /// <summary>
        /// Build an exception message
        /// </summary>
        /// <param name="send_buffer">Send buffer</param>
        /// <param name="code">Modbus operation code</param>
        /// <param name="error">Error code</param>
        void BuildExceptionMessage(List <byte> send_buffer, ModbusCodes code, Errors error)
        {
            byte exception_code = 0;

            send_buffer.Clear();
            switch (error)
            {
            case Errors.EXCEPTION_ILLEGAL_FUNCTION:
                exception_code = 1;
                break;

            case Errors.EXCEPTION_ILLEGAL_DATA_ADDRESS:
                exception_code = 2;
                break;

            case Errors.EXCEPTION_ILLEGAL_DATA_VALUE:
                exception_code = 3;
                break;

            case Errors.EXCEPTION_SLAVE_DEVICE_FAILURE:
                exception_code = 4;
                break;
            }
            // Add exception identifier
            send_buffer.Add((byte)(0x80 + (byte)code));
            // Add exception code
            send_buffer.Add(exception_code);
        }
예제 #2
0
파일: Modbus.cs 프로젝트: eprimo/Modbus-RTU
        /// <summary>
        /// Build an exception message
        /// </summary>
        /// <param name="send_buffer">Send buffer</param>
        /// <param name="code">Modbus operation code</param>
        /// <param name="error">Error code</param>
        void BuildExceptionMessage(List<byte> send_buffer, ModbusCodes code, Errors error)
        {
            byte exception_code = 0;

            send_buffer.Clear();
            switch (error)
            {
                case Errors.EXCEPTION_ILLEGAL_FUNCTION:
                    exception_code = 1;
                    break;

                case Errors.EXCEPTION_ILLEGAL_DATA_ADDRESS:
                    exception_code = 2;
                    break;

                case Errors.EXCEPTION_ILLEGAL_DATA_VALUE:
                    exception_code = 3;
                    break;

                case Errors.EXCEPTION_SLAVE_DEVICE_FAILURE:
                    exception_code = 4;
                    break;
            }
            // Add exception identifier
            send_buffer.Add((byte)(0x80 + (byte)code));
            // Add exception code
            send_buffer.Add(exception_code);
        }