Esempio n. 1
0
        /// <summary>
        /// Add new measurements to the graph
        /// </summary>
        /// <param name="time"></param>
        /// <param name="measurements"></param>
        private void AddData(double time, double[] measurements, USBdevice_GUI USB)
        {
            if (NBtoForceFactor != 0)
            {
                for (int i = 0; i < measurements.Length; i++)
                {
                    measurements[i] = measurements[i] * NBtoForceFactor / 512;
                }
            }

            memorySpaceUse = USB.dataBuffer.AddData(measurements, time);  // update
        }
Esempio n. 2
0
        public GUI()
        {
            string exceptionMessage = null;

            InitializeComponent();
            var finder = new ComPortFinder();

            // Get available serial ports.
            comPortList = finder.findSingleTact();
            if (comPortList.Count == 0)
            {
                MessageBox.Show(
                    "Failed to start sensor: no serial ports found.\n\nPlease ensure Arduino drivers are installed.\nThis can be checked by looking if the Arduino is identified in Device Manager.\n\nPlease connect the device then restart this application.",
                    "Hardware initialisation failed",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Exclamation);
                // There's no point showing the GUI.  Force the app to auto-close.
                Environment.Exit(-1);
            }
            else
            {
                for (int i = 0; i < comPortList.Count; i++)
                {
                    USBdevice_GUI USB = new USBdevice_GUI();
                    USB.Initialise(finder.prettyToComPort(comPortList[i]));
                    USBdevices.Add(USB);
                }
                if (comPortList.Count == 1)
                {
                    updateUIforOneDevice();
                }
            }

            try
            {
                PopulateGUIFields();
                foreach (USBdevice USB in USBdevices)
                {
                    USB.singleTact.PushSettingsToHardware();
                    RefreshFlashSettings_Click(this, null); //Get the settings from flash
                }
                CreateStripChart();
                AcquisitionWorker.RunWorkerAsync(); //Start the acquisition thread

                guiTimer_.Start();
            }
            catch
            {
                string summary = "Failed to start sensor";

                if (comPortList.Count == 0)
                {
                    summary += ": no serial ports detected.";
                }
                else
                {
                    summary += " on " + comPortList[0] + ".";
                }

                summary += "\n\n";

                if (exceptionMessage != null)
                {
                    summary += exceptionMessage;
                }
                else
                {
                    summary += "Please connect the device then restart this application.";
                }

                MessageBox.Show(
                    summary,
                    "Hardware initialisation failed",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Exclamation);

                // There's no point showing the GUI.  Force the app to auto-close.
                Environment.Exit(-1);
            }
        }
Esempio n. 3
0
        private void updateGraph(USBdevice_GUI USB)
        {
            int            index   = USBdevices.IndexOf(USB); // get current sensor number
            SingleTactData data_pt = USB.dataBuffer;

            Color[] colours = { Color.Blue, Color.Orange, Color.DarkViolet, Color.Red, Color.DeepPink, Color.DarkSlateGray };

            if (data_pt.data.Count > 0 && index < colours.Length)
            {
                // start graphing
                GraphPane graphPane = graph_.GraphPane;

                if (graphPane.CurveList.Count <= index)  // initialise curves
                {
                    string name = comPortList[index].ToString().Split('-')[1] + " " + (index + 1).ToString();
                    if (USBdevices[index].singleTact.firmwareVersion > 0)
                    {
                        if (USBdevices[index].isCalibrated)
                        {
                            name = name + "(calibrated)";
                        }
                        if (USB.singleTact.Settings.SerialNumber != 0)
                        {
                            name += " SN" + USB.singleTact.Settings.SerialNumber.ToString("D5");
                        }
                    }
                    LineItem myCurve = new LineItem(
                        name,
                        new PointPairList(),
                        colours[index],
                        SymbolType.None,
                        3.0f);
                    graphPane.CurveList.Add(myCurve);
                }
                else
                {
                    // update curve data with new readings
                    if (data_pt.data[0].Count > 1)
                    {
                        graphPane.CurveList[index].AddPoint(data_pt.data[0].Peek()); //grab the latest value from the buffer.
                        if (graphPane.CurveList[index].NPts > 100 * 60)              //only keep 6000 points on the screen
                        {
                            graphPane.CurveList[index].RemovePoint(0);
                        }
                    }
                }

                // This is to update the max and min value
                if (isFirstFrame_)
                {
                    graphPane.XAxis.Scale.Min = data_pt.MostRecentTime;
                    graphPane.XAxis.Scale.Max = graphPane.XAxis.Scale.Min + graphXRange_;
                    isFirstFrame_             = false;
                }

                if (data_pt.MostRecentTime >= graphPane.XAxis.Scale.Max)
                {
                    graphPane.XAxis.Scale.Max = data_pt.MostRecentTime;
                    graphPane.XAxis.Scale.Min = graphPane.XAxis.Scale.Max - graphXRange_;
                    //Update green valid region box
                    BoxObj b = (BoxObj)graphPane.GraphObjList[0];
                    b.Location.X = graphPane.XAxis.Scale.Max - graphXRange_;
                    if (NBtoForceFactor != 0)
                    {
                        b.Location.Y      = Math.Min(graphPane.YAxis.Scale.Max, NBtoForceFactor);
                        b.Location.Height = Math.Min(graphPane.YAxis.Scale.Max - graphPane.YAxis.Scale.Min, NBtoForceFactor);
                    }
                    else
                    {
                        b.Location.Y      = Math.Min(graphPane.YAxis.Scale.Max, 512);
                        b.Location.Height = Math.Min(graphPane.YAxis.Scale.Max - graphPane.YAxis.Scale.Min, 512);
                    }
                    try
                    {
                        graph_.AxisChange();
                    }
                    catch { }
                }
                graph_.Refresh();
            }
        }