Esempio n. 1
0
            protected bool CheckModbusHeader(byte[] Message, int MessageLength)
            {
                int Length = ((int)(Message[4]) << 8) + (int)(Message[5]);

                bool IsOK = false;

                if (MessageLength < 9)
                {
                    //??EventMBusException(this, new ModBusException(ModBusException.ModBusExceptionCodeEnum.ResponseFormatError));
                }
                else if (Length + 6 != MessageLength)
                {
                    //??EventMBusException(this, new ModBusException(ModBusException.ModBusExceptionCodeEnum.ResponseFormatError));
                }
                else if ((Message[7] & 0x80) > 0)
                {//skip non FC
                    ModBusException.ModBusExceptionCodeEnum Code = (ModBusException.ModBusExceptionCodeEnum)Message[8];
                    //??EventMBusException(this, new ModBusException(Code));
                }
                else
                {
                    m_FC      = Message[7];
                    m_TransID = Message[0] << 8 + Message[1];
                    IsOK      = true;
                }

                return(IsOK);
            }
Esempio n. 2
0
        protected virtual void OnMBusException(ModBusException.ModBusExceptionCodeEnum Code)
        {
            // Make a temporary copy of the event to avoid possibility of
            // a race condition if the last subscriber unsubscribes
            // immediately after the null check and before the event is raised.
            MBusException   handler = EventMBusException;
            ModBusException e       = new ModBusException(Code);

            // Event will be null if there are no subscribers
            if (handler != null)
            {
                // Use the () operator to raise the event.
                handler(this, e);
            }
        }
Esempio n. 3
0
        protected bool CheckModbusHeader(Int16 TransID, byte FC, byte[] Message, int MessageLength)
        {
            byte TransId0 = (byte)((TransID & 0xFF00) >> 8);
            byte TransId1 = (byte)(TransID & 0xFF);


            bool IsOK = false;

            if (MessageLength < 9)
            {
                OnMBusException(ModBusException.ModBusExceptionCodeEnum.ResponseFormatError);
            }
            else
            {
                int Length = ((int)(Message[4]) << 8) + (int)(Message[5]);
                if (Message[0] != TransId0 || Message[1] != TransId1)
                {
                    OnMBusException(ModBusException.ModBusExceptionCodeEnum.ResponseFormatError);
                }
                else if (Message[7] != FC)
                {
                    OnMBusException(ModBusException.ModBusExceptionCodeEnum.ResponseFormatError);
                }
                else if (Length + 6 != MessageLength)
                {
                    OnMBusException(ModBusException.ModBusExceptionCodeEnum.ResponseFormatError);
                }
                else if ((Message[7] & 0x80) > 0)
                {
                    ModBusException.ModBusExceptionCodeEnum Code = (ModBusException.ModBusExceptionCodeEnum)Message[8];
                    OnMBusException(Code);
                }
                else
                {
                    IsOK = true;
                }
            }
            return(IsOK);
        }
Esempio n. 4
0
 private void OnMBusException(ModBusException.ModBusExceptionCodeEnum Code)
 {
 }