public double[] StartInstantAI() { instantAiCtrl = new InstantAiCtrl(); instantAiCtrl.SelectedDevice = new DeviceInformation(deviceCode); if (!instantAiCtrl.Initialized) { throw new Exception("No device be selected or device open failed!"); } double[] data = new double[4]; ErrorCode er0 = instantAiCtrl.Read(0, out data[0]); ErrorCode er1 = instantAiCtrl.Read(1, out data[1]); ErrorCode er2 = instantAiCtrl.Read(2, out data[2]); ErrorCode er3 = instantAiCtrl.Read(3, out data[3]); return(data); }
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); } }