Esempio n. 1
0
        private static void PingController(object state)
        {
            ControllerPinger.Change(Timeout.Infinite, Timeout.Infinite);
            bool connected = true;

            if (FDAControllerClient == null)
            {
                connected = false;
            }
            else
            if (FDAControllerClient.Client == null)
            {
                connected = false;
            }
            else
            {
                if (!FDAControllerClient.Connected)
                {
                    connected = false;
                }
                else
                {
                    try
                    {
                        connected = !(FDAControllerClient.Client.Poll(1, SelectMode.SelectRead));
                    }
                    catch (SocketException)
                    {
                        connected = false;
                    }
                }
            }

            if (!connected)
            {
                ControllerConnectionStatus = ConnectionStatus.Disconnected;
                if (!bg_ControllerConnect.IsBusy)
                {
                    bg_ControllerConnect.RunWorkerAsync(new string[] { Host, FDAName, "True" });
                }
            }
            else
            {
                // controller is connected, ask it for the FDA status
                string statusJson = SendCommandToFDAController("FDASTATUS\0");
                Status = FDAStatus.Deserialize(statusJson);

                // and update the GUI, if it's open
                _mainForm?.SetFDAStatus(Status);

                //if (Status.RunStatus == "Running")
                //{
                //    _mainForm?.SetFDAStatus("Normal");

                //    // get the FDA Run time
                //    string ticksString = SendCommandToFDAController("RUNTIME\0");
                //    long ticks;

                //    if (long.TryParse(ticksString, out ticks))
                //    {
                //        _FDARuntime = ticks;
                //        _mainForm?.SetRunTime(ticks);
                //    }

                //    //Thread.Sleep(1000);
                //    // and the DBType (if we don't already know it)
                //    if (_FDADBType == "")
                //    {
                //        _FDADBType = SendCommandToFDAController("DBTYPE\0");
                //        if (_FDADBType != "")
                //            _mainForm?.SetDBType(_FDADBType);
                //    }

                //    // and the version number (if we don't already know it)
                //    if (_FDAVersion == "")
                //    {
                //        _FDAVersion = SendCommandToFDAController("VERSION\0");
                //        if (_FDAVersion != "")
                //            _mainForm?.SetVersion(_FDAVersion);
                //    }



                //}
                //else
                //{
                //    _mainForm?.SetFDAStatus("Stopped");
                //    _FDARuntime = 0;
                //    _FDAVersion = "";
                //    _FDADBType = "";
                //}

                // reset the ping timer
                ControllerPinger.Change(ControllerPingRate, ControllerPingRate);
            }
        }
Esempio n. 2
0
        private void CheckFDAProcess(bool controllerRunning)
        {
            Color  textcolor = GoodColor;
            string result;
            string statusText;

            bool runstatus = ProcessRunning("FDACore");

            // is the FDA running?
            if (runstatus)
            {
                _isStarting = false;
                statusText  = "FDACore process is running";
                textcolor   = GoodColor;

                if (controllerRunning)
                {
                    // Get the current FDA status
                    result = SendRequest(_controllerIP, _controllerPort, "FDASTATUS\0");
                    FDAStatus status = null;
                    try
                    {
                        status = FDAStatus.Deserialize(result);
                    }
                    catch { }

                    if (result == null)
                    {
                        return;
                    }

                    if (status.RunStatus != "")
                    {
                        statusText += ", the status is '" + status.RunStatus + "'";
                    }


                    if (status.RunMode != "")
                    {
                        statusText += "\nFDACore mode is '" + status.RunMode + "'";
                    }

                    // ask the FDA controller for the FDA's current queue count (serves as an 'FDA is responsive' test)
                    //result = SendRequest(_controllerIP, _controllerPort, "TOTALQUEUECOUNT\0");
                    if (status.TotalQueueCount > -1)
                    {
                        statusText += "\n" + status.TotalQueueCount + " items in the communications queues";
                    }
                }
            }
            else
            {
                statusText = "FDACore process is not running";
                textcolor  = BadColor;


                if (!_isStarting && controllerRunning)
                {
                    SafePropertySet(btnFDA, "Enabled", true);
                    SafePropertySet(btnFDA, "Text", "Start");
                }
            }
            SafePropertySet(lblFDA, "Text", statusText);
            SafePropertySet(lblFDA, "ForeColor", textcolor);

            SetButtonMode(btnFDA, runstatus);
        }