Exemple #1
0
 /// <summary>
 /// Stop acquisition thread
 /// </summary>
 private void StopAcquisitionThread()
 {
     AcquisitionWorker.CancelAsync();
     while (false == backgroundIsFinished_)
     {
         System.Windows.Forms.Application.DoEvents(); //Wait for us to finish
         Thread.Sleep(1);
     }
 }
Exemple #2
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);
            }
        }
Exemple #3
0
 /// <summary>
 /// Start the Acquisition Thread
 /// </summary>
 private void StartAcquisitionThread()
 {
     AcquisitionWorker.RunWorkerAsync();
 }