Beispiel #1
0
 private void ActiveSensor_SelectedIndexChanged(object sender, EventArgs e)
 {
     activeSingleTact = USBdevices[ActiveSensor.SelectedIndex].singleTact;
     if (activeSingleTact.isUSB && activeSingleTact.isCalibrated)
     {
         linkLabel1.Visible = true;
         if (Settings.TabPages.Count > 1)
         {
             Settings.TabPages.RemoveAt(Settings.TabPages.Count - 1);
         }
     }
     else if (activeSingleTact.isUSB && !activeSingleTact.isCalibrated)
     {
         linkLabel1.Visible = true;
         if (Settings.TabPages.Count > 1)
         {
             Settings.TabPages.RemoveAt(Settings.TabPages.Count - 1);
         }
     }
     else if (!activeSingleTact.isUSB && activeSingleTact.isCalibrated)
     {
         linkLabel1.Visible        = true;
         SetSettingsButton.Enabled = true;
     }
     else
     {
         linkLabel1.Visible        = true;
         SetSettingsButton.Enabled = true;
     }
     RefreshFlashSettings_Click(this, null); //Update display
 }
Beispiel #2
0
        /// <summary>
        /// Do work - process sensor data
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AcquisitionWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            backgroundIsFinished_ = false;
            BackgroundWorker worker = sender as BackgroundWorker;

            while (!worker.CancellationPending) //Do the work
            {
                foreach (USBdevice_GUI USB in USBdevices)
                {
                    SingleTact      singleTact = USB.singleTact;
                    SingleTactFrame newFrame   = singleTact.ReadSensorData(); //Get sensor data

                    if (null != newFrame)                                     //If we have data
                    {
                        USB.addFrame(newFrame);

                        // use first timestamp only to quantise readings and match csv output
                        AddData(USBdevices[0].lastTimeStamp, newFrame.SensorData, USB);     //Add to stripchart
                    }
                    else  // USB has been unplugged
                    {
                        new Thread(() =>
                        {
                            guiTimer_.Stop();
                            backgroundIsFinished_ = true;
                            var index             = USBdevices.IndexOf(USB);
                            var comPort           = comPortList[index];
                            var result            = MessageBox.Show(
                                comPort.ToString() + " has been unplugged.\nWould you like to save your data before exiting?",
                                "Error!",
                                MessageBoxButtons.YesNo,
                                MessageBoxIcon.Error);
                            if (result == DialogResult.Yes)
                            {
                                buttonSave_Click(this, null);
                            }
                            Application.Exit();
                        }).Start();
                        backgroundIsFinished_ = false;
                        StopAcquisitionThread();
                        break;
                    }

                    //Calculate rate
                    double delta = newFrame.TimeStamp - USB.lastTimeStamp; // calculate delta relative to previous sensor's last reading
                    if (delta != 0)
                    {
                        measuredFrequency_ = measuredFrequency_ * 0.95 + 0.05 * (1.0 / (delta));      //Averaging
                    }
                    //measuredFrequency_ = 1/delta;
                    USB.setTimestamp(newFrame.TimeStamp);
                }
            }
        }
Beispiel #3
0
 private void tareAllButton_Click(object sender, EventArgs e)
 {
     StopAcquisitionThread();
     foreach (USBdevice USB in USBdevices)
     {
         SingleTact singletact = USB.singleTact;
         if (singletact.Tare())
         {
             RefreshFlashSettings_Click(null, null);
         }
     }
     StartAcquisitionThread();
 }
Beispiel #4
0
 public new bool Initialise(string portName)
 {
     try
     {
         _dataBuffer = new SingleTactData();
         _frameList  = new List <SingleTactFrame>();
         _singleTact = new SingleTact();
         _arduino    = new ArduinoSingleTactDriver();
         _arduino.Initialise(portName); //Start Arduino driver
         _singleTact.Initialise(_arduino);
         _singleTact.I2cAddressForCommunications = ((byte)(4));
         isCalibrated = _singleTact.isCalibrated;
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Beispiel #5
0
        private delegate void CloseMainFormDelegate(); //Used to close the program if hardware is not connected

        public Form1()
        {
            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 < 1; i++)
                {
                    USBdevice USB = new USBdevice();
                    USB.Initialise(finder.prettyToComPort(comPortList[i]));
                    USBdevices.Add(USB);
                    this.Text = comPortList[i];
                }
            }
            activeSingleTact = USBdevices[0].singleTact;
            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);
            }
        }
Beispiel #6
0
        /// <summary>
        /// Fill appropriate Values into GUI Comboboxes
        /// </summary>
        private void PopulateGUIFields()
        {
            // Populate i2c addresses
            i2cAddressInputComboBox_.Items.Clear();

            //TODO appears to be race condition to populate combo box
            // This causes the invalid settings warning
            for (int i = reservedAddresses; i < 128; i++)
            {
                i2cAddressInputComboBox_.Items
                .Add("0x" + i.ToString("X2"));
            }

            //Populate active sensor combobox
            int j = 0;

            foreach (string port in comPortList)
            {
                string[] portSplit = port.Split('-');
                // replace COM port with index
                String name = portSplit[1] + " " + (comPortList.IndexOf(port) + 1).ToString();

                if (USBdevices[j].singleTact.firmwareVersion > 0)
                {
                    if (USBdevices[j].isCalibrated)
                    {
                        name = name + "(calibrated)";
                    }
                }

                ActiveSensor.Items.Add(name);
                j++;
            }
            ActiveSensor.SelectedIndex = 0;
            activeSingleTact           = USBdevices[0].singleTact;

            if (activeSingleTact.Settings.Scaling < 100)
            {
                activeSingleTact.Settings.Scaling = 100;
            }

            int maxWidth = 0;

            System.Windows.Forms.Label dummy = new System.Windows.Forms.Label();
            // find widest label to resize dropdown dynamically
            foreach (var obj in ActiveSensor.Items)
            {
                dummy.Text = obj.ToString();
                int temp = dummy.PreferredWidth;
                if (temp > maxWidth)
                {
                    maxWidth = temp;
                }
            }
            ActiveSensor.DropDownWidth = maxWidth;

            // Get firmware version
            byte fwRev = activeSingleTact.firmwareVersion;

            firmwareLabel.Text = fwRev.ToString();
        }