예제 #1
0
 public void StopInstantAI()
 {
     if (instantAiCtrl.State == ControlState.Running)
     {
         instantAiCtrl.Dispose();;
     }
 }
예제 #2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="disposing"></param>
 /// <remarks>
 /// Dispose(bool disposing) executes in two distinct scenarios.
 /// If disposing equals true, the method has been called directly
 /// or indirectly by a user's code. Managed and unmanaged resources
 /// can be disposed.
 /// If disposing equals false, the method has been called by the
 /// runtime from inside the finalizer and you should not reference
 /// other objects. Only unmanaged resources can be disposed.
 /// </remarks>
 private void Dispose(bool disposing)
 {
     // Check to see if Dispose has already been called.
     if (_disposed)
     {
         return;
     }
     // If disposing equals true, dispose all managed and unmanaged resources.
     if (disposing)
     {
         // Dispose managed resources.
         // Step 4: Close device and release any allocated resource.
         InstantAiContrl.Dispose();
         InstantAoContrl.Dispose();
         InstantDiCtrl.Dispose();
         InstantDoCtrl.Dispose();
         _baseDioCtrl.Dispose();
     }
     // Dispose native ( unmanaged ) resources, if exits
     // Note disposing has been done.
     _disposed = true;
 }
        static void Main(string[] args)
        {
            //-----------------------------------------------------------------------------------
            // Configure the following three parameters before running the demo
            //-----------------------------------------------------------------------------------
            //The default device of project is demo device, users can choose other devices according to their needs.
            //string deviceDescription = "DemoDevice,BID#0";
            string    deviceDescription = "USB-4702,BID#0";
            int       startChannel      = 4;
            const int channelCount      = 1;

            ErrorCode errorCode = ErrorCode.Success;

            // Ilosc probek = 250, Czas akwizycji - 1s, Czas miedzy probkami - 1/256 s, Czestotliwosc probkowania 256 Hz
            // Spelnia Twierdzenie Kotielnikowa-Shannona (badany sygnal ma czestliwosc 100 Hz)
            int   sampleIter      = 0;
            int   sampleCount     = 256;
            float sampleFrequency = 100;                         //[Hz]
            float timeSample      = (1f / sampleFrequency) * 1000;
            int   timeSample_i    = (int)Math.Round(timeSample); //[ms]

            // int convertClkRatePerChan = 1000;

            // Step 1: Create a 'InstantAiCtrl' for Instant AI function.
            InstantAiCtrl instantAIContrl = new InstantAiCtrl();

            try
            {
                // Step 2: Select a device by device number or device description and specify the access mode.
                // in this example we use AccessWriteWithReset(default) mode so that we can
                // fully control the device, including configuring, sampling, etc.
                instantAIContrl.SelectedDevice = new DeviceInformation(deviceDescription);

                // Step 3: Read samples and do post-process, we show data here.
                Console.WriteLine(" InstantAI is in progress...\n");
                int      channelCountMax = instantAIContrl.Features.ChannelCountMax;
                double[] scaledData      = new double[channelCount];//the count of elements in this array should not be less than the value of the variable channelCount
                for (int i = 0; i < channelCount; ++i)
                {
                    Console.Write("    channel: {0}", (i % channelCount + startChannel) % channelCountMax);
                }

                Console.WriteLine();
                using (System.IO.StreamWriter file =
                           new System.IO.StreamWriter(@"probki.txt"))
                    do
                    {
                        // read samples, just scaled data in this demo
                        errorCode = instantAIContrl.Read(startChannel, channelCount, scaledData);
                        if (BioFailed(errorCode))
                        {
                            throw new Exception();
                        }
                        // process the acquired samples
                        for (int i = 0; i < channelCount; ++i)
                        {
                            Console.Write(" {0,11:f8}", scaledData[i]);
                            file.WriteLine(" {0,11:f8}", scaledData[i]);
                        }
                        Console.Write("\n");
                        sampleIter++;
                        Thread.Sleep(timeSample_i);
                    } while (sampleIter < sampleCount);
            }
            catch (Exception e)
            {
                // Something is wrong
                string errStr = BioFailed(errorCode) ? " Some error occurred. And the last error code is " + errorCode.ToString()
                                                      : e.Message;
                Console.WriteLine(errStr);
            }
            finally
            {
                // Step 4: Close device and release any allocated resource.
                instantAIContrl.Dispose();
                Console.ReadKey(false);
            }
        }