|
@@ -5,6 +5,7 @@ using Prism.Mvvm;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
+using System.Net.Sockets;
|
|
|
using System.Text;
|
|
|
using System.Threading;
|
|
|
using System.Threading.Tasks;
|
|
@@ -50,9 +51,17 @@ namespace CustomModule.ViewModels
|
|
|
|
|
|
public class AsynchronousOneBufferedAI
|
|
|
{
|
|
|
- public static void RunTest()
|
|
|
+ public static bool isEnd = false;
|
|
|
+ public static WaveformAiCtrl waveformAiCtrl = new WaveformAiCtrl();
|
|
|
+ public static ErrorCode errorCode = ErrorCode.Success;
|
|
|
+ // Step 1: Create a 'WaveformAiCtrl' for Streaming AI function.
|
|
|
+ public static void Init()
|
|
|
{
|
|
|
- ErrorCode errorCode = ErrorCode.Success;
|
|
|
+
|
|
|
+ waveformAiCtrl.Stopped += new EventHandler<BfdAiEventArgs>(waveformAiCtrl_Stopped);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
//-----------------------------------------------------------------------------------
|
|
|
// Configure the following parameters before running the demo
|
|
|
//-----------------------------------------------------------------------------------
|
|
@@ -60,23 +69,16 @@ namespace CustomModule.ViewModels
|
|
|
string profilePath = "../../../profile/PCI-1711.xml";
|
|
|
int startChannel = 0;
|
|
|
int channelCount = 1;
|
|
|
- int sectionLength = 1024;
|
|
|
+ int sectionLength = 300;
|
|
|
int sectionCount = 1;
|
|
|
- double convertClkRate = 1000.0;
|
|
|
-
|
|
|
- // Step 1: Create a 'WaveformAiCtrl' for Streaming AI function.
|
|
|
- WaveformAiCtrl waveformAiCtrl = new WaveformAiCtrl();
|
|
|
-
|
|
|
- // Step 2: Set the notification event Handler by which we can known the state of operation effectively.
|
|
|
- waveformAiCtrl.Stopped += new EventHandler<BfdAiEventArgs>(waveformAiCtrl_Stopped);
|
|
|
-
|
|
|
+ double convertClkRate = 100;
|
|
|
try
|
|
|
{
|
|
|
// Step 3: Select a device by device number or device description and specify the access mode.
|
|
|
// in this example we use ModeWrite mode so that we can fully control the device, including configuring, sampling, etc.
|
|
|
waveformAiCtrl.SelectedDevice = new DeviceInformation(deviceDescription);
|
|
|
errorCode = waveformAiCtrl.LoadProfile(profilePath);//Loads a profile to initialize the device.
|
|
|
- if ( BioFailed(errorCode) )
|
|
|
+ if (BioFailed(errorCode))
|
|
|
{
|
|
|
throw new Exception();
|
|
|
}
|
|
@@ -92,7 +94,7 @@ namespace CustomModule.ViewModels
|
|
|
|
|
|
// Step 5: prepare the buffered AI.
|
|
|
errorCode = waveformAiCtrl.Prepare();
|
|
|
- if ( BioFailed(errorCode) )
|
|
|
+ if (BioFailed(errorCode))
|
|
|
{
|
|
|
throw new Exception();
|
|
|
}
|
|
@@ -100,69 +102,72 @@ namespace CustomModule.ViewModels
|
|
|
// Step 6: start Asynchronous Buffered AI, 'Asynchronous' means the method returns immediately
|
|
|
// after the acquisition has been started. The 'bufferedAiCtrl_Stopped' method will be called
|
|
|
// after the acquisition is completed.
|
|
|
- errorCode = waveformAiCtrl.Start();
|
|
|
- if ( BioFailed(errorCode) )
|
|
|
- {
|
|
|
- throw new Exception();
|
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
+ catch
|
|
|
+ {
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- Console.WriteLine(" AsynchronousOneBufferedAI is in progress...\n");
|
|
|
+ // Step 2: Set the notification event Handler by which we can known the state of operation effectively.
|
|
|
|
|
|
- // Step 7: The device is acquiring data.
|
|
|
- do
|
|
|
+ public static void RunTest()
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ errorCode = waveformAiCtrl.Start();
|
|
|
+ if (BioFailed(errorCode))
|
|
|
{
|
|
|
- Thread.Sleep(1000);
|
|
|
- } while ( !Console.KeyAvailable );
|
|
|
-
|
|
|
- // step 8: Stop the operation if it is running.
|
|
|
- //waveformAiCtrl.Stop();
|
|
|
-
|
|
|
+ throw new Exception();
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
- catch ( Exception e )
|
|
|
+ catch (Exception e)
|
|
|
{
|
|
|
// Something is wrong
|
|
|
- string errStr = BioFailed(errorCode)? " Some error occurred. And the last error code is " + errorCode.ToString()
|
|
|
- :e.Message;
|
|
|
+ string errStr = BioFailed(errorCode) ? " Some error occurred. And the last error code is " + errorCode.ToString()
|
|
|
+ : e.Message;
|
|
|
Console.WriteLine(errStr);
|
|
|
}
|
|
|
- finally
|
|
|
- {
|
|
|
- // Step 9: close device, release any allocated resource before quit.
|
|
|
- waveformAiCtrl.Dispose();
|
|
|
- Console.ReadKey(false);
|
|
|
- }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
// process the acquired data
|
|
|
static void waveformAiCtrl_Stopped(object sender, BfdAiEventArgs e)
|
|
|
{
|
|
|
- Console.Write(" Acquisition has completed, sample count is " + e.Count.ToString() + ".\n");
|
|
|
- WaveformAiCtrl waveformAiCtrl = (WaveformAiCtrl)sender;
|
|
|
- Int32 channelCountMax = waveformAiCtrl.Features.ChannelCountMax;
|
|
|
- Int32 startChan = waveformAiCtrl.Conversion.ChannelStart;
|
|
|
- Int32 channelCount = waveformAiCtrl.Conversion.ChannelCount;
|
|
|
- Int32 sectionLength = waveformAiCtrl.Record.SectionLength;
|
|
|
- Int32 bufSize = sectionLength * channelCount;
|
|
|
- Int32 getDataCount = 0, returnedCount = 0;
|
|
|
- Int32 remainingCount = e.Count;
|
|
|
- // e.Count notifys that how many samples had been gathered in the 'Stopped' event.
|
|
|
- Double[] allChanData = new Double[bufSize];
|
|
|
-
|
|
|
- do
|
|
|
+ try
|
|
|
{
|
|
|
- getDataCount = Math.Min(bufSize, remainingCount);
|
|
|
- waveformAiCtrl.GetData(getDataCount, allChanData, 0, out returnedCount);
|
|
|
- remainingCount -= returnedCount;
|
|
|
- } while ( remainingCount > 0 );
|
|
|
-
|
|
|
- InternalStorage.Buffs = allChanData;
|
|
|
- InternalStorage.ischange = true;
|
|
|
- Console.WriteLine(" Show each channel's new data:");
|
|
|
- for ( int i = 0; i < channelCount; ++i )
|
|
|
+ Console.Write(" Acquisition has completed, sample count is " + e.Count.ToString() + ".\n");
|
|
|
+ WaveformAiCtrl waveformAiCtrl = (WaveformAiCtrl)sender;
|
|
|
+ Int32 channelCountMax = waveformAiCtrl.Features.ChannelCountMax;
|
|
|
+ Int32 startChan = waveformAiCtrl.Conversion.ChannelStart;
|
|
|
+ Int32 channelCount = waveformAiCtrl.Conversion.ChannelCount;
|
|
|
+ Int32 sectionLength = waveformAiCtrl.Record.SectionLength;
|
|
|
+ Int32 bufSize = sectionLength * channelCount;
|
|
|
+ Int32 getDataCount = 0, returnedCount = 0;
|
|
|
+ Int32 remainingCount = e.Count;
|
|
|
+ // e.Count notifys that how many samples had been gathered in the 'Stopped' event.
|
|
|
+ Double[] allChanData = new Double[bufSize];
|
|
|
+
|
|
|
+ do
|
|
|
+ {
|
|
|
+ getDataCount = Math.Min(bufSize, remainingCount);
|
|
|
+ waveformAiCtrl.GetData(getDataCount, allChanData, 0, out returnedCount);
|
|
|
+ remainingCount -= returnedCount;
|
|
|
+ } while (remainingCount > 0);
|
|
|
+
|
|
|
+ InternalStorage.Buffs = allChanData;
|
|
|
+ InternalStorage.ischange = true;
|
|
|
+ isEnd = false;
|
|
|
+ Console.WriteLine(" Show each channel's new data:");
|
|
|
+ for (int i = 0; i < channelCount; ++i)
|
|
|
+ {
|
|
|
+ Console.WriteLine(" Channel {0}: {1,13:f8}", (i % channelCount + startChan) % channelCountMax, allChanData[i]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch
|
|
|
{
|
|
|
- Console.WriteLine(" Channel {0}: {1,13:f8}", ( i % channelCount + startChan ) % channelCountMax, allChanData[ i ]);
|
|
|
+ isEnd = false;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -170,5 +175,8 @@ namespace CustomModule.ViewModels
|
|
|
{
|
|
|
return err < ErrorCode.Success && err >= ErrorCode.ErrorHandleNotValid;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
}
|