예제 #1
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();
        }
예제 #2
0
        public void Initialize()
        {
            Server = new CAServer(IPAddress.Parse("127.0.0.1"));
            Client = new CAClient();
            Client.Configuration.SearchAddress = "127.0.0.1";
            Client.Configuration.WaitTimeout   = TIMEOUT;

            var  countChange = new AutoResetEvent(false);
            long count       = 3;

            IntArrayRecord    = Server.CreateArrayRecord <CAIntArrayRecord>(IntArrayChannelName, 20);
            IntSubArrayRecord = Server.CreateSubArrayRecord(IntSubArrayChannelName, IntArrayRecord);
            for (var i = 0; i < IntArrayRecord.Value.Length; i++)
            {
                IntArrayRecord.Value[i] = i;
            }

            FloatSubArrayRecord = Server.CreateSubArrayRecord <CAFloatSubArrayRecord>(FloatSubArrayChannelName, 10);
            for (byte i = 0; i < FloatSubArrayRecord.FullArray.Length; i++)
            {
                FloatSubArrayRecord.FullArray[i] = i;
            }

            ByteSubArrayRecord = Server.CreateSubArrayRecord <CAByteSubArrayRecord>(ByteSubArrayChannelName, 35);
            var str   = "Hello world";
            var bytes = Encoding.ASCII.GetBytes(str);

            for (byte i = 0; i < bytes.Length; i++)
            {
                ByteSubArrayRecord.FullArray[i] = bytes[i];
            }
            ByteSubArrayRecord.Scan = Constants.ScanAlgorithm.HZ10;

            void ProcessedHandler(object obj, EventArgs args)
            {
                Interlocked.Decrement(ref count);
                countChange.Set();
            };

            IntArrayRecord.RecordProcessed      += ProcessedHandler;
            FloatSubArrayRecord.RecordProcessed += ProcessedHandler;
            ByteSubArrayRecord.RecordProcessed  += ProcessedHandler;

            while (Interlocked.Read(ref count) > 0)
            {
                if (!countChange.WaitOne(TIMEOUT))
                {
                    Server.Dispose();
                    throw new Exception("Timed out");
                }
            }
            Server.Start();
        }
        static void Main(string[] args)
        {
            CAServer server = new CAServer(IPAddress.Parse("129.129.130.118"), 5062, 5062);
            intRecord = server.CreateRecord<CAIntRecord>("PCTOTO2:INT");
            intRecord.PrepareRecord += new EventHandler(intRecord_PrepareRecord);
            intRecord.Scan = CaSharpServer.Constants.ScanAlgorithm.HZ10;

            intArray = server.CreateArrayRecord<CAIntArrayRecord>("PCTOTO2:ARR",1000);
            for (int i = 0; i < intArray.Length; i++)
                intArray.Value[i] = i;

            strRecord = server.CreateRecord<CAStringRecord>("PCTOTO2:STR");
            strRecord.Value = "Default";

            Console.ReadLine();
        }
예제 #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;
                }
            }
        }
        public void Initialize()
        {
            Server = new CAServer(IPAddress.Parse("127.0.0.1"));
            Client = new CAClient();
            Client.Configuration.SearchAddress = "127.0.0.1";
            Client.Configuration.WaitTimeout   = TIMEOUT;

            IntArrayRecord = Server.CreateArrayRecord <CAIntArrayRecord>(IntArrayChannelName, 20);
            for (var i = 0; i < IntArrayRecord.Value.Length; i++)
            {
                IntArrayRecord.Value[i] = i;
            }
            Server.Start();

            AutoResetEvent waitOne = new AutoResetEvent(false);

            IntArrayRecord.RecordProcessed += (obj, args) =>
            {
                waitOne.Set();
            };
            waitOne.WaitOne();
        }