Ejemplo n.º 1
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());
            }
        }
Ejemplo n.º 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());
            }
        }
Ejemplo n.º 3
0
        public static IDisposable GetTypedS7Notification(this IPlc plc, Type type, string address, AdsClient beckhoff, ISymbol symbol, TimeSpan notificationCycle, TimeSpan regularTransmissionCycle)
        {
            if (type == typeof(byte[]))
            {
                return(plc.CreateNotification <byte[]>(address, TransmissionMode.Cyclic, regularTransmissionCycle)
                       .Do(value => Log.Logger.Debug($"Writing {address} to {symbol.InstancePath} {ByteToString(value)}"))
                       .SelectMany(value => beckhoff.Write(symbol, value))
                       .Subscribe());
            }

            var typecode = Type.GetTypeCode(type);

            switch (typecode)
            {
            case TypeCode.Boolean:
                return(plc.CreateNotification <bool>(address, TransmissionMode.OnChange, notificationCycle)
                       .SelectMany(value => beckhoff.Write(symbol, value))
                       .Subscribe());

            case TypeCode.SByte:
            case TypeCode.Byte:
            case TypeCode.Char:
                return(plc.CreateNotification <byte>(address, TransmissionMode.OnChange, notificationCycle)
                       .SelectMany(value => beckhoff.Write(symbol, value))
                       .Subscribe());

            case TypeCode.Int16:
            case TypeCode.UInt16:
                return(plc.CreateNotification <short>(address, TransmissionMode.OnChange, notificationCycle)
                       .SelectMany(value => beckhoff.Write(symbol, value))
                       .Subscribe());

            case TypeCode.Int32:
            case TypeCode.UInt32:
                return(plc.CreateNotification <int>(address, TransmissionMode.OnChange, notificationCycle)
                       .SelectMany(value => beckhoff.Write(symbol, value))
                       .Subscribe());

            case TypeCode.Int64:
            case TypeCode.UInt64:
                return(plc.CreateNotification <long>(address, TransmissionMode.OnChange, notificationCycle)
                       .SelectMany(value => beckhoff.Write(symbol, value))
                       .Subscribe());

            case TypeCode.Single:
                return(plc.CreateNotification <float>(address, TransmissionMode.OnChange, notificationCycle)
                       .SelectMany(value => beckhoff.Write(symbol, value))
                       .Subscribe());

            default:
                throw new ArgumentException($"Unsupported Type {type.Name}");
            }
        }
Ejemplo n.º 4
0
        public static void StartProcess(AmsNetId target, string path, string dir, string args)
        {
            byte[] Data = new byte[777];

            BitConverter.GetBytes(path.Length).CopyTo(Data, 0);
            BitConverter.GetBytes(dir.Length).CopyTo(Data, 4);
            BitConverter.GetBytes(args.Length).CopyTo(Data, 8);

            System.Text.Encoding.ASCII.GetBytes(path).CopyTo(Data, 12);
            System.Text.Encoding.ASCII.GetBytes(dir).CopyTo(Data, 12 + path.Length + 1);
            System.Text.Encoding.ASCII.GetBytes(args).CopyTo(Data, 12 + path.Length + 1 + dir.Length + 1);

            ReadOnlyMemory <byte> buffer = new ReadOnlyMemory <byte>(Data);

            using (AdsClient client = new AdsClient())
            {
                client.Connect(new AmsAddress(target, AmsPort.SystemService));
                client.Write(500, 0, buffer);
                client.Dispose();
            }
        }