コード例 #1
0
        /// <summary>
        /// Creates a new ModbusException from an error code
        /// </summary>
        /// <param name="errorCode">Error code</param>
        public ModbusException(ModbusErrorCode errorCode)
#if !NETMF
            : base(errorCode.ToString())
#endif
        {
            ErrorCode = errorCode;
        }
コード例 #2
0
      /// <summary>
      /// Creates a new ModbusException from an error code
      /// </summary>
      /// <param name="errorCode">Error code</param>
      public ModbusException(ModbusErrorCode errorCode)
#if !NETMF
         : base(errorCode.ToString())
#endif
      {
         ErrorCode = errorCode;
      }
コード例 #3
0
        private static string ErrorCodeToMessage(ModbusErrorCode code)
        {
            switch (code)
            {
            case ModbusErrorCode.UnknownFunction:
                return("The received function code can not be processed.");

            case ModbusErrorCode.InvalidAddress:
                return("The address specified in the request is not available.");

            case ModbusErrorCode.InvalidQuery:
                return("The value contained in the query data field is an invalid value.");

            case ModbusErrorCode.UnrecoverableError:
                return("An unrecoverable error occurred while the worker attempted to perform the requested action.");

            case ModbusErrorCode.WorkerTakesLongToProcess:
                return("The worker has accepted the request and processes it, but it takes a long time. This response prevents the host from generating a timeout error.");

            case ModbusErrorCode.WorkerBusy:
                return("The worker is busy processing the command. The client must repeat the message later when the worker is freed.");

            case ModbusErrorCode.WorkerCantExecuteFunction:
                return("The worker can not execute the program function specified in the request. This code is returned for an unsuccessful program request using functions with numbers 13 or 14. The client must request diagnostic information or error information from the worker.");

            case ModbusErrorCode.WorkerParityError:
                return("The worker detected a parity error when reading the extended memory. The client can repeat the request, but usually in such cases, repairs are required.");

            default:
                return("Unkown error!");
            }
        }
コード例 #4
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));
        }
コード例 #5
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));
        }
コード例 #6
0
        /// <summary>
        /// Sends a error result message.
        /// </summary>
        /// <param name="intf">Interface to send message to.</param>
        /// <param name="isBroadcast">true if the message is a broadcast. For broadcast messages no reponse is sent.</param>
        /// <param name="deviceAddress">Device address for response</param>
        /// <param name="telegramContext">Interface specific telegram context.</param>
        /// <param name="fc">Function code. The msg is automatically set.</param>
        /// <param name="modbusErrorCode">Modbus error code to send.</param>
        protected virtual void SendErrorResult(IModbusInterface intf, bool isBroadcast, byte deviceAddress, object telegramContext, ModbusFunctionCode fc, ModbusErrorCode modbusErrorCode)
        {
            if (isBroadcast)
            {
                return;
            }
            short telegramLength;
            short dataPos;

            intf.CreateTelegram(deviceAddress, (byte)((byte)fc | 0x80), 1, _buffer, out telegramLength, out dataPos, true, ref telegramContext);
            _buffer[dataPos] = (byte)modbusErrorCode;
            intf.SendTelegram(_buffer, telegramLength);
        }
コード例 #7
0
 internal ModbusRequestException(ModbusErrorCode code) : this(ErrorCodeToMessage(code))
 {
 }
コード例 #8
0
ファイル: ModbusDevice.cs プロジェクト: gremlinc5/ModbusLib
 /// <summary>
 /// Sends a error result message.
 /// </summary>
 /// <param name="intf">Interface to send message to.</param>
 /// <param name="isBroadcast">true if the message is a broadcast. For broadcast messages no reponse is sent.</param>
 /// <param name="deviceAddress">Device address for response</param>
 /// <param name="telegramContext">Interface specific telegram context.</param>
 /// <param name="fc">Function code. The msg is automatically set.</param>
 /// <param name="modbusErrorCode">Modbus error code to send.</param>
 protected virtual void SendErrorResult(IModbusInterface intf, bool isBroadcast, byte deviceAddress, object telegramContext, ModbusFunctionCode fc, ModbusErrorCode modbusErrorCode)
 {
    if (isBroadcast)
    {
       return;
    }
    short telegramLength;
    short dataPos;
    intf.CreateTelegram(deviceAddress, (byte)((byte)fc | 0x80), 1, _buffer, out telegramLength, out dataPos, true, ref telegramContext);
    _buffer[dataPos] = (byte)modbusErrorCode;
    intf.SendTelegram(_buffer, telegramLength);
 }