예제 #1
0
        /// <summary>
        /// Get the current routes
        /// </summary>
        /// <returns></returns>
        public IList<string> GetCurrentRoutes()
        {
			var amsSpecial = new Ams(ams.AmsSocket);
            amsSpecial.AmsNetIdSource = ams.AmsNetIdSource;
            amsSpecial.AmsNetIdTarget = ams.AmsNetIdTarget;
            amsSpecial.AmsPortTarget = 10000;
            bool ok = true;
            uint index = 0;
            var routes = new List<string>();

            while (ok)
            {
                try
                {
                    AdsReadCommand adsCommand = new AdsReadCommand(0x00000323, index++, 0x0800);
                    var result = adsCommand.Run(amsSpecial);
                    int length = result.Data.Length - 44;
                    byte[] routeBytes = new byte[length];
                    Array.Copy(result.Data, 44, routeBytes, 0, length);
                    string routeString = ByteArrayHelper.ByteArrayToString(routeBytes);
                    int stringLlength = routeString.Length + 1;
                    Array.Copy(routeBytes, stringLlength, routeBytes, 0, length - stringLlength);
                    routeString += " " + ByteArrayHelper.ByteArrayToString(routeBytes);
                    routes.Add(routeString);
                }
                catch (AdsException ex)
                {
                    if (ex.ErrorCode == 1814) ok = false;
                    else throw;
                }
            }
            return routes;
        }
예제 #2
0
        /// <summary>
        /// Get an xml description of the plc
        /// You can use XDocument.Parse(xml).ToString() to make the xml more readable
        /// </summary>
        /// <returns></returns>
		public string GetTargetDesc()
        {
			var amsSpecial = new Ams(ams.AmsSocket);
            amsSpecial.AmsNetIdSource = ams.AmsNetIdSource;
            amsSpecial.AmsNetIdTarget = ams.AmsNetIdTarget;
            amsSpecial.AmsPortTarget = 10000;
            AdsReadCommand adsCommand = new AdsReadCommand(0x000002bc, 0x00000001, 4);
            var result = adsCommand.Run(amsSpecial);
            uint length = BitConverter.ToUInt32(result.Data, 0);
            adsCommand = new AdsReadCommand(0x000002bc, 0x00000001, length);
            result = adsCommand.Run(amsSpecial);
            string xml = ByteArrayHelper.ByteArrayToString(result.Data);
            return xml;
        }
예제 #3
0
        public async Task<IList<IAdsSymhandle>> GetSymbolsAsync()
        {
            AdsReadCommand adsCommand = new AdsReadCommand(0x0000f00f, 0x000000, 0x30);
            var result = await adsCommand.RunAsync(ams);

            uint readLength = (uint)BitConverter.ToInt32(result.Data, 4);
            adsCommand = new AdsReadCommand(0x0000f00b, 0x000000, readLength);
            result = await adsCommand.RunAsync(ams);

            var symbols = GetSymbolsFromBytes(result.Data);

            return symbols;
        }
예제 #4
0
        public IList<IAdsSymhandle> GetSymbols()
        {
            AdsReadCommand adsCommand = new AdsReadCommand(0x0000f00f, 0x000000, 0x30);
            var result = adsCommand.Run(this.ams);

            uint readLength = (uint)BitConverter.ToInt32(result.Data, 4);
            adsCommand = new AdsReadCommand(0x0000f00b, 0x000000, readLength);
            result = adsCommand.Run(this.ams);

            return GetSymbolsFromBytes(result.Data);
        }