Exemple #1
0
        /// <summary>
        /// Asynchronous function that initializes DATAQ device and starts data acquisition
        /// </summary>
        protected async void initialize()
        {
            // Get device, preferably by serial number
            IDevice device;

            try
            {
                device = await Discovery.BySerial((string)Program.Settings.json["cycle counter"]["serial"]);
            }
            catch (Exception ex)
            {
                IReadOnlyList <IDevice> devices = await Discovery.AllDevices();

                if (devices.Count > 0)
                {
                    device = devices[0];
                }
                else
                {
                    device = null;
                }
            }

            if (device == null)
            {
                MessageBox.Show("DATAQ device not found.");
                return;
            }
            this.di_1100 = (Dataq.Devices.DI1100.Device)device;

            // Re-configure device
            await this.di_1100.AcquisitionStopAsync();

            this.di_1100.Channels.Clear();

            this.pressureChannel    = (Dataq.Devices.DI1100.AnalogVoltageIn) this.di_1100.ChannelFactory(DataqCycleCounter.IN_PRESSURE, typeof(AnalogVoltageIn));
            this.cycleChannel       = (Dataq.Devices.DI1100.AnalogVoltageIn) this.di_1100.ChannelFactory(DataqCycleCounter.IN_CYCLE, typeof(AnalogVoltageIn));
            this.di_1100.SampleRate = 2 * this.di_1100.SupportedSampleRateRange.Minimum;

            // Start device
            await this.di_1100.InitializeAsync();

            await this.di_1100.AcquisitionStartAsync();

            // Start background task for reading data
            this.readDataTask = new Task(new Action(this.readDataLoop));
            this.readDataTask.Start();
        }