Esempio n. 1
0
        /// <summary>
        /// Start testing for all tubes.
        /// </summary>
        private string Start()
        {
            if (!anyReady)
            {
                return(LogToConsole("No stations are ready."));
            }

            if (!eStopPressed && !doorOpen && doorLocked)
            {
                btnStart.Enabled = btnStop.Enabled = false;
                selected         = null;
                hvEnable         = true;

                foreach (ctlStation s in pan.Controls)
                {
                    s.Start();
                }
                btnStart.Text      = "PAUSE";
                btnStart.BackColor = Color.DarkBlue;
                btnStart.Enabled   = btnStop.Enabled = true;
                SetupResults();
                return(LogToConsole("All stations started."));
            }

            if (eStopPressed)
            {
                return(LogToConsole("Disengage emergency stop."));
            }
            if (doorOpen)
            {
                return(LogToConsole("Close the chamber door."));
            }
            return(LogToConsole("Lock the chamber door."));
        }
Esempio n. 2
0
        /// <summary>
        /// Select station from matrix.
        /// </summary>
        /// <param name="row">Row of matrix.</param>
        /// <param name="col">Column of matrix.</param>
        private string SelectStation(int row, int col)
        {
            selected = null;

            if (testing)
            {
                return("Testing in progress, pause before selecting.");
            }

            if (row > 0 && col > 0)
            {
                foreach (Control c in pan.Controls)
                {
                    c.BackColor = Color.Transparent;
                }
                var s = pan.GetControlFromPosition(col - 1, row - 1);
                if (s != null)
                {
                    selected           = (ctlStation)s;
                    selected.BackColor = Color.SteelBlue;
                }
            }

            return(selected != null ?
                   $"Station: { selected.Name } was selected." : "Station not ready.");
        }
Esempio n. 3
0
        /// <summary>
        /// Immediately abort testing on all tubes.
        /// </summary>
        private string Stop()
        {
            selected           = null;
            hvEnable           = false;
            btnStart.Text      = "START";
            btnStart.BackColor = Color.MediumSeaGreen;
            btnStop.Enabled    = false;

            foreach (ctlStation s in pan.Controls)
            {
                s.Stop();
            }

            return(LogToConsole("All stations stopped."));
        }
Esempio n. 4
0
 /// <summary>
 /// Update results data table.
 /// </summary>
 /// <param name="s">Station to update.</param>
 /// <param name="columns">Columns to update.</param>
 /// <param name="data">Data to write.</param>
 private void UpdateResults(ctlStation s)
 {
     if (s.testID != 0)
     {
         int errCount = 0;
         for (int i = 0; i < s.errorCount.Length; i++)
         {
             errCount += s.errorCount[i];
         }
         db.Update(resultsTable, "Time_End", DateTime.Now, $"TestID = { s.testID }");
         db.Update(resultsTable, "PassFail", s.errReason == "", $"TestID = { s.testID }");
         db.Update(resultsTable, "ErrorMessage", s.errReason, $"TestID = { s.testID }");
         db.Update(resultsTable, "RunTime_hours", s.runTimer.Elapsed.TotalHours, $"TestID = { s.testID }");
         db.Update(resultsTable, "ErrorCount", errCount, $"TestID = { s.testID }");
     }
 }
Esempio n. 5
0
        /// <summary>
        /// Handle when station is done testing.
        /// </summary>
        /// <param name="sender">Station that is done.</param>
        private void DoneTesting(object sender)
        {
            ctlStation s = sender as ctlStation;

            UpdateResults(s);
            Thread.Sleep(500);

            if (s.tub.status == Tube.Status.Done)
            {
                LogToConsole($"{ s.Name } has finished.");
            }
            else if (s.tub.status == Tube.Status.Error)
            {
                LogToConsole($"{ s.Name } has failed.");
            }
            CheckIfAllCompleted();
        }
Esempio n. 6
0
        /// <summary>
        /// Handles the STATIONSTATUS command from the socket and sends back the status of
        /// the requested station.
        /// </summary>
        /// <param name="vMessage">Contains the Socket message that was received</param>
        /// <returns>Returns string that is then sent back to the client</returns>
        public string SocketSTATIONSTATUS(MXSocketMessage vMessage)
        {
            string vRet = "";                                              // Return string to client

            if (vMessage.Data.Length == 1)                                 // Make sure station number was sent
            {
                int        StationNum = Convert.ToInt16(vMessage.Data[0]); // Station Number data is requested for
                ctlStation s          = GetStation(StationNum);
                if (s == null)
                {
                    vRet = $"Station;{ StationNum },Connected;false";
                }
                else
                {
                    vRet  = $"Station;{ StationNum }";
                    vRet += $",StationName;{ s.Name }";
                    vRet += $",Connected;{ s.tub.connected }";
                    vRet += $",SerialNum;{ s.serialNum }";
                    vRet += $",TubeName;{ s.tub.name }";
                    vRet += $",TubeStatus;{ s.tub.status }";
                    string hv = s.tub.on ? "On" : "Off";
                    vRet += $",HVStatus;{ hv }";
                    vRet += $",SetKV;{ s.tub.setkV }";
                    vRet += $",SetUA;{ s.tub.setuA }";
                    vRet += $",MonKV;{ s.tub.monkV }";
                    vRet += $",MonUA;{ s.tub.monuA }";
                    vRet += $",Status;{ s.lblStatus.Text }";
                    vRet += $",Progress;{ s.progressBar.Value }";
                    vRet += $",ErrorReason;{ s.errReason }";
                    vRet += $",ProductImage;{ s.tub.productImageFilePath}";
                    vRet += $",LoggingEnabled;{ s.chkLog.Checked }";
                    vRet += $",LEDOnColor;{ s.ledStatus.OnColor.ToKnownColor().ToString() }";
                    vRet += $",LEDOffColor;{ s.ledStatus.OffColor.ToKnownColor().ToString() }";
                    vRet += $",LEDEnabled;{ s.ledStatus.Value }";
                }
            }
            else
            {
                vRet = "Error - Wrong Number of Arguments"; // Return error
            }
            return(vRet);                                   // Return string to client
        }
Esempio n. 7
0
        /// <summary>
        /// Handle PLC state changes.
        /// </summary>
        /// <param name="e">Event args.</param>
        private void PLCStateChanged(DeviceChangedArgs e)
        {
            Invoke((MethodInvoker) delegate {
                lblSafe.BackColor  = safe ? Color.LightGreen : Color.LightGray;
                lblHV.BackColor    = hvEnable ? Color.White : Color.LightGray;
                lblXrays.BackColor = xRays ? Color.LightBlue : Color.LightGray;
                lblTest.BackColor  = testing ? Color.Gold : Color.LightGray;
                lblError.BackColor = error ? Color.IndianRed : Color.LightGray;
            });

            switch (e.Device.Name)
            {
            case SAF.inPLC_ERRACK:
                if (e.Device.Value)
                {
                    plc.SetState(SAF.inPLC_ERRACK, false);
                }
                break;

            case SAF.inPLC_RESTART:
                if (e.Device.Value)
                {
                    plc.SetState(SAF.inPLC_RESTART, false);
                }
                break;

            case SAF.SFI_CHB_UNLCK:
                doorLocked = !e.Device.Value;
                break;

            case SAF.SFI_CHB_OPEN:
                doorOpen = e.Device.Value;
                break;

            case SAF.SFI_EMO:
                eStopPressed = !e.Device.Value;
                if (eStopPressed)
                {
                    Pause();
                }
                break;

            case SAF.SFO_LED_SAFE:
                safe = e.Device.Value;
                break;

            case SAF.SFO_LED_XRAYS:
                xRays = e.Device.Value;
                break;

            case SAF.SFO_LED_TESTING:
                testing = e.Device.Value;
                Invoke((MethodInvoker) delegate
                {
                    selected = null;
                    Settings.Default.CurrentlyTesting = testing;
                    Settings.Default.Save();
                });
                break;

            case PLC.PLO_LED_ERROR:
                error = e.Device.Value;
                break;

            case SAF.SFO_HV_PWR:
                _hvEnable = e.Device.Value;
                break;

            case PLC.PLO_PS_PWR:
                _psEnable = e.Device.Value;
                break;

            case PLC.PLI_UPS_BATTERY:
                powerLoss = e.Device.Value;
                if (powerLoss)
                {
                    plc.SetState(PLC.PLO_LED_ERROR, powerLoss);
                    Tools.ShutdownPC();
                }
                break;
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Handle actions from barcode scanner, return msg goes to scanner.
        /// </summary>
        /// <param name="bc">Barcode to handle.</param>
        /// <returns>String output to scanner.</returns>
        private string BarcodeResponder(string bc)
        {
            string response = string.Empty;

            if (!bc.Contains(" "))
            {
                int id = 0;
                if (int.TryParse(bc.Split('-')[0], out id))
                {
                    Invoke((MethodInvoker) delegate { response = InitStation(id); });
                }
            }
            else if (bc.Contains("@") && bc.Contains("-"))
            {
                string[] rowcol = bc.Split(' ')[1].Split('-');
                int      row    = int.Parse(rowcol[0]);
                int      col    = int.Parse(rowcol[1]);
                Invoke((MethodInvoker) delegate { response = SelectStation(row, col); });
            }
            else if (bc.Contains("START"))
            {
                Invoke((MethodInvoker) delegate {
                    if (btnStart.Text == "START" || btnStart.Text == "RESUME")
                    {
                        response = Start();
                    }
                    else if (btnStart.Text == "PAUSE")
                    {
                        response = Pause();
                    }
                });
            }
            else if (bc.Contains("STOP"))
            {
                Invoke((MethodInvoker) delegate { response = Stop(); });
            }
            else if (bc.Contains("LOCK"))
            {
                Invoke((MethodInvoker) delegate { response = LockUnlock(); });
            }
            else if (bc.Contains("SAFE"))
            {
                Invoke((MethodInvoker) delegate { response = ResetSafety(); });
            }
            else if (bc.Contains("STATUS"))
            {
                StringBuilder sb = new StringBuilder();
                for (int r = 0; r < pan.RowCount; r++)
                {
                    for (int c = 0; c < pan.ColumnCount; c++)
                    {
                        ctlStation s = (ctlStation)pan.GetControlFromPosition(c, r);
                        if (s != null)
                        {
                            sb.AppendLine($"{ s.Name }: { s.lblStatus.Text }");
                        }
                    }
                }
                response = sb.ToString();
            }
            return(response);
        }
Esempio n. 9
0
        /// <summary>
        /// Connect to all universal tube controllers (utc).
        /// </summary>
        private void Connect()
        {
            int    nr         = pan.RowCount;
            int    nc         = pan.ColumnCount;
            string nameFormat = $"UTC100-{ cabinetName }";

            string[] allUTCs  = new string[nr * nc];
            string[] utcIP    = new string[allUTCs.Length]; // IP addresses of each utc
            string[] spIP     = new string[utcIP.Length];   // IP addresses of each spellman supply
            string[] utcQuery = Link.GetDeviceIP(Settings.Default.Domain + "255", Settings.Default.UDPServerPort, "UTC100" + "-" + cabinetName);
            string[] spQuery  = Settings.Default.SpellmanIP.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < utcIP.Length; i++)
            {
                allUTCs[i] = $"{ nameFormat }-{ (i + 1).ToString("00") }";
                for (int j = 0; j < utcQuery.Length; j++)
                {
                    if (utcQuery[j].Contains(allUTCs[i]))
                    {
                        utcIP[i] = utcQuery[j].Split(',')[1]; // Get IP address of UTC (Name,IP)

                        // Check if there is a spellman supply
                        if (spQuery.Length > i && spQuery[i].Split(' ')[1] != "None")
                        {
                            spIP[i] = spQuery[i].Split(' ')[1];
                        }
                    }
                }
            }
            for (int c = 0; c < nc; c++)
            {
                for (int r = 0; r < nr; r++)
                {
                    int i = (nc * r) + c;
                    if (i < utcIP.Length)
                    {
                        if (utcIP[i] != null && pan.GetControlFromPosition(c, r) == null)
                        {
                            ctlStation s = new ctlStation();
                            s.Name = allUTCs[i].Length > 7 ? allUTCs[i].Substring(7) : cabinetName;
                            if (spIP[i] == null)
                            {
                                s.Connect(utcIP[i]);
                            }
                            else
                            {
                                s.Connect($"{ utcIP[i] } { spIP[i] }");
                            }

                            if (!s.IsDisposed)
                            {
                                s.doneTesting += DoneTesting;
                                s.Dock         = DockStyle.Fill;
                                pan.Controls.Add(s, c, r);
                                LogToConsole($"Found { s.Name } @ { utcIP[i] }"); // Print name and ip of device
                            }
                        }
                    }
                }
            }
            btnStart.Enabled = pan.Controls.Count > 0;
            List <string> plots = new List <string>();

            for (int r = 0; r < pan.RowCount; r++)
            {
                for (int c = 0; c < pan.ColumnCount; c++)
                {
                    ctlStation s = (ctlStation)pan.GetControlFromPosition(c, r);
                    if (s != null)
                    {
                        plots.Add($"{ s.Name } kV");
                        plots.Add($"{ s.Name } uA");
                    }
                }
            }
            gra = new frmGraph();
            gra.ctlGraph1.AddPlots(plots.ToArray());
            btnGraph.Enabled = true;
            db = new DBHelper();
            SetupStatusDB();
            tmrDbWrite.Start();
        }