public void TestGet()
        {
            var c = client.CreateChannel("TEST:DBL:5");
            var d = c.Get <double>();

            Assert.AreEqual(10, d);
        }
Ejemplo n.º 2
0
        public void TestReceivingEnumAsInt()
        {
            var record = server.CreateRecord <CAEnumRecord <GoodEnumU8> >("TEST");

            record.Value = GoodEnumU8.two;

            var channel = client.CreateChannel <int>("TEST");
            var result  = channel.Get();

            Assert.AreEqual(result, (byte)record.Value);
        }
        private void CommandMonitor(string p)
        {
            if (monitoredChannels.ContainsKey(p))
            {
                Console.WriteLine("Channel {0} is already being monitored!", p);
                return;
            }
            startedCommunication = true;
            Channel <string> channel = client.CreateChannel <string>(p);

            channel.MonitorChanged += channel_MonitorChanged;
            monitoredChannels[p]    = channel;
            Console.WriteLine("Registered monitor on {0}", p);
        }
Ejemplo n.º 4
0
        public static void Main(string[] args)
        {
            using (var server = new CAServer())
            {
                var intArrChannel = server.CreateArrayRecord <CAIntArrayRecord>(ArrayChannel, 20);
                var subArrChannel = server.CreateSubArrayRecord(SubArrayChannel, intArrChannel);
                subArrChannel.Scan = ScanAlgorithm.SEC1;

                // Fill array
                for (var i = 0; i < 20; i++)
                {
                    intArrChannel.Value[i] = i;
                }

                subArrChannel.Index  = 0;
                subArrChannel.Length = 10;

                // Shift subarray position and length every second
                var counter = 0;
                subArrChannel.PrepareRecord += (s, e) =>
                {
                    counter++;
                    counter              = counter > 5 ? 0 : counter;
                    subArrChannel.Index  = counter;
                    subArrChannel.Length = 10 + counter;
                };

                server.Start();
                Console.WriteLine("Server started");

                using (var client = new CAClient())
                {
                    var arrayChannel    = client.CreateChannel <int[]>(ArrayChannel);
                    var subArrayChannel = client.CreateChannel <int[]>(SubArrayChannel);

                    void Handler(Channel <int[]> s, int[] v)
                    {
                        Console.WriteLine($"{s.ChannelName}: {string.Join(", ", v)}");
                    };
                    arrayChannel.MonitorChanged    += Handler;
                    subArrayChannel.MonitorChanged += Handler;
                    Console.ReadKey();
                    subArrayChannel.MonitorChanged -= Handler;
                    arrayChannel.MonitorChanged    -= Handler;
                }
            }
        }
Ejemplo n.º 5
0
        internal static void S2()
        {
            //CAServer server = new CAServer(System.Net.IPAddress.Parse("129.129.194.45"), 5432, 5432);
            CAServer server = new CAServer(System.Net.IPAddress.Parse("127.0.0.1"), 5432, 5432);
            var      record = server.CreateArrayRecord <CAIntArrayRecord>("BERTRAND:ARR", 196 * 196);
            var      start  = 0;

            record.Scan           = EpicsSharp.ChannelAccess.Constants.ScanAlgorithm.HZ2;
            record.PrepareRecord += (sender, evt) =>
            {
                for (var i = 0; i < record.Value.Length; i++)
                {
                    record.Value[i] = start + i;
                }
                start++;
            };

            var r2 = server.CreateRecord <CAStringRecord>("BERTRAND:STR");

            r2.Value = "Hello there!";

            server.Start();

            //Thread.Sleep(1000);

            CAClient client = new CAClient();

            //client.Configuration.SearchAddress = "129.129.194.45:5432";
            client.Configuration.SearchAddress = "127.0.0.1:5432";
            var channel = client.CreateChannel <int[]>("BERTRAND:ARR");

            channel.MonitorMask = EpicsSharp.ChannelAccess.Constants.MonitorMask.ALL;

            channel.StatusChanged += (sender, newStatus) =>
            {
                Console.WriteLine(
                    "{0} : status {1}",
                    sender.ChannelName,
                    newStatus
                    );
            };
            int sequenceNumber = 0;

            channel.WishedDataCount = 196 * 196;
            channel.MonitorChanged += (sender, newValue) =>
            {
                Console.WriteLine(
                    $"{sender.ChannelName} : {newValue.Length} array elements ; #{sequenceNumber++}"
                    );
            };

            /*var chan2 = client.CreateChannel<string>("BERTRAND:STR");
             * Console.WriteLine(chan2.Get());*/

            //var r = channel.Get();
            System.Console.ReadLine();
        }
Ejemplo n.º 6
0
        public void TestIntSubArrayGet()
        {
            var intSubArrayChannel = Client.CreateChannel <int[]>(IntSubArrayChannelName);

            IntSubArrayRecord.Index  = 9;
            IntSubArrayRecord.Length = 5;
            var intSubArrayResponse = intSubArrayChannel.Get <int[]>();

            CollectionAssert.AreEqual(new int[] { 9, 10, 11, 12, 13 }, intSubArrayResponse);

            IntSubArrayRecord.Index  = 0;
            IntSubArrayRecord.Length = 4;
            intSubArrayResponse      = intSubArrayChannel.Get <int[]>();
            CollectionAssert.AreEqual(new int[] { 0, 1, 2, 3 }, intSubArrayResponse);

            IntSubArrayRecord.Index  = 1;
            IntSubArrayRecord.Length = 6;
            intSubArrayResponse      = intSubArrayChannel.Get <int[]>(5); // Take only first 5 of the subarray
            CollectionAssert.AreEqual(new int[] { 1, 2, 3, 4, 5 }, intSubArrayResponse);
        }
        public void TestIntArrayGet()
        {
            var intArrayChannel = Client.CreateChannel <int[]>(IntArrayChannelName);

            var intArrayResponse = intArrayChannel.Get <int[]>();

            Assert.AreEqual(20, intArrayResponse.Length);

            intArrayResponse = intArrayChannel.Get <int[]>(3);
            Assert.AreEqual(3, intArrayResponse.Length);
            CollectionAssert.AreEqual(new int[] { 0, 1, 2 }, intArrayResponse);
        }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            var server = new CAServer(IPAddress.Parse("129.129.194.45"));

            var record = server.CreateRecord <CAByteRecord>("TEST-BYTE");

            record.Value = 5;
            server.Start();

            var client = new CAClient(5432);

            client.Configuration.SearchAddress = "129.129.194.45";
            var channel = client.CreateChannel <byte>("TEST-BYTE");

            Console.WriteLine(channel.Get());
            Console.ReadKey();
        }
        static void DoubleEvents()
        {
            CAClient client = new CAClient();

            client.Configuration.SearchAddress = "127.0.0.1";
            client.Configuration.WaitTimeout   = 500; // .5 seconds

            CAServer       server = new CAServer(IPAddress.Parse("127.0.0.1"));
            CADoubleRecord record = server.CreateRecord <CADoubleRecord>("TEST:DBL");

            record.Scan  = EpicsSharp.ChannelAccess.Constants.ScanAlgorithm.ON_CHANGE;
            record.Value = 0;

            long nbEvents = 0;

            //AutoResetEvent waitOne = new AutoResetEvent(false);
            Channel <double> channel = client.CreateChannel <double>("TEST:DBL");

            channel.MonitorChanged += delegate(Channel <double> c, double d)
            {
                nbEvents++;
                record.Value = nbEvents;
            };

            Stopwatch sw = new Stopwatch();

            sw.Start();

            while (sw.Elapsed.TotalSeconds < 10)
            {
                //Console.WriteLine(sw.Elapsed.TotalSeconds);
                Console.Write(string.Format("Time remaining {0:0.0}   \r", 10 - sw.Elapsed.TotalSeconds));
                Thread.Sleep(100);
            }
            Console.WriteLine("NB Double events: " + (nbEvents / 10) + " / sec.           ");
            server.Dispose();
            client.Dispose();
        }
Ejemplo n.º 10
0
        private static void S4(string[] args)
        {
            var client = new CAClient(5432);

            //client.Configuration.SearchAddress = "129.129.194.45:5432";

            //client.Configuration.SearchAddress = "129.129.194.45:5055";
            client.Configuration.SearchAddress = "129.129.130.255:5064";
            //client.Configuration.SearchAddress = "129.129.130.255:5064;129.129.131.255:5064;129.129.137.255:5064;129.129.158.255:5064";
            client.Configuration.WaitTimeout = 2000;
            //var channel = client.CreateChannel<string>("SYSAD-AB:HOSTNAME");
            //var channel = client.CreateChannel<string>("ARIDI-PCT:CURRENT");
            //var r = channel.Get();
            var channel = client.CreateChannel <int[]>("DISKFREE-AB-LT:ARR-M");
            //channel.MonitorMask = EpicsSharp.ChannelAccess.Constants.MonitorMask.ALL;

            /*int sequenceNumber = 0;
             * channel.StatusChanged += (sender, newStatus) =>
             * {
             *  Console.WriteLine(
             *    "{0} : status {1}",
             *    sender.ChannelName,
             *    newStatus
             *  );
             * };
             *
             * channel.MonitorChanged += (sender, newValue) =>
             * {
             *  Console.WriteLine(
             *    $"{sender.ChannelName} : {newValue.Length} array elements ; #{sequenceNumber++}"
             *  );
             * };*/

            var r = channel.Get <int[]>();


            System.Console.ReadLine();
        }
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            Gateway = "130.246.71.15";

            if (_monitoredChannels.ContainsKey(_pv))
            {
                Console.WriteLine("PV {0} is already being monitored!", _pv);
            }
            else
            {
                try
                {
                    Channel <string> channel = _ca_client.CreateChannel <string>(_pv);
                    channel.MonitorChanged += Channel_MonitorChanged;
                    _monitoredChannels[_pv] = channel;
                    _startedCommunication   = true;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    _startedCommunication = false;
                }
            }
        }
        public void TestExtControlDouble()
        {
            var c = client.CreateChannel <ExtControl <double> >("TEST:DBL");
            var r = c.Get();

            Assert.AreEqual(Constants.AlarmSeverity.MAJOR, r.Severity);
            Assert.AreEqual(10.0, r.Value);
            Assert.AreEqual(20.0, r.LowAlertLimit);
            Assert.AreEqual("My", r.EGU);
        }
        static void Main(string[] args)
        {
            int nbRepeat = 1;

            if (args.Any(row => row == "-r"))
            {
                for (int i = 0; i < args.Length; i++)
                {
                    if (args[i] == "-r")
                    {
                        i++;
                        nbRepeat = int.Parse(args[i]);
                    }
                }
            }

            for (int r = 0; r < nbRepeat || nbRepeat == 0;)
            {
                if (nbRepeat > 0)
                {
                    r++;
                }

                if (r != 0 || nbRepeat == 0)
                {
                    Console.WriteLine("-------------------------------------------");
                    Console.WriteLine("-------------------------------------------");
                    Thread.Sleep(100);
                }

                using (var client = new CAClient())
                {
                    client.Configuration.WaitTimeout = 10000;
                    client.Configuration.DebugTiming = true;

                    string channelName  = "";
                    bool   usingMonitor = false;

                    for (int i = 0; i < args.Length; i++)
                    {
                        if (args[i] == "-e")
                        {
                            i++;
                            client.Configuration.SearchAddress = args[i];
                        }
                        else if (args[i] == "-m")
                        {
                            usingMonitor = true;
                        }
                        else
                        {
                            channelName = args[i];
                        }
                    }

                    client.Configuration.DebugTiming = true;
                    Console.WriteLine("EPICS Configuration: " + client.Configuration.SearchAddress);
                    Console.WriteLine("Trying to read " + channelName);
                    var sw = new Stopwatch();
                    sw.Start();

                    var channel = client.CreateChannel <string>(channelName);

                    bool hasError = false;

                    if (usingMonitor)
                    {
                        Console.WriteLine("Monitor and wait for the first value back.");
                        channel.MonitorChanged += (c, v) =>
                        {
                            Console.WriteLine("Value: " + v);
                            gotMonitorValue.Set();
                        };
                        try
                        {
                            gotMonitorValue.WaitOne(5000);
                        }
                        catch
                        {
                            hasError = true;
                        }
                    }
                    else
                    {
                        Console.WriteLine("Get and waits the value back.");
                        try
                        {
                            Console.WriteLine(channel.Get());
                        }
                        catch (Exception ex)
                        {
                            hasError = true;
                            //Console.WriteLine(ex);
                        }
                    }

                    sw.Stop();
                    Console.WriteLine("Status: " + channel.Status.ToString());
                    Console.WriteLine("-------------------------------------------");
                    Console.WriteLine("Timings:");
                    Console.WriteLine("-------------------------------------------");

                    TimeSpan?prevTime = null;
                    foreach (var i in channel.ElapsedTimings)
                    {
                        if (!prevTime.HasValue)
                        {
                            Console.WriteLine(i.Key + ": " + i.Value.ToString());
                        }
                        else
                        {
                            Console.WriteLine(i.Key + ": " + (i.Value - prevTime).ToString());
                        }
                        prevTime = i.Value;
                    }

                    Console.WriteLine("-------------------------------------------");
                    Console.WriteLine("Total: " + sw.Elapsed.ToString());
                    Console.WriteLine("Search answered by " + channel.SearchAnswerFrom);
                    Console.WriteLine("IOC: " + channel.IOC);
                    Console.WriteLine("EPICS Type: " + channel.ChannelDefinedType);
                    if (channel.Status != EpicsSharp.ChannelAccess.Constants.ChannelStatus.CONNECTED || hasError)
                    {
                        Console.Beep();
                    }
                }
            }

            if (System.Diagnostics.Debugger.IsAttached)
            {
                Console.WriteLine("Press any key to continue...");
                Console.ReadKey();
            }
        }
Ejemplo n.º 14
0
        private static void S1()
        {
            //CAServer server = new CAServer(System.Net.IPAddress.Parse("129.129.130.44"), 5162, 5162);
            CAServer server = new CAServer(System.Net.IPAddress.Parse("129.129.130.44"), 5432, 5432);
            var      record = server.CreateRecord <CAStringRecord>("BERTRAND:STR");

            record.Value          = "Hello there!";
            record.Scan           = EpicsSharp.ChannelAccess.Constants.ScanAlgorithm.HZ10;
            record.PrepareRecord += ((sender, e) => { record.Value = DateTime.Now.ToLongTimeString(); });

            var record2 = server.CreateRecord <CAStringRecord>("BERTRAND:STR2");

            record2.Value          = "Hello there too!";
            record2.Scan           = EpicsSharp.ChannelAccess.Constants.ScanAlgorithm.HZ10;
            record2.PrepareRecord += ((sender, e) => { record2.Value = DateTime.Now.ToLongTimeString(); });

            var record3 = server.CreateRecord <CAEnumRecord <MyEnum> >("BERTRAND:ENUM");

            record3.Value          = MyEnum.Alain;
            record3.Scan           = EpicsSharp.ChannelAccess.Constants.ScanAlgorithm.SEC1;
            record3.PrepareRecord += ((sender, e) => { record3.Value = 1 - record3.Value; });

            Thread.Sleep(1000);

            CAClient client = new CAClient();

            //client.Configuration.WaitTimeout = 1000;
            client.Configuration.SearchAddress = "129.129.130.44:5432";

            /*var c = client.CreateChannel<ExtControlEnum>("BERTRAND:ENUM");
             * var r=c.Get();*/

            var record4 = server.CreateRecord <CAEnumRecord <GoodEnumU8> >("TEST");

            record4.Value = GoodEnumU8.two;

            var channel = client.CreateChannel <ExtControlEnum>("TEST");
            var result  = channel.Get();


            Console.WriteLine("S to stop or start answering get");
            Console.WriteLine("Q to quit");
            Console.WriteLine("Running!");
            while (true)
            {
                switch (Console.ReadKey().Key)
                {
                case ConsoleKey.S:
                    //server.StopGet = !server.StopGet;
                    //record2.Dispose();
                    break;

                case ConsoleKey.Q:
                    return;

                default:
                    break;
                }
            }


            /*CAClient client = new CAClient();
             * client.Configuration.WaitTimeout = 1000;
             * var c=client.CreateChannel("ARIDI-PCT:CURREsNT");
             * Console.WriteLine(c.Get<string>());
             * Console.ReadKey();*/
        }