public void ReadDeviceInfoAsync()
        {
            var amsTestSocket = new AmsSocketTest();

            amsTestSocket.SendMessage = new byte[] {
                0, 0, 32, 0, 0, 0, 5, 1, 204, 123, 1, 1, 33, 3, 10, 0, 0,
                120, 1, 1, 137, 128, 1, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0
            };

            amsTestSocket.ReceiveMessage = new byte[] {
                0, 0, 56, 0, 0, 0, 10, 0, 0, 120, 1, 1, 137, 128, 5, 1, 204, 123,
                1, 1, 33, 3, 1, 0, 5, 0, 24, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
                0, 2, 11, 234, 5, 84, 67, 97, 116, 80, 108, 99, 67, 116, 114, 108, 0, 0, 0, 0, 0
            };

            using (AdsClient client = new AdsClient(
                       amsNetIdSource: "10.0.0.120.1.1",
                       amsSocket: amsTestSocket,
                       amsNetIdTarget: "5.1.204.123.1.1"))
            {
                var task = client.ReadDeviceInfoAsync();
                task.Wait(5000);
                AdsDeviceInfo deviceInfo = task.Result;
                Assert.AreEqual(deviceInfo.ToString(), "Version: 2.11.1514 Devicename: TCatPlcCtrl");
            }
        }
Exemple #2
0
        protected override void AdsResponseIsChanged()
        {
            adsDeviceInfo = new AdsDeviceInfo();
            adsDeviceInfo.MajorVersion = this.AdsResponse[4];
            adsDeviceInfo.MinorVersion = this.AdsResponse[5];
            adsDeviceInfo.VersionBuild = BitConverter.ToUInt16(this.AdsResponse, 6);
            var deviceNameArray = new byte[16];

            Array.Copy(this.AdsResponse, 8, deviceNameArray, 0, 16);
            adsDeviceInfo.DeviceName = ByteArrayHelper.ByteArrayToString(deviceNameArray);
        }
Exemple #3
0
        /// <summary>
        /// Get some information of the ADS device (version, name)
        /// </summary>
        /// <returns></returns>
        public new AdsDeviceInfo ReadDeviceInfo()
        {
            AdsDeviceInfo result = new AdsDeviceInfo();

            deviceInfo = client.ReadDeviceInfo();

            result.DeviceName   = deviceInfo.Name;
            result.MajorVersion = deviceInfo.Version.Version;
            result.MinorVersion = deviceInfo.Version.Revision;
            result.VersionBuild = (ushort)deviceInfo.Version.Build;

            return(result);
        }
Exemple #4
0
        public async Task TestSoftBhf()
        {
            IPAddress plcIpAddress = IPAddress.Parse(_plcIpAddress);
            IPAddress localhost    = IPAddress.Parse(_localhostIp);

            RouteInfo info = new RouteInfo();

            info.Localhost        = localhost.ToString();
            info.LocalAmsNetId    = new AdsNetId(_localAsmNetId);
            info.IsTemporaryRoute = false;
            info.Login            = "******";
            info.Password         = "******";

            bool isSuccessful = await RouteManager.AddRemoteRouteAsync(localhost, plcIpAddress, info, 1000);

            Assert.Equal(isSuccessful, true);
            //missing client finder

            using (Socket.AdsClient client = new Socket.AdsClient(
                       amsNetIdSource: _localAsmNetId,
                       ipTarget: _plcIpAddress,
                       amsNetIdTarget: _amsNetIdSource))
            {
                AdsDeviceInfo deviceInfo = await client.ReadDeviceInfoAsync();

                AdsState state = await client.ReadStateAsync();

                client.OnNotification += (sender, e) =>
                {
                    var value = e.Notification.ByteValue;
                    int i     = BitConverter.ToInt32(value, 0);
                    Debug.Write(i);
                };
                uint notification1Handle = await client.AddNotificationAsync <int>(
                    "MAIN.ARRUDICOUNTER[1]", AdsTransmissionMode.OnChange, 1000);

                await Task.Delay(TimeSpan.FromSeconds(10));

                Assert.Equal(true, true);
            }
        }