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