Example #1
0
        private static void ReadSingleVariable(AdsClient client)
        {
            var symbol = client.CreateVariableHandle("KLEMME 4 (EL3204).RTD INPUTS CHANNEL 1");

            var buffer = new Memory <byte>(new byte[4]);
            var value  = client.Read(symbol, buffer);
        }
Example #2
0
        public void RunTest()
        {
            using (AdsClient client = new AdsClient(settings))
            {
                var deviceInfo = client.ReadDeviceInfo();
                Console.WriteLine("Device info: " + deviceInfo.ToString());

                Console.WriteLine();
                Console.WriteLine("Available symbols: ");
                var symbols = client.Special.GetSymbols();
                foreach (var symbol in symbols)
                {
                    Console.WriteLine("  " + symbol.ToString());
                }
                Console.WriteLine();

                uint startTestHandle = client.GetSymhandleByName("MAIN.STARTTEST");
                Console.WriteLine("Handle StartTest: " + startTestHandle.ToString());

                uint testIsRunningHandle = client.GetSymhandleByName("MAIN.TESTISRUNNING");
                Console.WriteLine("Handle TestIsRunning: " + testIsRunningHandle.ToString());

                uint stopTestHandle = client.GetSymhandleByName("MAIN.STOPTEST");
                Console.WriteLine("Handle StopTest: " + stopTestHandle.ToString());

                var testIsRunning = client.Read <bool>(testIsRunningHandle);
                Console.WriteLine("Is test running? " + testIsRunning.ToString());

                client.Write <bool>(startTestHandle, true);
                Console.WriteLine("Starting test");

                testIsRunning = client.Read <bool>(testIsRunningHandle);
                Console.WriteLine("Is test running? " + testIsRunning.ToString());


                //TODO



                client.Write <bool>(stopTestHandle, true);
                Console.WriteLine("Stopping test");

                testIsRunning = client.Read <bool>(testIsRunningHandle);
                Console.WriteLine("Is test running? " + testIsRunning.ToString());
            }
        }
Example #3
0
        public void RunTest()
        {
            using (AdsClient client = new AdsClient(settings))
            {
                var deviceInfo = client.ReadDeviceInfo();
                Console.WriteLine("Device info: " + deviceInfo.ToString());

                Console.WriteLine();
                Console.WriteLine("Available symbols: ");
                var symbols = client.Special.GetSymbols();
                foreach (var symbol in symbols)
                {
                    Console.WriteLine("  " + symbol.ToString());
                }
                Console.WriteLine();

                uint startTestHandle = client.GetSymhandleByName("MAIN.STARTTEST");
                Console.WriteLine("Handle StartTest: " + startTestHandle.ToString());

                uint testIsRunningHandle = client.GetSymhandleByName("MAIN.TESTISRUNNING");
                Console.WriteLine("Handle TestIsRunning: " + testIsRunningHandle.ToString());

                uint stopTestHandle = client.GetSymhandleByName("MAIN.STOPTEST");
                Console.WriteLine("Handle StopTest: " + stopTestHandle.ToString());

                var testIsRunning = client.Read<bool>(testIsRunningHandle);
                Console.WriteLine("Is test running? " + testIsRunning.ToString());

                client.Write<bool>(startTestHandle, true);
                Console.WriteLine("Starting test");

                testIsRunning = client.Read<bool>(testIsRunningHandle);
                Console.WriteLine("Is test running? " + testIsRunning.ToString());

                //TODO

                client.Write<bool>(stopTestHandle, true);
                Console.WriteLine("Stopping test");

                testIsRunning = client.Read<bool>(testIsRunningHandle);
                Console.WriteLine("Is test running? " + testIsRunning.ToString());
            }
        }
Example #4
0
        public static int GetSystemLatencyMaximum(AmsNetId target)
        {
            var buffer = new Memory <byte>(new byte[8]);

            using (AdsClient client = new AdsClient())
            {
                client.Connect(new AmsAddress(target, AmsPort.R0_Realtime));
                client.Read(0x01, 0x02, buffer);
            }

            return(BitConverter.ToInt32(buffer.ToArray(), 4));
        }
Example #5
0
        public static int GetCpuUsage(AmsNetId target)
        {
            var buffer = new Memory <byte>(new byte[4]);

            using (AdsClient client = new AdsClient())
            {
                client.Connect(new AmsAddress(target, AmsPort.R0_Realtime));
                client.Read(0x01, 0x06, buffer);
            }

            return(BitConverter.ToInt32(buffer.ToArray(), 0));
        }
        public T Read<T>(ushort index, byte subIndex, ushort stringLength = 0)
        {
            if (_client?.IsConnected != true)
                Connect();

            // https://infosys.beckhoff.de/index.php?content=../content/1031/eap/9007200776467979.html&id=

            uint indexOffset = ((uint)index) << 16 | subIndex;
            if (typeof(T) == typeof(string))
            {
                var m = new Memory<byte>(new byte[stringLength]);
                _client.Read(SdoIndexGroup, indexOffset, m);
                return (T)(object)Encoding.ASCII.GetString(m.ToArray());
            }
            else
            {
                return _client.ReadAny<T>(SdoIndexGroup, indexOffset);
            }
        }