Example #1
0
        public AdsErrorCode AdsDeviceNotificationReq(AmsAddress rAddr, uint invokeId, uint numStampHeaders, TcAdsStampHeader[] notificationHeaders)
        {
            TcAdsDeviceNotificationReqHeader adsHeader = new TcAdsDeviceNotificationReqHeader {
                _numStamps = numStampHeaders
            };

            byte[] adsData = TcAdsParser.BuildDeviceNotificationBuffer(notificationHeaders);
            adsHeader._cbData = (uint)adsData.Length;
            return(this.AdsRequest(rAddr, invokeId, 8, (uint)adsData.Length, adsHeader, adsData));
        }
Example #2
0
        private AdsErrorCode AdsRequest(AmsAddress rAddr, uint invokeId, ushort serviceId, uint cbLength, ITcAdsHeader adsHeader, byte[] adsData)
        {
            uint num = 0;

            if (adsHeader != null)
            {
                num = (uint)Marshal.SizeOf(adsHeader);
            }
            TcAmsHeader amsHeader = new TcAmsHeader(rAddr, this.Address, serviceId, 4, num + cbLength, 0, invokeId);

            return(this._amsServer.Send(new TcAmsCommand(amsHeader, TcAdsParser.BuildAdsBuffer(adsHeader, adsData))));
        }
Example #3
0
        private void OnAmsReceive(TcAmsCommand amsCmd)
        {
            byte[] data            = amsCmd.Data;
            uint   indexGroup      = 0;
            uint   cbLength        = 0;
            uint   cbWriteLength   = 0;
            uint   numStampHeaders = 0;

            if (amsCmd.AmsHeader.StateFlags != 4)
            {
                if (amsCmd.AmsHeader.StateFlags == 5)
                {
                    AdsErrorCode code;
                    switch (amsCmd.AmsHeader.CommandId)
                    {
                    case 1:
                    {
                        AdsVersion version = new AdsVersion();
                        if (amsCmd.AmsHeader.ErrCode != 0)
                        {
                            this.AdsReadDeviceInfoCon(amsCmd.AmsHeader.Sender, amsCmd.AmsHeader.HUser, (AdsErrorCode)amsCmd.AmsHeader.ErrCode, null, version);
                            return;
                        }
                        code             = (AdsErrorCode)TcAdsParser.ReadUInt(data, 0);
                        version.Version  = data[4];
                        version.Revision = data[5];
                        version.Build    = TcAdsParser.ReadUShort(data, 6);
                        this.AdsReadDeviceInfoCon(amsCmd.AmsHeader.Sender, amsCmd.AmsHeader.HUser, code, TcAdsParser.ReadString(data, 8, 0x10), version);
                        return;
                    }

                    case 2:
                        if (amsCmd.AmsHeader.ErrCode != 0)
                        {
                            this.AdsReadCon(amsCmd.AmsHeader.Sender, amsCmd.AmsHeader.HUser, (AdsErrorCode)amsCmd.AmsHeader.ErrCode, 0, null);
                            return;
                        }
                        code     = (AdsErrorCode)TcAdsParser.ReadUInt(data, 0);
                        cbLength = TcAdsParser.ReadUInt(data, 4);
                        this.AdsReadCon(amsCmd.AmsHeader.Sender, amsCmd.AmsHeader.HUser, code, cbLength, TcAdsParser.AdsData(data, 8, cbLength));
                        return;

                    case 3:
                        if (amsCmd.AmsHeader.ErrCode != 0)
                        {
                            this.AdsWriteCon(amsCmd.AmsHeader.Sender, amsCmd.AmsHeader.HUser, (AdsErrorCode)amsCmd.AmsHeader.ErrCode);
                            return;
                        }
                        code = (AdsErrorCode)TcAdsParser.ReadUInt(data, 0);
                        this.AdsWriteCon(amsCmd.AmsHeader.Sender, amsCmd.AmsHeader.HUser, code);
                        return;

                    case 4:
                        if (amsCmd.AmsHeader.ErrCode != 0)
                        {
                            this.AdsReadStateCon(amsCmd.AmsHeader.Sender, amsCmd.AmsHeader.HUser, (AdsErrorCode)amsCmd.AmsHeader.ErrCode, AdsState.Invalid, 0);
                            return;
                        }
                        code = (AdsErrorCode)TcAdsParser.ReadUInt(data, 0);
                        this.AdsReadStateCon(amsCmd.AmsHeader.Sender, amsCmd.AmsHeader.HUser, code, (AdsState)((short)TcAdsParser.ReadUShort(data, 4)), TcAdsParser.ReadUShort(data, 6));
                        return;

                    case 5:
                        if (amsCmd.AmsHeader.ErrCode != 0)
                        {
                            this.AdsWriteControlCon(amsCmd.AmsHeader.Sender, amsCmd.AmsHeader.HUser, (AdsErrorCode)amsCmd.AmsHeader.ErrCode);
                            return;
                        }
                        code = (AdsErrorCode)TcAdsParser.ReadUInt(data, 0);
                        this.AdsWriteControlCon(amsCmd.AmsHeader.Sender, amsCmd.AmsHeader.HUser, code);
                        return;

                    case 6:
                        if (amsCmd.AmsHeader.ErrCode != 0)
                        {
                            this.AdsAddDeviceNotificationCon(amsCmd.AmsHeader.Sender, amsCmd.AmsHeader.HUser, (AdsErrorCode)amsCmd.AmsHeader.ErrCode, 0);
                            return;
                        }
                        code = (AdsErrorCode)TcAdsParser.ReadUInt(data, 0);
                        this.AdsAddDeviceNotificationCon(amsCmd.AmsHeader.Sender, amsCmd.AmsHeader.HUser, code, TcAdsParser.ReadUInt(data, 4));
                        return;

                    case 7:
                        if (amsCmd.AmsHeader.ErrCode != 0)
                        {
                            this.AdsDelDeviceNotificationCon(amsCmd.AmsHeader.Sender, amsCmd.AmsHeader.HUser, (AdsErrorCode)amsCmd.AmsHeader.ErrCode);
                            return;
                        }
                        code = (AdsErrorCode)TcAdsParser.ReadUInt(data, 0);
                        this.AdsDelDeviceNotificationCon(amsCmd.AmsHeader.Sender, amsCmd.AmsHeader.HUser, code);
                        return;

                    case 8:
                        break;

                    case 9:
                        if (amsCmd.AmsHeader.ErrCode != 0)
                        {
                            this.AdsReadWriteCon(amsCmd.AmsHeader.Sender, amsCmd.AmsHeader.HUser, (AdsErrorCode)amsCmd.AmsHeader.ErrCode, 0, null);
                            break;
                        }
                        code     = (AdsErrorCode)TcAdsParser.ReadUInt(data, 0);
                        cbLength = TcAdsParser.ReadUInt(data, 4);
                        this.AdsReadWriteCon(amsCmd.AmsHeader.Sender, amsCmd.AmsHeader.HUser, code, cbLength, TcAdsParser.AdsData(data, 8, cbLength));
                        return;

                    default:
                        return;
                    }
                }
            }
            else
            {
                switch (amsCmd.AmsHeader.CommandId)
                {
                case 1:
                    this.AdsReadDeviceInfoInd(amsCmd.AmsHeader.Sender, amsCmd.AmsHeader.HUser);
                    return;

                case 2:
                    indexGroup = TcAdsParser.ReadUInt(data, 0);
                    this.AdsReadInd(amsCmd.AmsHeader.Sender, amsCmd.AmsHeader.HUser, indexGroup, TcAdsParser.ReadUInt(data, 4), TcAdsParser.DataLength(data, 8));
                    return;

                case 3:
                    indexGroup = TcAdsParser.ReadUInt(data, 0);
                    cbLength   = TcAdsParser.DataLength(data, 8);
                    this.AdsWriteInd(amsCmd.AmsHeader.Sender, amsCmd.AmsHeader.HUser, indexGroup, TcAdsParser.ReadUInt(data, 4), cbLength, TcAdsParser.AdsData(data, 12, cbLength));
                    return;

                case 4:
                    this.AdsReadStateInd(amsCmd.AmsHeader.Sender, amsCmd.AmsHeader.HUser);
                    return;

                case 5:
                {
                    AdsState adsState = TcAdsParser.AdsState(data);
                    cbLength = TcAdsParser.DataLength(data, 4);
                    this.AdsWriteControlInd(amsCmd.AmsHeader.Sender, amsCmd.AmsHeader.HUser, adsState, TcAdsParser.ReadUShort(data, 2), cbLength, TcAdsParser.AdsData(data, 8, cbLength));
                    return;
                }

                case 6:
                    indexGroup = TcAdsParser.ReadUInt(data, 0);
                    this.AdsAddDeviceNotificationInd(amsCmd.AmsHeader.Sender, amsCmd.AmsHeader.HUser, indexGroup, TcAdsParser.ReadUInt(data, 4), TcAdsParser.DataLength(data, 8), (AdsTransMode)TcAdsParser.ReadUInt(data, 12), TcAdsParser.ReadUInt(data, 0x10), TcAdsParser.ReadUInt(data, 20));
                    return;

                case 7:
                {
                    uint hNotification = TcAdsParser.ReadUInt(data, 0);
                    this.AdsDelDeviceNotificationInd(amsCmd.AmsHeader.Sender, amsCmd.AmsHeader.HUser, hNotification);
                    return;
                }

                case 8:
                    if (!this._useSingleNotificationEventHandler)
                    {
                        goto TR_0008;
                    }
                    else
                    {
                        using (AdsBinaryReader reader = new AdsBinaryReader(new AdsStream(data)))
                        {
                            cbLength        = reader.ReadUInt32();
                            numStampHeaders = reader.ReadUInt32();
                            this.AdsDeviceNotificationInd(amsCmd.AmsHeader.Sender, amsCmd.AmsHeader.HUser, numStampHeaders, reader);
                            break;
                        }
                        goto TR_0008;
                    }
                    break;

                case 9:
                    indexGroup    = TcAdsParser.ReadUInt(data, 0);
                    cbWriteLength = TcAdsParser.ReadUInt(data, 12);
                    this.AdsReadWriteInd(amsCmd.AmsHeader.Sender, amsCmd.AmsHeader.HUser, indexGroup, TcAdsParser.ReadUInt(data, 4), TcAdsParser.ReadUInt(data, 8), cbWriteLength, TcAdsParser.AdsData(data, 0x10, cbWriteLength));
                    return;

                default:
                    return;
                }
            }
            return;

TR_0008:
            cbLength        = TcAdsParser.ReadUInt(data, 0);
            numStampHeaders = TcAdsParser.ReadUInt(data, 4);
            this.AdsDeviceNotificationInd(amsCmd.AmsHeader.Sender, amsCmd.AmsHeader.HUser, numStampHeaders, TcAdsParser.ReadNotificationStampHeaders(data, numStampHeaders));
        }
Example #4
0
        private AdsErrorCode AdsResponse(AmsAddress rAddr, uint invokeId, ushort serviceId, uint cbLength, ITcAdsHeader adsHeader, byte[] adsData)
        {
            TcAmsHeader amsHeader = new TcAmsHeader(rAddr, this.Address, serviceId, 5, ((uint)Marshal.SizeOf(adsHeader)) + cbLength, 0, invokeId);

            return(this._amsServer.Send(new TcAmsCommand(amsHeader, TcAdsParser.BuildAdsBuffer(adsHeader, adsData))));
        }