|
@@ -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;
|
|
|
+
|
|
|
+ public static void Init()
|
|
|
{
|
|
|
- ErrorCode errorCode = ErrorCode.Success;
|
|
|
+
|
|
|
+ waveformAiCtrl.Stopped += new EventHandler<BfdAiEventArgs>(waveformAiCtrl_Stopped);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -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;
|
|
|
-
|
|
|
-
|
|
|
- WaveformAiCtrl waveformAiCtrl = new WaveformAiCtrl();
|
|
|
-
|
|
|
-
|
|
|
- waveformAiCtrl.Stopped += new EventHandler<BfdAiEventArgs>(waveformAiCtrl_Stopped);
|
|
|
-
|
|
|
+ double convertClkRate = 100;
|
|
|
try
|
|
|
{
|
|
|
|
|
|
|
|
|
waveformAiCtrl.SelectedDevice = new DeviceInformation(deviceDescription);
|
|
|
errorCode = waveformAiCtrl.LoadProfile(profilePath);
|
|
|
- if ( BioFailed(errorCode) )
|
|
|
+ if (BioFailed(errorCode))
|
|
|
{
|
|
|
throw new Exception();
|
|
|
}
|
|
@@ -92,7 +94,7 @@ namespace CustomModule.ViewModels
|
|
|
|
|
|
|
|
|
errorCode = waveformAiCtrl.Prepare();
|
|
|
- if ( BioFailed(errorCode) )
|
|
|
+ if (BioFailed(errorCode))
|
|
|
{
|
|
|
throw new Exception();
|
|
|
}
|
|
@@ -100,69 +102,72 @@ namespace CustomModule.ViewModels
|
|
|
|
|
|
|
|
|
|
|
|
- errorCode = waveformAiCtrl.Start();
|
|
|
- if ( BioFailed(errorCode) )
|
|
|
- {
|
|
|
- throw new Exception();
|
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
+ catch
|
|
|
+ {
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- Console.WriteLine(" AsynchronousOneBufferedAI is in progress...\n");
|
|
|
+
|
|
|
|
|
|
-
|
|
|
- do
|
|
|
+ public static void RunTest()
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ errorCode = waveformAiCtrl.Start();
|
|
|
+ if (BioFailed(errorCode))
|
|
|
{
|
|
|
- Thread.Sleep(1000);
|
|
|
- } while ( !Console.KeyAvailable );
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ throw new Exception();
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
- catch ( Exception e )
|
|
|
+ catch (Exception e)
|
|
|
{
|
|
|
|
|
|
- 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
|
|
|
- {
|
|
|
-
|
|
|
- waveformAiCtrl.Dispose();
|
|
|
- Console.ReadKey(false);
|
|
|
- }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
|
|
-
|
|
|
- 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;
|
|
|
+
|
|
|
+ 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;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
}
|