async Task ConnectAsync(string channelName)
        {
            lock (knownChannels)
            {
                if (knownChannelsLastUsage.ContainsKey(channelName))
                {
                    knownChannelsLastUsage.Remove(channelName);
                }
            }

            bool         shouldCheck = true;
            EpicsChannel c           = null;

            lock (knownChannels)
            {
                shouldCheck = !knownChannels.ContainsKey(channelName);
            }
            if (shouldCheck)
            {
                c = epicsClient.CreateChannel(channelName);
                await c.ConnectAsync();
            }
            lock (knownChannels)
            {
                if (!knownChannels.ContainsKey(channelName) && c != null)
                {
                    if (c.ChannelDefinedType != null && c.ChannelDefinedType.Name == "Enum")
                    {
                        knownChannels.Add(channelName, epicsClient.CreateChannel <int>(channelName));
                        if (!knownChannelsEnum.ContainsKey(channelName))
                        {
                            var t = epicsClient.CreateChannel <ExtControlEnum>(channelName);
                            var v = t.Get();
                            knownChannelsEnum.Add(channelName, v.States);
                        }
                    }
                    else
                    {
                        knownChannels.Add(channelName, c);
                    }
                    knownChannelsUsage.Add(channelName, 0);
                }
                if (knownChannelsEnum.ContainsKey(channelName))
                {
                    if (ChannelEnumStates != null)
                    {
                        ChannelEnumStates(channelName, knownChannelsEnum[channelName]);
                    }
                }
                knownChannels[channelName].MonitorChanged += channel_MonitorChanged;
                knownChannelsUsage[channelName]++;
                subscribedChannels.Add(knownChannels[channelName]);
            }
        }
 static void Main(string[] args)
 {
     EpicsClient client = new EpicsClient();
     EpicsChannel<int> test_channel_1 = client.CreateChannel<int>("NDW1033:dpk62:SIMPLE:VALUE1");
     int PV_value = test_channel_1.Get<int>();
     Console.WriteLine(PV_value);
     test_channel_1.Put<int>(2);
 }
        static void Main(string[] args)
        {
            EpicsClient client = new EpicsClient();

            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);

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

            if (usingMonitor)
            {
                Console.WriteLine("Monitor and wait for the first value back.");
                channel.MonitorChanged += new EpicsDelegate<string>(channel_MonitorChanged);
                gotMonitorValue.WaitOne(5000);
            }
            else
            {
                Console.WriteLine("Get and waits the value back.");
                try
                {
                    Console.WriteLine(channel.Get());
                }
                catch
                {
                }
            }

            Console.WriteLine(channel.Status.ToString());
            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("Total: " + prevTime.ToString());
        }
        static void Main(string[] args)
        {
            EpicsClient client = new EpicsClient();
            client.Configuration.SearchAddress = "129.129.130.87:5432";

            channel = client.CreateChannel<string>("ADG1:IST1:2");
            channel.StatusChanged += new EpicsStatusDelegate(channel_StatusChanged);
            channel.MonitorChanged += new EpicsDelegate<string>(channel_MonitorChanged);

            while (true)
            {
                switch (Console.ReadKey().KeyChar)
                {
                    case (char)27:
                        return;
                    case (char)13:
                        if (channel == null)
                        {
                            channel = client.CreateChannel<string>("ADG1:IST1:2");
                            channel.StatusChanged += new EpicsStatusDelegate(channel_StatusChanged);
                            channel.MonitorChanged += new EpicsDelegate<string>(channel_MonitorChanged);
                        }
                        else
                        {
                            channel.Dispose();
                            channel = null;
                        }
                        break;
                    case ' ':
                        monitored = !monitored;
                        if (monitored)
                            channel.MonitorChanged += new EpicsDelegate<string>(channel_MonitorChanged);
                        else
                            channel.MonitorChanged -= new EpicsDelegate<string>(channel_MonitorChanged);
                        break;
                    default:
                        break;
                }
            }
        }
        static void Main(string[] args)
        {
            EpicsClient client = new EpicsClient();
            /*client.Config.ServerList.Add("129.129.130.87:5432");
            EpicsChannel<sbyte[]> screen = client.CreateChannel<sbyte[]>("PBGW:LOGVIEW");*/
            client.Configuration.SearchAddress="172.22.200.117:5062";
            EpicsChannel<sbyte[]> screen = client.CreateChannel<sbyte[]>("HIPA-TEST-GW:LOGVIEW");
            screen.MonitorChanged += new EpicsDelegate<sbyte[]>(screen_MonitorChanged);

            Console.WindowWidth = 200;
            Console.WindowHeight = 100;
            Console.Clear();

            Console.ReadKey();
        }
        void CheckGateway()
        {
            Thread.Sleep(40000);

            while (!shouldStop)
            {
                bool isOk=false;
                for (int i = 0; i < 5; i++)
                {
                    using (EpicsClient client = new EpicsClient())
                    {
                        //Console.WriteLine("Checking...");
                        client.Configuration.WaitTimeout = 15000;
                        EpicsChannel<double> cpuInfo = client.CreateChannel<double>(ConfigurationManager.AppSettings["GatewayName"] + ":CPU");
                        try
                        {
                            double v = cpuInfo.Get();
                            if (v < 80.0)
                            {
                                isOk = true;
                                break;
                            }
                            /*else
                                Console.WriteLine("All ok");*/
                        }
                        catch
                        {
                        }
                    }
                    Thread.Sleep(1000);
                }

                if (!isOk)
                {
                    StopGateway();
                    StartGateway();
                }
                else
                    Thread.Sleep(10000);
            }
        }
Exemplo n.º 7
0
        public void ClientServer()
        {
            using (var server = new EpicsServer())
                using (var client = new EpicsClient())
                {
                    server.Config.BeaconPort  = 95;
                    server.Config.TCPPort     = 115;
                    server.Config.UDPPort     = 115;
                    server.Config.UDPDestPort = 115;

                    var record = server.GetEpicsRecord <double>("OMA:Counter");
                    record.HIGH = 50;
                    record.HIHI = 75;
                    record.VAL  = 19;

                    client.Config.UDPBeaconPort = 95;
                    client.Config.UDPIocPort    = 115;

                    var monitor = client.CreateChannel("OMA:Counter");
                    Assert.Equal(19, monitor.Get());
                }
        }
Exemplo n.º 8
0
        public static void Main()
        {
            /*Application.EnableVisualStyles();
             * Application.SetCompatibleTextRenderingDefault(false);
             * Application.Run(new TestApp());*/

            var client  = new EpicsClient();
            var monitor = client.CreateChannel("TestChannel01:Counter");

            monitor.MonitorChanged += (sender, value) => Console.WriteLine(value);

            Task.Factory.StartNew(() =>
            {
                var server = new EpicsServer();
                var record = server.GetEpicsRecord <string>("TestChannel01:Counter");

                for (int i = 0; i < 500; i++)
                {
                    record.VAL = i.ToString();
                    Thread.Sleep(1000);
                }
            });



            /*var server = new EpicsServer();
             * var record = server.GetEpicsRecord<double>("TestChannel01:Counter");
             * record.HIGH = 50;
             * record.HIHI = 75;
             * record.VAL = 19;
             *
             * for (int i = 0; i < 10; i++)
             * {
             *      record.VAL = i;
             *      Thread.Sleep(1000);
             * }*/

            Console.ReadKey();
        }
		public void ClientServer()
		{
			using (var server = new EpicsServer())
			using (var client = new EpicsClient())
			{
				server.Config.BeaconPort = 95;
				server.Config.TCPPort = 115;
				server.Config.UDPPort = 115;
				server.Config.UDPDestPort = 115;

				var record = server.GetEpicsRecord<double>("OMA:Counter");
				record.HIGH = 50;
				record.HIHI = 75;
				record.VAL = 19;

				client.Config.UDPBeaconPort = 95;
				client.Config.UDPIocPort = 115;

				var monitor = client.CreateChannel("OMA:Counter");
				Assert.Equal(19, monitor.Get());
			}
		}
Exemplo n.º 10
0
		public static void Main()
		{
			/*Application.EnableVisualStyles();
			Application.SetCompatibleTextRenderingDefault(false);
			Application.Run(new TestApp());*/

			var client = new EpicsClient();
			var monitor = client.CreateChannel("TestChannel01:Counter");
			monitor.MonitorChanged += (sender, value) => Console.WriteLine(value);
			
			Task.Factory.StartNew(() =>
				{
					var server = new EpicsServer();
					var record = server.GetEpicsRecord<string>("TestChannel01:Counter");
					
					for (int i = 0; i < 500; i++)
					{
						record.VAL = i.ToString();
						Thread.Sleep(1000);
					}
				});



			/*var server = new EpicsServer();
			var record = server.GetEpicsRecord<double>("TestChannel01:Counter");
			record.HIGH = 50;
			record.HIHI = 75;
			record.VAL = 19;

			for (int i = 0; i < 10; i++)
			{
				record.VAL = i;
				Thread.Sleep(1000);
			}*/

			Console.ReadKey();
		}
Exemplo n.º 11
0
        private static void ZTest()
        {
            string[] channelNames = File.ReadAllLines(@"channels.txt");

            List<EpicsChannel> channels = new List<EpicsChannel>();

            client = new EpicsClient();
            //client.Configuration.SearchAddress = "172.22.200.117:5062";
            //client.Configuration.SearchAddress = "172.22.200.103:5062";
            client.Configuration.WaitTimeout = 2000;

            channelNames = channelNames.OrderBy(a => Guid.NewGuid()).ToArray();

            gotDisconnect = new AutoResetEvent(false);

            foreach (var i in channelNames)
            {
                if (needToStop)
                    break;
                Console.WriteLine("Checking " + i);
                EpicsChannel<ExtControl<string>> c = client.CreateChannel<ExtControl<string>>(i.Trim());
                //EpicsChannel c = client.CreateChannel(i.Trim());
                gotValue = new AutoResetEvent(false);
                c.MonitorChanged += gotValueNotified;
                channels.Add(c);
                /*if (channels.Count > 295)
                    break;*/
                c.StatusChanged += new EpicsStatusDelegate(c_StatusChanged);
                Thread.Sleep(100);
                /*try
                {
                    if (!gotValue.WaitOne(2000))
                    {
                        Console.WriteLine("Never got back.");
                    }
                }
                catch
                {
                    Console.WriteLine("Didn't get value for "+i);
                }
                c.Dispose();
                client.Dispose();*/
            }
            //Console.ReadKey();
            gotDisconnect.WaitOne();
            Console.WriteLine("Nb ok: " + channels.Count);
            Console.WriteLine("Disconnected!");
            client.Dispose();
            Console.ReadKey();
        }
Exemplo n.º 12
0
        static void ReconnectProscan()
        {
            gateway = new Gateway();
            gateway.Configuration.GatewayName = "TESTGW";
            gateway.Configuration.LocalAddressSideA = ip + ":5555";
            //gateway.Configuration.LocalAddressSideA = "129.129.130.87:5555";
            gateway.Configuration.RemoteAddressSideA = remoteIp + ":5552";
            gateway.Configuration.LocalAddressSideB = ip + ":5888";
            //gateway.Configuration.RemoteAddressSideB = remoteIp + ":5777";
            gateway.Configuration.RemoteAddressSideB = "172.25.60.67:5062";
            gateway.Configuration.ConfigurationType = PBCaGw.Configurations.ConfigurationType.UNIDIRECTIONAL;
            gateway.SaveConfig();
            gateway.Start();

            client = new EpicsClient();
            client.Configuration.WaitTimeout = 2000;
            client.Configuration.SearchAddress = ip + ":5555";

            EpicsChannel<ExtGraphic<string>> ch = client.CreateChannel<ExtGraphic<string>>("MMAP10Y:CMODE:1");
            ch.StatusChanged += new EpicsStatusDelegate(ch_StatusChanged);
            ch.MonitorChanged += new EpicsDelegate<ExtGraphic<string>>(ch_MonitorChangedView);

            EpicsChannel<ExtGraphic<string>> ch2 = client.CreateChannel<ExtGraphic<string>>("MMAP12Y:CNSAMPLES:1");
            ch2.StatusChanged += new EpicsStatusDelegate(ch_StatusChanged);
            ch2.MonitorChanged += new EpicsDelegate<ExtGraphic<string>>(ch_MonitorChangedView);

            Thread.Sleep(1000);

            Console.WriteLine("------------------------------------------------------------------------");
            gateway.Dispose();
            //Thread.Sleep(5000);

            gateway = new Gateway();
            gateway.Configuration.LocalAddressSideA = ip + ":5555";
            //gateway.Configuration.LocalAddressSideA = "129.129.130.87:5555";
            gateway.Configuration.RemoteAddressSideA = remoteIp + ":5552";
            gateway.Configuration.LocalAddressSideB = ip + ":5888";
            //gateway.Configuration.RemoteAddressSideB = remoteIp + ":5777";
            gateway.Configuration.RemoteAddressSideB = "172.25.60.67:5062";
            gateway.Configuration.ConfigurationType = PBCaGw.Configurations.ConfigurationType.UNIDIRECTIONAL;
            gateway.Start();

            /*EpicsChannel restart = client.CreateChannel("TESTGW:RESTART");
            try
            {
                restart.Put<int>(2);
            }
            catch
            {
            }*/

            Thread.Sleep(5000);
            Console.ReadKey();
        }
Exemplo n.º 13
0
        static void ReconnectIoc()
        {
            InitServer();

            gateway = new Gateway();
            gateway.Configuration.GatewayName = "TESTGW";
            gateway.Configuration.LocalAddressSideA = ip + ":5555";
            //gateway.Configuration.LocalAddressSideA = "129.129.130.87:5555";
            gateway.Configuration.RemoteAddressSideA = ip + ":5552";
            gateway.Configuration.LocalAddressSideB = ip + ":5888";
            //gateway.Configuration.RemoteAddressSideB = remoteIp + ":5777";
            gateway.Configuration.RemoteAddressSideB = ip + ":5777";
            gateway.Configuration.ConfigurationType = PBCaGw.Configurations.ConfigurationType.UNIDIRECTIONAL;
            gateway.SaveConfig();

            Gateway.AutoCreateChannel = false;
            Gateway.RestoreCache = false;
            gateway.Start();

            client = new EpicsClient();
            client.Configuration.SearchAddress = ip + ":5555";
            client.Configuration.WaitTimeout = 200;
            chans = new List<EpicsChannel>();

            for (int i = 0; i < 1; i++)
            {
                EpicsChannel<int> intChan = client.CreateChannel<int>("PCT:INT-" + i);
                chans.Add(intChan);
                intChan.MonitorChanged += new EpicsDelegate<int>(intChan_MonitorChanged);
            }

            Thread t = new Thread(ChanToGet);
            t.IsBackground = true;
            t.Start();

            //Thread.Sleep(2000);
            //chans[0].Get<int>();

            //for (int i = 0; i < 100; i++)
            while(true)
            {
                Thread.Sleep(5000);
                server.Dispose();
                Thread.Sleep(2000);
                InitServer();
            }

            Console.ReadKey();
        }
Exemplo n.º 14
0
        private static void QuickMonitor()
        {
            gateway = new Gateway();
            gateway.Configuration.GatewayName = "TESTGW";
            gateway.Configuration.LocalAddressSideA = "127.0.0.1:5432";
            //gateway.Configuration.LocalAddressSideA = "129.129.130.87:5555";
            gateway.Configuration.RemoteAddressSideA = "127.0.0.1:5552";
            gateway.Configuration.LocalAddressSideB = "129.129.130.87:5064";
            //gateway.Configuration.LocalAddressSideB = "172.22.200.116:5432";
            //gateway.Configuration.RemoteAddressSideB = remoteIp + ":5777";
            //gateway.Configuration.RemoteAddressSideB = "172.22.255.255:5064";
            gateway.Configuration.RemoteAddressSideB = "172.22.200.117:5062";
            gateway.Configuration.ConfigurationType = PBCaGw.Configurations.ConfigurationType.UNIDIRECTIONAL;
            gateway.SaveConfig();
            gateway.Start();

            Thread.Sleep(1000);

            EpicsClient client = new EpicsClient();
            string clientConfig = "127.0.0.1:5432";
            //string clientConfig="172.22.100.101:5064";
            client.Configuration.SearchAddress = clientConfig;

            //string[] channelNames = { "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:CAL", "ZPSAF101-VME:CALNCONN.EGU", "ZPSAF101-VME:CALDCONN.EGU", "ZPSAF101-VME:LOAD", "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:HBT" };
            //string[] channelNames = { "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:CALNCONN.EGU", "ZPSAF101-VME:CALDCONN.EGU", "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:CAL.EGU" };
            string[] channelNames = { "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:CALNCONN.EGU", "ZPSAF101-VME:CALDCONN.EGU", "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:HBT.EGU", "ZPSAF101-VME:HBT.EGU", "ZPSAF101-VME:LOAD.EGU" };
            //string[] channelNames = { "ZPSAF101-VME:CAL.EGU" };
            while (true)
            {
                for (int l = 0; l < 10; l++)
                {
                    List<EpicsChannel<ExtGraphic<string>>> channels = new List<EpicsChannel<ExtGraphic<string>>>();
                    foreach (var i in channelNames)
                    {
                        EpicsChannel<ExtGraphic<string>> c = client.CreateChannel<ExtGraphic<string>>(i);
                        c.MonitorChanged += new EpicsDelegate<ExtGraphic<string>>(QuickMonitor);
                        channels.Add(c);
                    }
                    foreach (var i in channels)
                        i.Dispose();
                    client.Dispose();
                    client = new EpicsClient();
                    client.Configuration.SearchAddress = clientConfig;
                }

                if (true)
                {
                    bool gotError = false;
                    List<EpicsChannel<ExtGraphic<string>>> channels = new List<EpicsChannel<ExtGraphic<string>>>();
                    foreach (var i in channelNames)
                    {
                        EpicsChannel<ExtGraphic<string>> c = client.CreateChannel<ExtGraphic<string>>(i);
                        channels.Add(c);
                    }

                    CountdownEvent multiActionCountDown = new CountdownEvent(channelNames.Count());
                    Dictionary<uint, bool> gotMonitor = new Dictionary<uint, bool>();

                    foreach (EpicsChannel<ExtGraphic<string>> c in channels)
                    {
                        c.MonitorChanged += delegate(EpicsChannel<ExtGraphic<string>> sender, ExtGraphic<string> newValue)
                        {
                            if ((newValue.Value != "#" && sender.ChannelName.Contains(":CAL")) ||
                                (newValue.Value != "%" && sender.ChannelName.Contains(":LOAD")) ||
                                (newValue.Value != "ticks" && sender.ChannelName.Contains(":HBT")))
                            {
                                Console.WriteLine("Wrong data on CID (" + sender.ChannelName + "): " + sender.CID + ", " + newValue.Value);
                                gotError = true;
                            }
                            lock (gotMonitor)
                            {
                                if (!gotMonitor.ContainsKey(sender.CID))
                                {
                                    gotMonitor.Add(sender.CID, true);
                                    multiActionCountDown.Signal();
                                }
                            }
                        };

                        c.MonitorChanged += new EpicsDelegate<ExtGraphic<string>>(QuickMonitor);
                    }

                    multiActionCountDown.Wait(2500);

                    bool allConnected = true;
                    foreach (var i in channels)
                    {
                        if (i.Status != ChannelStatus.CONNECTED)
                        {
                            allConnected = false;
                            Console.WriteLine(i.ChannelName + " not connected.");
                            //gotError = true;
                        }
                    }

                    if (!allConnected)
                    {
                        needToShow = false;
                        //gotError = true;
                        Console.WriteLine("Not all connected!!!!!");
                    }

                    foreach (var i in channels)
                        i.Dispose();
                    client.Dispose();
                    client = new EpicsClient();
                    client.Configuration.SearchAddress = clientConfig;
                    multiActionCountDown.Dispose();

                    if (gotError)
                    {
                        Console.Beep();
                        Console.WriteLine("Press any key to continue...");
                        Console.ReadKey();
                        needToShow = true;
                    }
                }
            }
        }
Exemplo n.º 15
0
        static void ProscanWave()
        {
            PBCaGw.Services.Log.Enabled = false;
            gateway = new Gateway();
            gateway.Configuration.GatewayName = "TESTGW";
            gateway.Configuration.LocalAddressSideA = ip + ":5555";
            //gateway.Configuration.LocalAddressSideA = "129.129.130.87:5555";
            gateway.Configuration.RemoteAddressSideA = remoteIp + ":5552";
            gateway.Configuration.LocalAddressSideB = ip + ":5888";
            //gateway.Configuration.RemoteAddressSideB = remoteIp + ":5777";
            gateway.Configuration.RemoteAddressSideB = "172.25.60.67:5062";
            gateway.Configuration.ConfigurationType = PBCaGw.Configurations.ConfigurationType.UNIDIRECTIONAL;
            gateway.SaveConfig();
            gateway.Start();

            Console.WriteLine("Gateway up");
            //gateway.Configuration.ConfigurationType = PBCaGw.Configurations.ConfigurationType.BIDIRECTIONAL;

            client = new EpicsClient();
            client.Configuration.WaitTimeout = 2000;
            client.Configuration.SearchAddress = ip + ":5555";
            List<EpicsChannel<ExtGraphic<string>>> channels = new List<EpicsChannel<ExtGraphic<string>>>();
            foreach (string i in channelsToConnect)
            {
                EpicsChannel<ExtGraphic<string>> ch = client.CreateChannel<ExtGraphic<string>>(i);
                ch.MonitorChanged += new EpicsDelegate<ExtGraphic<string>>(ch_MonitorChanged);
                channels.Add(ch);
            }
            Thread.Sleep(2000);

            gateway.Dispose();
            PBCaGw.Services.Log.Enabled = true;
            //Thread.Sleep(5000);

            gateway = new Gateway();
            gateway.Configuration.LocalAddressSideA = ip + ":5555";
            //gateway.Configuration.LocalAddressSideA = "129.129.130.87:5555";
            gateway.Configuration.RemoteAddressSideA = remoteIp + ":5552";
            gateway.Configuration.LocalAddressSideB = ip + ":5888";
            //gateway.Configuration.RemoteAddressSideB = remoteIp + ":5777";
            gateway.Configuration.RemoteAddressSideB = "172.25.60.67:5062";
            gateway.Configuration.ConfigurationType = PBCaGw.Configurations.ConfigurationType.UNIDIRECTIONAL;
            gateway.Start();

            Thread.Sleep(5000);

            foreach (var i in channels)
            {
                if (i.Status != ChannelStatus.CONNECTED)
                {
                    Console.WriteLine(i.ChannelName + " not connected.");
                }
            }
            //client.Dispose();

            Console.ReadKey();
            //Console.WriteLine(ch.Get<string>());
        }
Exemplo n.º 16
0
        private static void MultipleCreate()
        {
            Console.WindowWidth = 120;
            Console.BufferWidth = 120;
            Console.WindowHeight = 60;
            Console.BufferHeight = 3000;

            server = new CAServer(IPAddress.Parse(ip), 5777, 5777);
            CAStringRecord record = server.CreateRecord<CAStringRecord>("PCTEST:STR");
            record.Value = "Hello there!";

            gateway = new Gateway();
            gateway.Configuration.GatewayName = "TESTGW";
            gateway.Configuration.LocalAddressSideA = ip + ":5555";
            //gateway.Configuration.LocalAddressSideA = "129.129.130.87:5555";
            gateway.Configuration.RemoteAddressSideA = ip + ":5552";
            gateway.Configuration.LocalAddressSideB = ip + ":5888";
            //gateway.Configuration.RemoteAddressSideB = remoteIp + ":5777";
            gateway.Configuration.RemoteAddressSideB = ip + ":5777";
            gateway.Configuration.ConfigurationType = PBCaGw.Configurations.ConfigurationType.UNIDIRECTIONAL;
            gateway.SaveConfig();

            Gateway.AutoCreateChannel = false;
            Gateway.RestoreCache = false;
            gateway.Start();

            Thread.Sleep(2000);

            EpicsClient c1 = new EpicsClient();
            c1.Configuration.SearchAddress = ip + ":5555";
            EpicsClient c2 = new EpicsClient();
            c2.Configuration.SearchAddress = ip + ":5555";

            EpicsChannel ca1 = c1.CreateChannel("PCTEST:STR");
            EpicsChannel ca2 = c2.CreateChannel("PCTEST:STR");

            Console.WriteLine("Reading...");

            ca1.MonitorChanged += new EpicsDelegate(ca1_MonitorChanged);
            ca2.MonitorChanged += new EpicsDelegate(ca2_MonitorChanged);

            Console.ReadKey();
        }
Exemplo n.º 17
0
        static void MultiConnect()
        {
            EpicsChannel[] channels = new EpicsChannel[intRecords.Length];

            for (int i = 0; i < channels.Length; i++)
                channels[i] = client.CreateChannel("PCT:INT-" + i);

            client.MultiConnect(channels);
            client.Dispose();

            client = new EpicsClient();
            client.Configuration.SearchAddress = "127.0.0.1:5555";
            for (int i = 0; i < channels.Length; i++)
                channels[i] = client.CreateChannel("PCT:INT-" + i);
            client.MultiConnect(channels);

            Console.WriteLine("Done...");
            Dictionary<uint, string> sids = new Dictionary<uint, string>();
            foreach (EpicsChannel c in channels)
            {
                if (sids.ContainsKey(c.SID) && sids[c.SID] != c.ChannelName)
                {
                    Console.WriteLine("Reuse: " + c.SID);
                }
                else if (!sids.ContainsKey(c.SID))
                    sids.Add(c.SID, c.ChannelName);
            }

            client.Dispose();
        }
Exemplo n.º 18
0
        static void MonAll()
        {
            //PBCaGw.Services.Log.Enabled = false;
            Stopwatch sw = new Stopwatch();
            for (int loop = 0; loop < 10; loop++)
            {
                gateway = new Gateway();
                gateway.Configuration.GatewayName = "TESTGW";
                gateway.Configuration.LocalAddressSideA = ip + ":5555";
                //gateway.Configuration.LocalAddressSideA = "129.129.130.87:5555";
                gateway.Configuration.RemoteAddressSideA = remoteIp + ":5552";
                gateway.Configuration.LocalAddressSideB = ip + ":5888";
                //gateway.Configuration.RemoteAddressSideB = remoteIp + ":5777";
                gateway.Configuration.RemoteAddressSideB = "172.25.60.67:5062";
                gateway.Configuration.ConfigurationType = PBCaGw.Configurations.ConfigurationType.UNIDIRECTIONAL;
                gateway.SaveConfig();
                gateway.Start();

                Console.WriteLine("Gateway up");
                //gateway.Configuration.ConfigurationType = PBCaGw.Configurations.ConfigurationType.BIDIRECTIONAL;

                Gateway.BufferedSockets = false;

                Thread.Sleep(1000);
                multiActionCountDown = new CountdownEvent(channelsToConnect.Count(row => !row.Contains("TRACE")));
                hadValue = new Dictionary<string, bool>();
                sw.Start();
                client = new EpicsClient();
                client.Configuration.WaitTimeout = 2000;
                client.Configuration.SearchAddress = ip + ":5555";
                List<EpicsChannel<ExtGraphic<string>>> channels = new List<EpicsChannel<ExtGraphic<string>>>();
                foreach (string i in channelsToConnect.Where(row => !row.Contains("TRACE")))
                {
                    EpicsChannel<ExtGraphic<string>> ch = client.CreateChannel<ExtGraphic<string>>(i);
                    ch.MonitorChanged += new EpicsDelegate<ExtGraphic<string>>(ch_MonitorChangedGotValue);
                    channels.Add(ch);
                }
                if (multiActionCountDown.Wait(5000) == false)
                    Console.WriteLine("Didn't got it...");
                client.Dispose();
                sw.Stop();
                gateway.Dispose();
            }

            Console.WriteLine("Time: " + sw.Elapsed.ToString());
            Console.ReadKey();
        }
Exemplo n.º 19
0
        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 (EpicsClient client = new EpicsClient())
                {
                    client.Configuration.WaitTimeout = 10000;

                    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);

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

                    bool hasError = false;

                    if (usingMonitor)
                    {
                        Console.WriteLine("Monitor and wait for the first value back.");
                        channel.MonitorChanged += new EpicsDelegate <string>(channel_MonitorChanged);
                        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);
                        }
                    }

                    Console.WriteLine(channel.Status.ToString());
                    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("Total: " + prevTime.ToString());
                    Console.WriteLine("Search answered by " + channel.SearchAnswerFrom);
                    Console.WriteLine("IOC: " + channel.IOC);
                    Console.WriteLine("EPICS Type: " + channel.ChannelDefinedType);
                    if (channel.Status != ChannelStatus.CONNECTED || hasError)
                    {
                        Console.Beep();
                    }
                }
            }
        }
        void ContextNewName(DebugContext ctx, string name)
        {
            this.Dispatcher.BeginInvoke((Action)delegate
            {
                if (epicsClient != null)
                {
                    foreach (var i in channels)
                    {
                        i.Dispose();
                    }
                    channels.Clear();
                    epicsClient.Dispose();
                }
                txtGatewayName.Text = name;

                epicsClient = new EpicsClient();
                epicsClient.Configuration.SearchAddress = (string)Properties.Settings.Default["StoredGateway"];

                foreach (var i in channelNames)
                {
                    EpicsChannel<string> channel = epicsClient.CreateChannel<string>(name + i);
                    channels.Add(channel);
                    channel.MonitorChanged += new EpicsDelegate<string>(ChannelMonitorChanged);
                }
            });
        }
Exemplo n.º 21
0
        static void Main(string[] args)
        {
            using (EpicsClient client = new EpicsClient())
            {
                client.Configuration.SearchAddress="129.129.130.87:6789";

                if (args.Length > 0 && args[0] == "-m")
                {
                    //Console.WriteLine("Running monitor mode");
                    EpicsChannel<string>[] channels = new EpicsChannel<string>[100];
                    for (int j = 0; j < channels.Length; j++)
                    {
                        channels[j] = client.CreateChannel<string>("STRESS:INT:" + j / 2);
                        channels[j].MonitorChanged += new EpicsDelegate<string>(Program_MonitorChanged);
                    }
                    Thread.Sleep(5000);
                    int nbNotConnected = 0;
                    for (int j = 0; j < channels.Length; j++)
                    {
                        if (channels[j].Status != ChannelStatus.CONNECTED)
                            nbNotConnected++;
                    }

                    if (nbNotConnected > 0)
                    {
                        Console.WriteLine("Channels not connected: " + nbNotConnected);
                        Console.Beep();
                        Thread.Sleep(10000);
                    }

                    for (int j = 0; j < channels.Length; j++)
                    {
                        channels[j].Dispose();
                    }
                }
                else
                {
                    for (int i = 0; i < 10; i++)
                    {
                        //Console.WriteLine("Create channel");
                        EpicsChannel<string> channel = client.CreateChannel<string>("STRESS:INT");
                        channel.StatusChanged += new EpicsStatusDelegate(channel_StatusChanged);
                        try
                        {
                            //Console.WriteLine("Get");
                            for (int j = 0; j < 10; j++)
                            {
                                string val = channel.Get();
                                if (val != "1234")
                                    Console.WriteLine("Wrong value!");
                                //Console.WriteLine("Got " + val);
                            }
                        }
                        catch
                        {
                            Console.WriteLine("Didn't got back!");
                            //Console.Beep();
                        }
                        channel.Dispose();
                        Thread.Sleep(10);
                    }
                    //Console.WriteLine("Disposed");
                }
            }
        }
Exemplo n.º 22
0
        static void InternTest()
        {
            InitServer();

            gateway = new Gateway();
            gateway.Configuration.LocalAddressSideA = ip + ":5555";
            //gateway.Configuration.LocalAddressSideA = "129.129.130.87:5555";
            gateway.Configuration.RemoteAddressSideA = remoteIp + ":5552";
            gateway.Configuration.LocalAddressSideB = ip + ":5888";
            gateway.Configuration.RemoteAddressSideB = remoteIp + ":5777";
            gateway.Configuration.ConfigurationType = PBCaGw.Configurations.ConfigurationType.UNIDIRECTIONAL;
            //gateway.Configuration.ConfigurationType = PBCaGw.Configurations.ConfigurationType.BIDIRECTIONAL;
            gateway.Start();

            client = new EpicsClient();
            client.Configuration.SearchAddress = ip + ":5555";
            //client.Configuration.SearchAddress = "129.129.130.255:5555";
            //client.Configuration.SearchAddress = "127.0.0.1:5777";

            //MultiConnect();
            //Checks2();

            EpicsChannel ca = client.CreateChannel("PCT:INT-1");
            Console.WriteLine(ca.Get<string>());

            //GetDisconnect();

            Console.WriteLine("Press a key to continue...");
            Console.ReadKey();
        }