public void SetUp()
        {
            server = new CAServer(IPAddress.Parse("127.0.0.1"));
            client = new CAClient();
            client.Configuration.SearchAddress = "127.0.0.1";
            client.Configuration.WaitTimeout   = TIMEOUT;

            record = server.CreateRecord <CADoubleRecord>("TEST:DBL");

            record.LowAlarmLimit       = 25;
            record.LowAlarmSeverity    = Constants.AlarmSeverity.MINOR;
            record.LowLowAlarmLimit    = 20;
            record.LowLowAlarmSeverity = Constants.AlarmSeverity.MAJOR;

            record.HighAlarmLimit        = 100;
            record.HighAlarmSeverity     = Constants.AlarmSeverity.MINOR;
            record.HighHighAlarmLimit    = 105;
            record.HighHighAlarmSeverity = Constants.AlarmSeverity.MAJOR;

            record.Value            = 10;
            record.EngineeringUnits = "My";
            server.Start();
            AutoResetEvent waitOne = new AutoResetEvent(false);

            record.RecordProcessed += (obj, args) =>
            {
                waitOne.Set();
            };
            waitOne.WaitOne();
        }
        private static void Main(string[] args)
        {
            Console.WriteLine("EpicsSharp Channel Access Example Server");
            Console.WriteLine("----------------------------------------");
            Console.WriteLine();

            CAServer server = new CAServer(IPAddress.Parse("129.129.194.45"), 5055, 5055);

            Console.WriteLine("Listening on:");
            Console.WriteLine("  TCP port {0}", server.TcpPort);
            Console.WriteLine("  UDP port {0}", server.UdpPort);
            Console.WriteLine();

            CAStringRecord record = server.CreateRecord <CAStringRecord>("MY-STRING");

            record.Value          = "Hello, EPICS world!";
            record.PrepareRecord += (e, v) =>
            {
                record.Value = "Hello, EPICS world! " + DateTime.Now;
            };
            record.Scan = Constants.ScanAlgorithm.SEC1;
            Console.WriteLine("Registered PV 'MY-STRING'");
            Console.WriteLine();

            Console.WriteLine("Press any key to quit");
            Console.ReadKey();
        }
 public void StartServer()
 {
     server = new CAServer(IPAddress.Parse("127.0.0.1"));
     record = server.CreateRecord <CAIntRecord>("SECOND");
     record.PrepareRecord += record_PrepareRecord;
     record.Scan           = Constants.ScanAlgorithm.HZ2;
     server.Start();
 }
Example #4
0
 public void SetUp()
 {
     server = new CAServer(IPAddress.Parse("127.0.0.1"));
     client = new CAClient();
     client.Configuration.SearchAddress = "127.0.0.1";
     client.Configuration.WaitTimeout   = TIMEOUT;
     server.Start();
 }
Example #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();
        }
        internal static DataPipe CreateServerTcp(CAServer server, Socket client)
        {
            DataPipe res = PopulatePipe(new Type[] { typeof(ServerTcpReceiver), typeof(PacketSplitter), typeof(ServerHandleMessage) });

            //((TcpReceiver)res[0]).Start(iPEndPoint);
            ((ServerHandleMessage)res.LastFilter).Server = server;
            ((ServerTcpReceiver)res.FirstFilter).Init(client);

            return(res);
        }
        internal static DataPipe CreateServerUdp(CAServer server, IPAddress address, int udpPort)
        {
            DataPipe res = new DataPipe();

            res.Add(new UdpReceiver(address, udpPort));
            res[0].Pipe = res;
            AddToPipe(new Type[] { typeof(PacketSplitter), typeof(ServerHandleMessage) }, res);
            ((ServerHandleMessage)res.LastFilter).Server = server;
            return(res);
        }
Example #8
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();
        }
        public CABeacon(CAServer server, int udpPort)
        {
            endPoint = new IPEndPoint(IPAddress.Broadcast, udpPort);
            if (server.ServerAddress == IPAddress.Any)
                serverIps.AddRange(Dns.GetHostAddresses(Dns.GetHostName()).Where(row => !row.IsIPv6LinkLocal && !row.IsIPv6Multicast && !row.IsIPv6SiteLocal && row.AddressFamily == AddressFamily.InterNetwork));
            else
                serverIps.Add(server.ServerAddress);

            runningThread = new Thread(new ThreadStart(Do));
            runningThread.IsBackground = true;
            runningThread.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();
        }
Example #11
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;
                }
            }
        }
Example #12
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();
        }
        internal CATcpConnection(Socket socket, CAServer server)
        {
            pipe = new Pipe();

            Socket = socket;

            processData = new Thread(new ThreadStart(BackgroundProcess));
            processData.IsBackground = true;
            processData.Start();

            Server = server;
            remoteKey = Socket.RemoteEndPoint.ToString();
            Socket.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, ReceiveData, null);

            // Send version
            Socket.Send(new byte[] { 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 0, 0, 0, 0, 0 });

            Closed = false;
        }
        void ServerInit()
        {
            server  = new CAServer(IPAddress.Parse("127.0.0.1"));
            records = new CADoubleRecord[10];

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

            for (var i = 0; i < 10; i++)
            {
                records[i] = server.CreateRecord <CADoubleRecord>("TEST:DBL:" + i);

                records[i].Scan                  = Constants.ScanAlgorithm.HZ10;
                records[i].LowAlarmLimit         = 25;
                records[i].LowAlarmSeverity      = Constants.AlarmSeverity.MINOR;
                records[i].LowLowAlarmLimit      = 20;
                records[i].LowLowAlarmSeverity   = Constants.AlarmSeverity.MAJOR;
                records[i].HighAlarmLimit        = 100;
                records[i].HighAlarmSeverity     = Constants.AlarmSeverity.MINOR;
                records[i].HighHighAlarmLimit    = 105;
                records[i].HighHighAlarmSeverity = Constants.AlarmSeverity.MAJOR;
                records[i].EngineeringUnits      = "My";

                records[i].RecordProcessed += (obj, args) =>
                {
                    Interlocked.Decrement(ref count);
                    countChange.Set();
                };
                records[i].Value = 10;
            }
            server.Start();

            while (Interlocked.Read(ref count) > 0)
            {
                if (!countChange.WaitOne(TIMEOUT))
                {
                    throw new Exception("Timed out");
                }
            }
        }
        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();
        }
        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();
        }
 public CAServerChannel(CAServer cAServer, int serverId, int clientId, string channelName, CATcpConnection tcpConnection)
 {
     // TODO: Complete member initialization
     this.Server = cAServer;
     this.ServerId = serverId;
     this.ClientId = clientId;
     this.ChannelName = channelName;
     this.TcpConnection = tcpConnection;
     tcpConnection.Closing += new EventHandler(tcpConnection_Closing);
     Property = "VAL";
     if (channelName.Contains("."))
     {
         string[] splitted = channelName.Split('.');
         Record = Server.records[splitted[0]];
         Property = splitted[1].ToUpper();
     }
     else
         Record = Server.records[ChannelName];
     if (!Record.CanBeRemotlySet)
         Access = AccessRights.ReadOnly;
     TcpConnection.Send(Server.Filter.ChannelCreatedMessage(ClientId, ServerId, FindType(Record), Record.dataCount, Access));
     //TcpConnection.Send(Server.Filter.ChannelCreatedMessage(ClientId, ServerId, FindType(Record[Property].GetType()), Record.dataCount, Access));
 }
        static void Main(string[] args)
        {
            int port = 5064;
            CAServer server = null;

            try
            {
                //null = IP.Any
                server = new CAServer(null, port, 5064, 5065);
                Console.WriteLine("Connected to configured TCP port (" + port + ")");
            }
            catch (SocketException e)
            {
                if (e.SocketErrorCode == SocketError.AddressAlreadyInUse)
                {
                    //the port is already in use, so ask the OS for a free port
                    server = new CAServer(null, 0, 5064, 5065);
                    Console.WriteLine("Configured TCP port was unavailable.");
                    Console.WriteLine("Using dynamically assigned TCP port " + server.TcpPort);
                }
                else
                {
                    Console.WriteLine("Could not create CAServer: " + e.Message);
                }
            }

            intRecord = server.CreateRecord<CAIntRecord>("TESTSERVER:INT");
            intRecord.PrepareRecord += new EventHandler(intRecord_PrepareRecord);
            intRecord.Scan = CaSharpServer.Constants.ScanAlgorithm.SEC5;

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

            Console.ReadLine();
            server.Dispose();
        }
 public void StopServer()
 {
     server.Dispose();
     server = null;
 }
Example #20
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();*/
        }
        private static void SimpleServer()
        {
            Console.WindowWidth = 120;
            Console.BufferWidth = 120;
            Console.WindowHeight = 60;
            Console.BufferHeight = 3000;

            server = new CAServer(IPAddress.Parse(ip), 5777, 5777);
            CAIntRecord record = server.CreateRecord<CAIntRecord>("MXI1:ILOG:2");
            record.Value = 5;

            gateway = new Gateway();
            gateway.Configuration.GatewayName = "TESTGW";
            gateway.Configuration.LocalAddressSideA = ip + ":5432";
            //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();
            Console.ReadKey();
            gateway.Dispose();
        }
        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();
        }
 private static void InitServer()
 {
     server = new CAServer(IPAddress.Parse(ip), 5777, 5777);
     for (int i = 0; i < intRecords.Length; i++)
     {
         intRecords[i] = server.CreateRecord<CAIntRecord>("PCT:INT-" + i);
         intRecords[i].Scan = CaSharpServer.Constants.ScanAlgorithm.HZ10;
         intRecords[i].PrepareRecord += new EventHandler(Program_PrepareRecord);
     }
 }
 internal CAServerFilter(CAServer server)
 {
     this.Server = server;
 }
        public DiagnosticServer(Gateway gateway, IPAddress address)
        {
            this.gateway = gateway;
            // Starts the diagnostic server
            // using the CAServer library
            diagServer = new CAServer(address, 7890, 7890);
            if (Log.WillDisplay(TraceEventType.Start))
                Log.TraceEvent(TraceEventType.Start, 0, "Starting debug server on " + 7890);
            // CPU usage
            channelCpu = diagServer.CreateRecord<CADoubleRecord>(gateway.Configuration.GatewayName + ":CPU");
            channelCpu.EngineeringUnits = "%";
            channelCpu.CanBeRemotlySet = false;
            channelCpu.Scan = CaSharpServer.Constants.ScanAlgorithm.SEC5;
            channelCpu.PrepareRecord += new EventHandler(channelCPU_PrepareRecord);
            cpuCounter = new PerformanceCounter();
            cpuCounter.CategoryName = "Processor";
            cpuCounter.CounterName = "% Processor Time";
            cpuCounter.InstanceName = "_Total";
            // Mem free
            channelMem = diagServer.CreateRecord<CADoubleRecord>(gateway.Configuration.GatewayName + ":MEM-FREE");
            channelMem.CanBeRemotlySet = false;
            channelMem.Scan = CaSharpServer.Constants.ScanAlgorithm.SEC5;
            channelMem.EngineeringUnits = "Mb";
            channelMem.PrepareRecord += new EventHandler(channelMEM_PrepareRecord);
            ramCounter = new PerformanceCounter("Memory", "Available MBytes");
            // NB Client connections
            channelNbClientConn = diagServer.CreateRecord<CAIntRecord>(gateway.Configuration.GatewayName + ":NBCLIENTS");
            channelNbClientConn.CanBeRemotlySet = false;
            channelNbClientConn.Scan = CaSharpServer.Constants.ScanAlgorithm.SEC5;
            channelNbClientConn.PrepareRecord += new EventHandler(channelNbClientConn_PrepareRecord);
            // NB Server connections
            channelNbServerConn = diagServer.CreateRecord<CAIntRecord>(gateway.Configuration.GatewayName + ":NBSERVERS");
            channelNbServerConn.CanBeRemotlySet = false;
            channelNbServerConn.Scan = CaSharpServer.Constants.ScanAlgorithm.SEC5;
            channelNbServerConn.PrepareRecord += new EventHandler(channelNbServerConn_PrepareRecord);
            // Known channels (PV keept)
            channelKnownChannels = diagServer.CreateRecord<CAIntRecord>(gateway.Configuration.GatewayName + ":PVTOTAL");
            channelKnownChannels.CanBeRemotlySet = false;
            channelKnownChannels.Scan = CaSharpServer.Constants.ScanAlgorithm.SEC5;
            channelKnownChannels.PrepareRecord += new EventHandler(channelKnownChannels_PrepareRecord);
            // Open monitors
            channelOpenMonitor = diagServer.CreateRecord<CAIntRecord>(gateway.Configuration.GatewayName + ":MONITORS");
            channelOpenMonitor.CanBeRemotlySet = false;
            channelOpenMonitor.Scan = CaSharpServer.Constants.ScanAlgorithm.SEC5;
            channelOpenMonitor.PrepareRecord += new EventHandler(channelOpenMonitor_PrepareRecord);
            // Searches per sec
            channelNbSearchPerSec = diagServer.CreateRecord<CAIntRecord>(gateway.Configuration.GatewayName + ":SEARCH-SEC");
            channelNbSearchPerSec.CanBeRemotlySet = false;
            channelNbSearchPerSec.Scan = CaSharpServer.Constants.ScanAlgorithm.SEC5;
            channelNbSearchPerSec.PrepareRecord += new EventHandler(channelNbSearchPerSec_PrepareRecord);
            // Messages per sec
            channelNbMessagesPerSec = diagServer.CreateRecord<CAIntRecord>(gateway.Configuration.GatewayName + ":MESSAGES-SEC");
            channelNbMessagesPerSec.CanBeRemotlySet = false;
            channelNbMessagesPerSec.Scan = CaSharpServer.Constants.ScanAlgorithm.SEC5;
            channelNbMessagesPerSec.PrepareRecord += new EventHandler(channelNbMessagesPerSec_PrepareRecord);
            // DataPacket created per sec
            channelNbCreatedPacketPerSec = diagServer.CreateRecord<CAIntRecord>(gateway.Configuration.GatewayName + ":NEWDATA-SEC");
            channelNbCreatedPacketPerSec.CanBeRemotlySet = false;
            channelNbCreatedPacketPerSec.Scan = CaSharpServer.Constants.ScanAlgorithm.SEC5;
            channelNbCreatedPacketPerSec.PrepareRecord += new EventHandler(channelNbCreatedPacketPerSec_PrepareRecord);
            // DataPacket created per sec
            channelNbPooledPacket = diagServer.CreateRecord<CAIntRecord>(gateway.Configuration.GatewayName + ":POOLED-DATA");
            channelNbPooledPacket.CanBeRemotlySet = false;
            channelNbPooledPacket.Scan = CaSharpServer.Constants.ScanAlgorithm.SEC5;
            channelNbPooledPacket.PrepareRecord += new EventHandler(channelNbPooledPacket_PrepareRecord);
            // TCP Created from startup
            channelNbTcpCreated = diagServer.CreateRecord<CAIntRecord>(gateway.Configuration.GatewayName + ":COUNT-TCP");
            channelNbTcpCreated.CanBeRemotlySet = false;
            channelNbTcpCreated.Scan = CaSharpServer.Constants.ScanAlgorithm.SEC5;
            channelNbTcpCreated.PrepareRecord += new EventHandler(channelNbTcpCreated_PrepareRecord);
            // MAX CID (not reused)
            channelMaxCid = diagServer.CreateRecord<CAIntRecord>(gateway.Configuration.GatewayName + ":MAX-CID");
            channelMaxCid.CanBeRemotlySet = false;
            channelMaxCid.Scan = CaSharpServer.Constants.ScanAlgorithm.SEC5;
            channelMaxCid.PrepareRecord += new EventHandler(channelMaxCID_PrepareRecord);
            // Average CPU usage
            channelAverageCpu = diagServer.CreateRecord<CADoubleRecord>(gateway.Configuration.GatewayName + ":AVG-CPU");
            channelAverageCpu.CanBeRemotlySet = false;
            channelAverageCpu.EngineeringUnits = "%";
            channelAverageCpu.Scan = CaSharpServer.Constants.ScanAlgorithm.SEC5;
            channelAverageCpu.PrepareRecord += new EventHandler(channelAverageCpu_PrepareRecord);

            // Restart channel
            channelRestartGateway = diagServer.CreateRecord<CAIntRecord>(gateway.Configuration.GatewayName + ":RESTART");
            channelRestartGateway.Value = 0;
            channelRestartGateway.PropertySet += new EventHandler<PropertyDelegateEventArgs>(channelRestartGateway_PropertySet);
            // Gateway Version channel
            channelVersion = diagServer.CreateRecord<CAStringRecord>(gateway.Configuration.GatewayName + ":VERSION");
            channelVersion.CanBeRemotlySet = false;
            channelVersion.Value = Gateway.Version;
            // Gateway build date channel
            channelBuild = diagServer.CreateRecord<CAStringRecord>(gateway.Configuration.GatewayName + ":BUILD");
            channelBuild.CanBeRemotlySet = false;
            channelBuild.Value = BuildTime.ToString(CultureInfo.InvariantCulture);
        }