Exemplo n.º 1
0
        public void Post()
        {
            //FORWARD WHEELCHAIR
            double Voltagevalue0, Voltagevalue1;

            Voltagevalue0 = 2.77;
            Voltagevalue1 = 2.5;

            NationalInstruments.DAQmx.Task analogOut0 = new NationalInstruments.DAQmx.Task();
            NationalInstruments.DAQmx.Task analogOut1 = new NationalInstruments.DAQmx.Task();

            AOChannel ChanelAO0, ChanelAO1;

            ChanelAO0 = analogOut0.AOChannels.CreateVoltageChannel("dev2/ao0", "ChanelAO0", 0, 5, AOVoltageUnits.Volts);
            ChanelAO1 = analogOut1.AOChannels.CreateVoltageChannel("dev2/ao1", "ChanelAO1", 0, 5, AOVoltageUnits.Volts);

            AnalogSingleChannelWriter writer0 = new AnalogSingleChannelWriter(analogOut0.Stream);

            writer0.WriteSingleSample(true, Voltagevalue0);


            AnalogSingleChannelWriter writer1 = new AnalogSingleChannelWriter(analogOut1.Stream);

            writer1.WriteSingleSample(true, Voltagevalue1);
        }
Exemplo n.º 2
0
        public void DAQAI()
        {
            //foreach (string s in DaqSystem.Local.Tasks)
            //{
            //    try
            //    {
            //        using (NationalInstruments.DAQmx.Task t = DaqSystem.Local.LoadTask(s))
            //        {
            //            t.Control(TaskAction.Verify);

            //            if (t.AIChannels.Count > 0)
            //            {
            //                AI.Add(s);
            //            }
            //        }
            //    }
            //    catch (DaqException)
            //    {
            //    }
            //}
            //string taskName = AI[0];
            NationalInstruments.DAQmx.Task analogReadTask = DaqSystem.Local.LoadTask("Voltage_Read_Multi");
            AnalogMultiChannelReader       AI_Channel     = new AnalogMultiChannelReader(analogReadTask.Stream);

            do
            {
                Global.AI = AI_Channel.ReadSingleSample();
            } while (exit == false);
        }
Exemplo n.º 3
0
        public string[] ReadDITasks()
        {
            List <string> tasklist = new List <string>();

            foreach (string s in DaqSystem.Local.Tasks)
            {
                try
                {
                    using (NationalInstruments.DAQmx.Task t = DaqSystem.Local.LoadTask(s))
                    {
                        t.Control(TaskAction.Verify);

                        if (t.DIChannels.Count > 0 && t.Timing.SampleTimingType == SampleTimingType.OnDemand)
                        {
                            tasklist.Add(s);
                        }
                    }
                }
                catch (DaqException)
                {
                }
            }
            string[] tasks = tasklist.ToArray();
            return(tasks);
        }
Exemplo n.º 4
0
        private void AnalogInCallback(IAsyncResult ar)
        {
            try
            {
                if (runningTask != null && runningTask == ar.AsyncState)
                {
                    // Read the available data from the channels
                    data = analogInReader.EndReadWaveform(ar);
                    if (_queueMode == true) //Sikres at der ikke bliver lagt målinger i kø når der laves kalibrering
                    {
                        RawData reading = new RawData();
                        reading.SetRawDataSample(data);
                        _rawDataQueue.Enqueue(reading); //Consumer producer patteren

                        RawData reading2 = new RawData();
                        reading2.SetRawDataSample(data);
                        _saveDataQueue.Enqueue(reading2);
                    }
                    analogInReader.BeginMemoryOptimizedReadWaveform(_daqSettingsDTO.SamplesPerChannel,
                                                                    analogCallback, myTask, data);
                }
            }
            catch (DaqException exception)
            {
                // Display Errors
                runningTask = null;
                myTask.Dispose();
            }
        }
Exemplo n.º 5
0
        public bool Digital_Connect(string DAQName)
        {
            bool flag = false;

            try
            {
                flag      = true;
                Writetask = new NationalInstruments.DAQmx.Task();
                Writetask.DOChannels.CreateChannel(DAQName + "/port0/line0:7", "", ChannelLineGrouping.OneChannelForAllLines);
                Writer = new DigitalSingleChannelWriter(Writetask.Stream);

                for (int i = 0; i < 8; i++)
                {
                    LED[i] = false;
                }
                if (Writer != null)
                {
                    Writer.WriteSingleSampleMultiLine(true, LED);
                }
            }
            catch (DaqException Exception)
            {
                flag = false;
                MessageBox.Show(Exception.Message);
            }
            return(flag);
        }
Exemplo n.º 6
0
        ///Reads the tcontrol volatege from the DAQ
        public static double ReadControl()
        {
            double analogData      = 0;
            var    temperatureTask = new NationalInstruments.DAQmx.Task();

            try
            {
                temperatureTask.AIChannels.CreateVoltageChannel(deviceName + "/ai1", "Volt", AITerminalConfiguration.Rse, 0, 5, AIVoltageUnits.Volts);
                var reader = new AnalogSingleChannelReader(temperatureTask.Stream);
                analogData = reader.ReadSingleSample();
                if ((analogData < -0.5) || (analogData > 5.5))
                {
                    throw new Exception("Data from temperatureTask outside boundries");
                }
            }
            catch (Exception e)
            {
                analogData = 999; //999 is an error code
            }
            finally
            {
                temperatureTask.Dispose();
            }
            return(analogData);
        }
Exemplo n.º 7
0
        private void AnalogInCallback(IAsyncResult ar)
        {
            try
            {
                if (runningTask != null && runningTask == ar.AsyncState)
                {
                    // Read the available data from the channels
                    data = reader.EndReadWaveform(ar);

                    // Plot your data here
                    dataToDataTable(data, ref dataTable);
                    Debug.WriteLine("AnalogInCallback");
                    //// Check for and report any overloaded channels
                    //if (overloadDetectionCheckBox.Checked)
                    //  ReportOverloadedChannels();

                    reader.BeginMemoryOptimizedReadWaveform(samplesPerChannel,
                                                            analogCallback, myTask, data);
                }
            }
            catch (DaqException exception)
            {
                // Display Errors
                Console.WriteLine(exception.Message);
                runningTask = null;
                myTask.Dispose();
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// 使用AIChannelConfiguration进行NI采集卡通道配置
        /// </summary>
        /// <param name="niTask"></param>
        /// <param name="channelConfiguration"></param>
        public static void MapAndConfigChannel(NationalInstruments.DAQmx.Task niTask, AIChannelConfiguration channelConfiguration)
        {
            AITerminalConfiguration niTerminalConfig;

            switch (channelConfiguration.TerminalConfigType)
            {
            case AITerminalType.NRSE:
                niTerminalConfig = AITerminalConfiguration.Nrse;
                break;

            case AITerminalType.RSE:
                niTerminalConfig = AITerminalConfiguration.Rse;
                break;

            case AITerminalType.Differential:
                niTerminalConfig = AITerminalConfiguration.Differential;
                break;

            case AITerminalType.Pseudodifferential:
                niTerminalConfig = AITerminalConfiguration.Pseudodifferential;
                break;

            default:
                throw new Exception("终端输入方式(差分、单端等)配置错误!");
            }
            //channelName是NI驱动规定格式的字符串,单位默认是伏特
            niTask.AIChannels.CreateVoltageChannel((string)channelConfiguration.ChannelName, "", niTerminalConfig, channelConfiguration.MinimumValue, channelConfiguration.MaximumValue, AIVoltageUnits.Volts);
        }
Exemplo n.º 9
0
        //포트0 연결
        public bool Connect_port0_write()
        {
            bool flag = false;

            try
            {
                flag      = true;
                Writetask = new NationalInstruments.DAQmx.Task();
                Writetask.DOChannels.CreateChannel(ini.GetIniValue("NI", "Name") + "/port0/line0:7", "Digital Output Port0", ChannelLineGrouping.OneChannelForAllLines);
                writer = new DigitalSingleChannelWriter(Writetask.Stream);

                for (int i = 0; i < 8; i++)
                {
                    LED[i] = false;
                }
                if (writer != null)
                {
                    writer.WriteSingleSampleMultiLine(true, LED);
                }
            }
            catch
            {
                flag = false;
            }
            return(flag);
        }
Exemplo n.º 10
0
        //포트0 연결
        public bool Connect_port0_read(ref string ErrorMsg)
        {
            bool flag = false;

            try
            {
                flag = true;

                Readtask = new NationalInstruments.DAQmx.Task();
                Readtask.DIChannels.CreateChannel(ini.GetIniValue("NI", "Name") + "/port0/line0:7", "Digital Input", ChannelLineGrouping.OneChannelForAllLines);
                reader = new DigitalSingleChannelReader(Readtask.Stream);

                if (reader != null)
                {
                    Input = reader.ReadSingleSampleMultiLine();
                }
            }
            catch (DaqException de)
            {
                flag     = false;
                ErrorMsg = de.Message;
            }
            catch (Exception e)
            {
                ErrorMsg = e.Message;
            }
            return(flag);
        }
Exemplo n.º 11
0
        /// <summary>
        /// 停止任务,回到idle状态
        /// </summary>
        /// <returns></returns>
        public bool TryStopTask()
        {
            if (aiTask != null)
            {
                try
                {
                    aiTask.Stop();

                    //之前没有,发布停事件
                    //OnAITaskStopped();
                }
                catch (Exception ex)
                {
                    //目前啥也不用做
                }
                Thread.Sleep(1000);
                if (aiTask != null)
                {
                    aiTask.Dispose();
                }
                aiTask  = null;
                AIState = Status.Idle;
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 12
0
 private void StopAcquisitionBtn_Click(object sender, EventArgs e)
 {
     try
     {
         if (runningTask != null)
         {
             // Dispose of the task
             runningTask = null;
             myTask.Dispose();
         }
         _log.Info("Stop to Data acquisition.");
         SamplingTextbox.Enabled     = true;
         DataLengthtextBox.Enabled   = true;
         ChanneltextBox.Enabled      = true;
         FreqrangetextBox.Enabled    = true;
         DeviceIDtextBox.Enabled     = true;
         FreqMintextBox.Enabled      = true;
         FreqMaxtextBox.Enabled      = true;
         StartAcquisitionBtn.Enabled = true;
         StopAcquisitionBtn.Enabled  = false;
         acquisitionstatus.Text      = "Status : Stop";
         acquisitionbar.Style        = System.Windows.Forms.ProgressBarStyle.Blocks;
     }
     catch (Exception err)
     {
         _log.Error("Stop acquisition failed  message is ---" + err.Message);
         MessageBox.Show(err.Message);
         myTask.Dispose();
     }
 }
Exemplo n.º 13
0
        private double ReadSensor(string panel, string port, int nbr)
        {
            double sample = 00.0D;

            try
            {
                using (NationalInstruments.DAQmx.Task analogInTask = new NationalInstruments.DAQmx.Task("ReadSensor" + panel + port + nbr))
                {
                    AIChannel myAIChannel;

                    myAIChannel = analogInTask.AIChannels.CreateVoltageChannel("Dev1/ai2", "myAIChannel", AITerminalConfiguration.Differential, -5, 10, AIVoltageUnits.Volts);

                    // Create the reader and attach it to the stream
                    AnalogSingleChannelReader reader = new AnalogSingleChannelReader(analogInTask.Stream);

                    sample = reader.ReadSingleSample();
#if DEBUG
                    Console.WriteLine("Read Data Value {0}", sample);
#endif
                }
            }
            catch (DaqException ex)
            {
                MessageBox.Show(ex.Message);
                eventLog1.WriteEntry("Read Sensor Error - " + ex.Message);
                sample = -999.0D;
            }
            finally
            { }

            return(sample);
        }
Exemplo n.º 14
0
        private void AnalogCallback(IAsyncResult ar)
        {
            try
            {
                if (runningTask != null && runningTask == ar.AsyncState && timer1.Enabled)
                {
                    data = Reader.EndReadWaveform(ar);

                    dataRead(data);

                    Reader.BeginMemoryOptimizedReadWaveform(samples, Callback, myTask, data);
                }
                if (!timer1.Enabled)
                {
                    BTN_Reset.Enabled = true;
                    BTN_Open.Enabled  = true;
                    BTN_Data.Enabled  = true;
                    runningTask       = null;
                    myTask.Dispose();
                }
            }
            catch (DaqException de)
            {
                MessageBox.Show(de.Message);
                runningTask = null;
                myTask.Dispose();
                BTN_Reset.Enabled = false;
                BTN_Start.Enabled = true;
            }
        }
Exemplo n.º 15
0
        private async System.Threading.Tasks.Task ReadData(NationalInstruments.DAQmx.Task aiTask, int channelCount, int readSamplePerTime)
        {
            await System.Threading.Tasks.Task.Run(() =>
            {
                AnalogMultiChannelReader reader = new AnalogMultiChannelReader(aiTask.Stream);
                int totalReadDataLength         = 0;
                do
                {
                    double[,] readData = new double[channelCount, readSamplePerTime];
                    int actualLength;
                    reader.MemoryOptimizedReadMultiSample(readSamplePerTime, ref readData, ReallocationPolicy.DoNotReallocate, out actualLength);

                    System.Diagnostics.Debug.WriteLine("Data arrival!" + actualLength + " Thread no: " + Thread.CurrentThread.ManagedThreadId.ToString());

                    OnDataArrival(readData);
                    totalReadDataLength += readSamplePerTime;
                    if (AIState == Status.Ready)
                    {
                        //ready -> running
                        AIState = Status.Running;
                    }
                    //当读够数据则停止
                    if (aiTask.IsDone)
                    {
                        OnAITaskStopped();
                        break;
                    }
                }while (true);
            });
        }
Exemplo n.º 16
0
        /// <summary>
        /// 使用AITriggerConfiguration进行NI采集卡触发及多卡同步配置
        /// </summary>
        /// <param name="niTask"></param>
        /// <param name="triggerConfiguration"></param>
        public static void MapAndConfigTrigger(NationalInstruments.DAQmx.Task niTask, AITriggerConfiguration triggerConfiguration)
        {
            switch (triggerConfiguration.TriggerType)
            {
            case AITriggerType.Immediate:
                //没触发,无需配置
                break;

            case AITriggerType.DigitalTrigger:
                DigitalEdgeStartTriggerEdge digitalTriggerEdge;
                switch (triggerConfiguration.TriggerEdge)
                {
                case Edge.Falling:
                    digitalTriggerEdge = DigitalEdgeStartTriggerEdge.Falling;
                    break;

                case Edge.Rising:
                    digitalTriggerEdge = DigitalEdgeStartTriggerEdge.Rising;
                    break;

                default:
                    throw new Exception("触发边沿配置错误!");
                }
                niTask.Triggers.StartTrigger.ConfigureDigitalEdgeTrigger((string)triggerConfiguration.TriggerSource, digitalTriggerEdge);
                //设置为0 NI报错
                if (triggerConfiguration.Delay != 0)
                {
                    niTask.Triggers.StartTrigger.DelayUnits = StartTriggerDelayUnits.Seconds;
                    niTask.Triggers.StartTrigger.Delay      = triggerConfiguration.Delay;
                }
                break;

            case AITriggerType.AnalogTrigger:
                AnalogEdgeStartTriggerSlope analogTriggerEdge;
                switch (triggerConfiguration.TriggerEdge)
                {
                case Edge.Falling:
                    analogTriggerEdge = AnalogEdgeStartTriggerSlope.Falling;
                    break;

                case Edge.Rising:
                    analogTriggerEdge = AnalogEdgeStartTriggerSlope.Rising;
                    break;

                default:
                    throw new Exception("触发边沿配置错误!");
                }
                //默认触发电平2.5v
                niTask.Triggers.StartTrigger.ConfigureAnalogEdgeTrigger((string)triggerConfiguration.TriggerSource, analogTriggerEdge, 2.5);
                if (triggerConfiguration.Delay != 0)
                {
                    niTask.Triggers.StartTrigger.DelayUnits = StartTriggerDelayUnits.Seconds;
                    niTask.Triggers.StartTrigger.Delay      = triggerConfiguration.Delay;
                }
                break;

            default:
                throw new Exception("触发方式配置错误!");
            }
        }
Exemplo n.º 17
0
        public void SetScopeAddr(int addr)
        {
            byte addrOut = (byte)(~addr & 0xFF);

            //Ignore any invalid addresses and set to 0
            if (addr > MaxAddr)
            {
                addrOut = 0;
            }

            //Set address using a single port write
            try
            {
                using (NationalInstruments.DAQmx.Task digitalWriteTask = new NationalInstruments.DAQmx.Task())
                {
                    string addressCh = outputs[(int)OutputSignals.ScopeAddr0].slot;
                    addressCh += "/port" + outputs[(int)OutputSignals.ScopeAddr0].port.ToString();
                    //addressCh += "/line0:7";
                    digitalWriteTask.DOChannels.CreateChannel(addressCh, "", ChannelLineGrouping.OneChannelForAllLines);
                    DigitalSingleChannelWriter writer = new DigitalSingleChannelWriter(digitalWriteTask.Stream);
                    writer.WriteSingleSamplePort(true, addrOut);
                }
            }
            catch
            {
            }

            //Wait for relays to switch
            Thread.Sleep(RelayWaitMs);
        }
Exemplo n.º 18
0
 /// <summary>
 /// Starter den asynkrone indlæsning af data fra DAQ'en
 /// </summary>
 /// <param name="samples"></param>
 public void startInputAsync(int samples)
 {
     this.samples = samples;
     indstilDAQ();
     inputCallback = new AsyncCallback(InputRead);
     runningTask   = analogInTask;
     reader.BeginReadMultiSample(samples, inputCallback, analogInTask);
 }
Exemplo n.º 19
0
 public void stopDAQ()
 {
     // Dispose of the task
     runningTask = null;
     myTask.Dispose();
     time   = 0;
     rowIdx = 0;
 }
        public TempSensor(string physicalChannelName, AIVoltageUnits aiUnits, string tempUnits)
        {
            this.tempUnits = tempUnits;

            readTask = new NationalInstruments.DAQmx.Task();
            reader   = new AnalogSingleChannelReader(readTask.Stream);
            readTask.AIChannels.CreateVoltageChannel(physicalChannelName, "", AITerminalConfiguration.Rse, -10.0, 10.0, aiUnits);
        }
Exemplo n.º 21
0
        public void startTempReading(tempCallback itcb)
        {
            try
            {
                tcb    = itcb;
                myTask = new NationalInstruments.DAQmx.Task();
                AIChannel          channel1;
                AIChannel          channel2;
                AIThermocoupleType thermocoupleType;



                thermocoupleType = AIThermocoupleType.K;
                string[] channellist = DaqSystem.Local.GetPhysicalChannels(PhysicalChannelTypes.AI, PhysicalChannelAccess.External);

                channel1 = myTask.AIChannels.CreateThermocoupleChannel(channellist[1], "", 0, 1000, thermocoupleType, AITemperatureUnits.DegreesC);
                channel2 = myTask.AIChannels.CreateThermocoupleChannel(channellist[3], "", 0, 1000, thermocoupleType, AITemperatureUnits.DegreesC);
                channel1.AutoZeroMode = AIAutoZeroMode.Once;
                channel2.AutoZeroMode = AIAutoZeroMode.Once;

                /* if (scxiModuleCheckBox.Checked)
                 * {
                 *   switch (autoZeroModeComboBox.SelectedIndex)
                 *   {
                 *       case 0:
                 *           autoZeroMode = AIAutoZeroMode.None;
                 *           break;
                 *       case 1:
                 *       default:
                 *           autoZeroMode = AIAutoZeroMode.Once;
                 *           break;
                 *   }
                 *   myChannel.AutoZeroMode = autoZeroMode;
                 * }*/

                myTask.Timing.ConfigureSampleClock("", 4,
                                                   SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples, 1000);

                myTask.Control(TaskAction.Verify);

                analogInReader = new AnalogMultiChannelReader(myTask.Stream);

                runningTask = myTask;
                //InitializeDataTable(myTask.AIChannels, ref dataTable);
                //acquisitionDataGrid.DataSource = dataTable;

                // Use SynchronizeCallbacks to specify that the object
                // marshals callbacks across threads appropriately.
                analogInReader.SynchronizeCallbacks = true;
                analogInReader.BeginReadWaveform(10, myAsyncCallback, myTask);
            }
            catch (DaqException exception)
            {
                //MessageBox.Show(exception.Message);
                myTask.Dispose();
                runningTask = null;
            }
        }
Exemplo n.º 22
0
        public void Setup_USB6008()
        {
            //Resets and configures the NI USB6008 Daq boards
            Device dev = DaqSystem.Local.LoadDevice(loc);//added to reset the DAQ boards if they fail to comunicate giving error code 50405

            dev.Reset();
            AIChannel StrainChannel, CurrentChannel;
            AOChannel LateralMotorChannel, TraverseMotorChannel;

            try
            {
                //Setting up NI DAQ for Axial Force Measurment via Strain Circuit and current Measurment of Spindle Motor for torque
                USB6008_AITask = new NationalInstruments.DAQmx.Task();

                StrainChannel = USB6008_AITask.AIChannels.CreateVoltageChannel(
                    loc + "/ai0",                         //Physical name of channel
                    "strainChannel",                      //The name to associate with this channel
                    AITerminalConfiguration.Differential, //Differential Wiring
                    -0.1,                                 //-0.1v minimum
                    NIMaxVolt,                            //1v maximum
                    AIVoltageUnits.Volts                  //Use volts
                    );
                CurrentChannel = USB6008_AITask.AIChannels.CreateVoltageChannel(
                    loc + "/ai1",                         //Physical name of channel
                    "CurrentChannel",                     //The name to associate with this channel
                    AITerminalConfiguration.Differential, //Differential Wiring
                    -0.1,                                 //-0.1v minimum
                    10,                                   //10v maximum
                    AIVoltageUnits.Volts                  //Use volts
                    );
                USB6008_Reader = new AnalogMultiChannelReader(USB6008_AITask.Stream);
                ////////////////////////////////////////////////////////////
                USB6008_AOTask       = new NationalInstruments.DAQmx.Task();
                TraverseMotorChannel = USB6008_AOTask.AOChannels.CreateVoltageChannel(
                    loc + "/ao0",            //Physical name of channel)
                    "TravverseMotorChannel", //The name to associate with this channel
                    0,                       //0v minimum
                    5,                       //5v maximum
                    AOVoltageUnits.Volts
                    );
                LateralMotorChannel = USB6008_AOTask.AOChannels.CreateVoltageChannel(
                    loc + "/ao1",          //Physical name of channel)
                    "LateralMotorChannel", //The name to associate with this channel
                    0,                     //0v minimum
                    5,                     //5v maximum
                    AOVoltageUnits.Volts
                    );
                USB6008_Analog_Writter = new AnalogMultiChannelWriter(USB6008_AOTask.Stream);
                ////////////////////////////////////////////////////////////
                USB6008_DOTask = new NationalInstruments.DAQmx.Task();
                USB6008_DOTask.DOChannels.CreateChannel(loc + "/port0", "port0", ChannelLineGrouping.OneChannelForAllLines);
                USB6008_Digital_Writter = new DigitalSingleChannelWriter(USB6008_DOTask.Stream);
            }
            catch (NationalInstruments.DAQmx.DaqException e)
            {
                Console.WriteLine("Error?\n\n" + e.ToString(), "NI USB 6008 1 Error");
            }
        }
Exemplo n.º 23
0
 public void StopMeasurement()
 {
     if (runningTask != null)
     {
         // Dispose of the task
         runningTask = null;
         myTask.Dispose();
     }
 }
Exemplo n.º 24
0
        public DAQ()
        {
            task      = null;
            IsConnect = false;

            LED   = new bool[8];
            Input = new bool[8];
            P1LED = new bool[4];
        }
Exemplo n.º 25
0
        /// <summary>
        /// 启动AI采集任务
        /// </summary>
        public void TryArmTask()
        {
            if (AIState != Status.Idle)
            {
                throw new Exception("If you want to arm, the AI state must be 'Idle'!");
            }
            else
            {
                if (aiTask == null)
                {
                    try
                    {
                        hasFinishFlag = false;
                        //新建任务
                        aiTask = new NationalInstruments.DAQmx.Task();

                        //aiTask.Stream.ReadAutoStart = true;

                        //配置任务
                        NIAIConfigMapper.MapAndConfigAll(aiTask, _staticConfig);

                        //获取并设置通道数
                        _staticConfig.ChannelCount = aiTask.AIChannels.Count;

                        //使用NI Task中的EveryNSamplesRead事件读取数据
                        aiTask.EveryNSamplesReadEventInterval = _staticConfig.ClockConfig.ReadSamplePerTime;
                        aiTask.EveryNSamplesRead += AiTask_EveryNSamplesRead;

                        //计算读取次数
                        times      = 0;
                        totalTimes = _staticConfig.ClockConfig.TotalSampleLengthPerChannel / _staticConfig.ClockConfig.ReadSamplePerTime;

                        //Verify the Task
                        aiTask.Control(TaskAction.Verify);

                        //read stream
                        //使用reader读数据
                        reader = new AnalogMultiChannelReader(aiTask.Stream);

                        aiTask.SynchronizeCallbacks = true;

                        //开始任务
                        aiTask.Start();

                        //idle -> ready
                        AIState = Status.Ready;
                    }
                    catch (DaqException ex)
                    {
                        //ex.Message
                        goError();
                        throw ex;
                    }
                }
            }
        }
Exemplo n.º 26
0
        public void RunDAQ()
        {
            DigitalEdgeStartTriggerEdge triggerEdge = DigitalEdgeStartTriggerEdge.Rising;

            try
            {
                string s = string.Empty;
                s          = _name == "/ai1" ? "etalon" : "measured";
                inputTask  = new NationalInstruments.DAQmx.Task(s);
                outputTask = new NationalInstruments.DAQmx.Task(s + "_output");

                inputTask.AIChannels.CreateVoltageChannel(sInputName, "", AITerminalConfiguration.Pseudodifferential, inputDAQMinValue, inputDAQMaxValue, AIVoltageUnits.Volts);
                outputTask.AOChannels.CreateVoltageChannel(sOutputName, "", outputDAQMinValue, outputDAQMaxValue, AOVoltageUnits.Volts);

                inputTask.Timing.ConfigureSampleClock("", dRateIO, SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples, iInputOutputSamples);
                outputTask.Timing.ConfigureSampleClock("", dRateIO, SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples, iInputOutputSamples);

                outputTask.Triggers.StartTrigger.ConfigureDigitalEdgeTrigger(terminalNameBase + "ai/StartTrigger", triggerEdge);

                inputTask.Control(TaskAction.Verify);
                outputTask.Control(TaskAction.Verify);

                outputData = fGen.Data;

                writer = new AnalogSingleChannelWriter(outputTask.Stream);
                writer.WriteMultiSample(false, outputData);

                StartTask();
                outputTask.Start();
                inputTask.Start();

                //inputCallback = new AsyncCallback(InputReady);
                reader = new AnalogSingleChannelReader(inputTask.Stream);


                //------------ТЕСТОВЫЙ КУСОК------------ ЧТЕНИЕ В ЭТОМ ЖЕ ПОТОКЕ--
                double[] data = reader.ReadMultiSample(iInputOutputSamples);

                BufReadDAQReceived?.Invoke(data);
                StopTask();
                //----------------------------------------------------------------



                /*// Use SynchronizeCallbacks to specify that the object
                 * // marshals callbacks across threads appropriately.
                 * reader.SynchronizeCallbacks = bSynchronizeCallbacks;
                 *
                 * reader.BeginReadMultiSample(iInputOutputSamples, inputCallback, inputTask);*/
            }
            catch (Exception ex)
            {
                StopTask();
                WarningDAQUpdate?.Invoke(ex.Message);
            }
        }
Exemplo n.º 27
0
    public void DAQAI()
    {
        NationalInstruments.DAQmx.Task analogReadTask = DaqSystem.Local.LoadTask("Voltage_Read_Single");
        AnalogSingleChannelReader      AI_Channel     = new AnalogSingleChannelReader(analogReadTask.Stream); // If task has only 1 channel

        do
        {
            Global.AI_Single = AI_Channel.ReadSingleSample();
        } while (exit == false);
    }
Exemplo n.º 28
0
        public void DAQDO()
        {
            NationalInstruments.DAQmx.Task digitalWriteTask = DaqSystem.Local.LoadTask("Digital_Write_Single");
            DigitalSingleChannelWriter     DO_Channel       = new DigitalSingleChannelWriter(digitalWriteTask.Stream);

            do
            {
                DO_Channel.WriteSingleSampleSingleLine(true, Global.DO);
            } while (exit == false);
        }
Exemplo n.º 29
0
        public void DAQDI()
        {
            NationalInstruments.DAQmx.Task digitalReadTask = DaqSystem.Local.LoadTask("Digital_Read_Multi");
            DigitalMultiChannelReader      DI_Channel      = new DigitalMultiChannelReader(digitalReadTask.Stream);

            do
            {
                Global.DI = DI_Channel.ReadSingleSampleSingleLine();
            } while (exit == false);
        }
        public TemperatureController(double timeStep, string tempUnits, string aiChannel, AIVoltageUnits aiUnits, string aoChannel, AOVoltageUnits aoUnits) : base(timeStep)
        {
            sensor    = new TempSensor(aiChannel, aiUnits, tempUnits);
            writeTask = new NationalInstruments.DAQmx.Task();
            writer    = new AnalogSingleChannelWriter(writeTask.Stream);

            writeTask.AOChannels.CreateVoltageChannel(aoChannel, "", -10.0, 10.0, aoUnits);

            sensor.TemperatureCoefficient = 0.01; //temperature controller inherently contains a temp sensor with 0.01mV/K coefficient
        }
Exemplo n.º 31
0
        private void runMainPerformance2()
        {
            if (runningTask == null)
            {
                try
                {
                    duration = Properties.Settings.Default.jobDuration * 1000;
                    countRows = 0;
                    fault_count = 0;
                    fault_stitch = "";
                    iswelding = false;
                    current_stitch = 0;
                    samplingVariable = Convert.ToInt32(1 / ((Properties.Settings.Default.samplesPerChannelNumeric * 100) / Properties.Settings.Default.rateNumeric));

                    //this.label3.Content = Convert.ToString(Properties.Settings.Default.jobNum - 1);
                    //this.label5.Content = Convert.ToString(fault_num);

                    dataTable = new DataTable();

                    // Create a new task
                    myTask = new NationalInstruments.DAQmx.Task();

                    // Create a virtual channel
                    myTask.AIChannels.CreateVoltageChannel(Properties.Settings.Default.physicalChannel, "",
                        (AITerminalConfiguration)(-1), Convert.ToDouble(Properties.Settings.Default.minVoltage),
                        Convert.ToDouble(Properties.Settings.Default.maxVoltage), AIVoltageUnits.Volts);

                    // Configure the timing parameters
                    myTask.Timing.ConfigureSampleClock("", Properties.Settings.Default.rateNumeric,
                        SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples, 100000);

                    // Verify the Task
                    myTask.Control(TaskAction.Verify);

                    // Prepare the table for Data
                    InitializeDataTable(myTask.AIChannels, ref dataTable);

                    runningTask = myTask;
                    analogInReader = new AnalogMultiChannelReader(myTask.Stream);
                    analogCallback = new AsyncCallback(AnalogInCallback2);

                    // Use SynchronizeCallbacks to specify that the object 
                    // marshals callbacks across threads appropriately.
                    analogInReader.SynchronizeCallbacks = true;
                    analogInReader.BeginReadWaveform(Convert.ToInt32(Properties.Settings.Default.samplesPerChannelNumeric),
                        analogCallback, myTask);
                }
                catch (DaqException exception)
                {
                    // Display Errors
                    MessageBox.Show(exception.Message, "기기 연결을 확인해주세요");
                    runningTask = null;
                    myTask.Dispose();
                }
            }
        }
Exemplo n.º 32
0
 private void Button_Click_4(object sender, RoutedEventArgs e)
 {
     if (runningTask != null)
     {
         // Dispose of the task
         runningTask = null;
         myTask.Dispose();
         endTrigger = false;
         isfirst = false;
     }
     if(stopReplay == true)
     {
         stopReplay = false;
     }
     if(StopBtn.Content == "시작으로")
     {
         startBtn.Content = "시 작";
         StopBtn.Content = "정 지";
         startBtnGrid.RowDefinitions[1].Height = new GridLength(0, GridUnitType.Pixel);
     }
 }
Exemplo n.º 33
0
        private void dataToDataTable2(AnalogWaveform<double>[] sourceArray, ref DataTable dataTable)
        {
            // Iterate over channels
            int currentLineIndex = 0;
            int i = 0;
            DataRow tmprow = dataTable.NewRow();
            int lengthOfSourceArray = sourceArray.GetLength(0);

            foreach (AnalogWaveform<double> waveform in sourceArray)
            {
                for (int sample = 0; sample < waveform.Samples.Count; sample++)
                {
                    if (waveform.Samples[i].Value > triggerSensitivity && countRows <= numOfdata)
                    {
                        if (holding == false)
                        {
                            chart1.Series[0].Points.Clear();
                            chart2.Series[0].Points.Clear();
                            holding = true;
                        }
                        startTrigger = true;
                        endTrigger = true;
                    }
                    else if (countRows >= numOfdata)
                        startTrigger = false;

                    if (sample == lengthOfSourceArray)
                        break;

                    tmprow[i] = waveform.Samples[i].Value;

                }
                i++;
                currentLineIndex++;
            }
            if (lengthOfSourceArray == 1 && startTrigger == true && endTrigger == true)
            {
                countRows++;
                if (countRows % samplingVariable == 0)
                {
                    chart1.Series[0].Points.AddXY(countRows, tmprow[0]);
                }
            }
            else if (lengthOfSourceArray == 2 && startTrigger == true && endTrigger == true)
            {
                countRows++;
                if (countRows % samplingVariable == 0)
                {
                    chart1.Series[0].Points.AddXY(countRows, tmprow[0]);
                    chart2.Series[0].Points.AddXY(countRows, tmprow[1]);
                }
            }
            if (startTrigger == true)
            {
                dataTable.Rows.Add(tmprow);
            }
            else if (startTrigger == false && countRows >= numOfdata && endTrigger == true)
            {
                if (runningTask != null)
                {
                    runningTask = null;
                    dataTableToFile(ref dataTable);

                    if (fault_stitch.Length > 0)
                    {
                        uploadToDB_faultResult();
                    }

                    // Dispose of the task
                    myTask.Dispose();
                    countRows = 0;
                    endTrigger = false;
                    holding = false;
                    measure_index++;
                    runMainPerformance2();
                    Properties.Settings.Default.jobNum++;
                    this.label3.Content = Convert.ToString(Properties.Settings.Default.jobNum);
                }
            }
        }
Exemplo n.º 34
0
 private double ReadSingleDigital(NIDAQInputStream stream)
 {
     using (var t = new DAQTask())
     {
         t.DIChannels.CreateChannel(stream.PhysicalName, "", ChannelLineGrouping.OneChannelForAllLines);
         var reader = new DigitalSingleChannelReader(t.Stream);
         return reader.ReadSingleSamplePortUInt32();
     }
 }
Exemplo n.º 35
0
 private double ReadSingleAnalog(NIDAQInputStream stream)
 {
     using (var t = new DAQTask())
     {
         t.AIChannels.CreateVoltageChannel(stream.PhysicalName, "", (AITerminalConfiguration) (-1),
                                           Device.AIVoltageRanges.Min(), Device.AIVoltageRanges.Max(),
                                           AIVoltageUnits.Volts);
         var reader = new AnalogSingleChannelReader(t.Stream);
         return reader.ReadSingleSample();
     }
 }
Exemplo n.º 36
0
 private void WriteSingleAnalog(NIDAQOutputStream stream, double value)
 {
     using (var t = new DAQTask())
     {
         t.AOChannels.CreateVoltageChannel(stream.PhysicalName, "", Device.AOVoltageRanges.Min(),
                                           Device.AOVoltageRanges.Max(), AOVoltageUnits.Volts);
         var writer = new AnalogSingleChannelWriter(t.Stream);
         writer.WriteSingleSample(true, value);
     }
 }
Exemplo n.º 37
0
            public void CreateDOTask(IEnumerable<string> physicalNames)
            {
                if (_digitalOut != null)
                    throw new InvalidOperationException("Digital output task already created");

                var t = new DAQTask();
                t.DOChannels.CreateChannel(string.Join(",", physicalNames), "",
                                           ChannelLineGrouping.OneChannelForAllLines);
                _digitalOut = t;
                All.Add(t);
            }
Exemplo n.º 38
0
            public void CreateAOTask(IEnumerable<string> physicalNames, double min, double max)
            {
                if (_analogOut != null)
                    throw new InvalidOperationException("Analog output task already created");

                var t = new DAQTask();
                t.AOChannels.CreateVoltageChannel(string.Join(",", physicalNames), "", min, max, AOVoltageUnits.Volts);
                _analogOut = t;
                All.Add(t);
            }
Exemplo n.º 39
0
            public void CreateAITask(IEnumerable<string> physicalNames, double min, double max)
            {
                if (_analogIn != null)
                    throw new InvalidOperationException("Analog input task already created");

                var t = new DAQTask();
                t.AIChannels.CreateVoltageChannel(string.Join(",", physicalNames), "", (AITerminalConfiguration) (-1),
                                                  min, max, AIVoltageUnits.Volts);
                _analogIn = t;
                All.Add(t);
            }
Exemplo n.º 40
0
 private void WriteSingleDigital(NIDAQOutputStream stream, double value)
 {
     using (var t = new DAQTask())
     {
         t.DOChannels.CreateChannel(stream.PhysicalName, "", ChannelLineGrouping.OneChannelForAllLines);
         var writer = new DigitalSingleChannelWriter(t.Stream);
         writer.WriteSingleSamplePort(true, (UInt32) value);
     }
 }
Exemplo n.º 41
0
        private void firstMainPerformance(bool isref)
        {
            this.label_projectName.Content = Properties.Settings.Default.projectName;
            if (runningTask == null)
            {
                if (isref == true)
                {
                    jobNumGrid.ColumnDefinitions[1].Width = new GridLength(1, GridUnitType.Star);
                    jobNumGrid.ColumnDefinitions[0].Width = new GridLength(1, GridUnitType.Star);
                    try
                    {
                        Properties.Settings.Default.jobNum = 1;
                        duration = Properties.Settings.Default.jobDuration * 1000;
                        try
                        {
                            string conStr = "Server=localhost;Database=" + Properties.Settings.Default.databaseName + ";Uid=" + Properties.Settings.Default.databaseID + ";Pwd=" + Properties.Settings.Default.databasePwd;
                            MySqlConnection con = new MySqlConnection(conStr);

                            MySqlCommand comm = con.CreateCommand();
                            MySqlDataReader Reader;
                            con.Open();
                            comm.CommandText = "SELECT MAX(Measure_index) FROM `" + Properties.Settings.Default.databaseName + "`.`measured_data`";
                            Reader = comm.ExecuteReader();
                            Reader.Read();
                            measure_index = Convert.ToInt32(Reader[0]) + 1;
                            con.Close();

                        }
                        catch (Exception exc)
                        {
                            measure_index = 0;
                        }

                        try
                        {
                            string conStr = "Server=localhost;Database=" + Properties.Settings.Default.databaseName + ";Uid=" + Properties.Settings.Default.databaseID + ";Pwd=" + Properties.Settings.Default.databasePwd;
                            MySqlConnection con = new MySqlConnection(conStr);

                            MySqlCommand comm = con.CreateCommand();
                            MySqlDataReader Reader;

                            con.Open();
                            comm.CommandText = "SELECT COUNT(*) FROM `" + Properties.Settings.Default.databaseName + "`.`measured_data`";
                            Reader = comm.ExecuteReader();
                            Reader.Read();
                            measured_id = Convert.ToInt32(Reader[0]) + 1;
                            con.Close();
                        }
                        catch (Exception exc)
                        {
                            measured_id = 0;
                        }

                        try
                        {
                            string conStr = "Server=localhost;Database=" + Properties.Settings.Default.databaseName + ";Uid=" + Properties.Settings.Default.databaseID + ";Pwd=" + Properties.Settings.Default.databasePwd;
                            MySqlConnection con = new MySqlConnection(conStr);

                            MySqlCommand comm = con.CreateCommand();
                            MySqlDataReader Reader;

                            con.Open();
                            comm.CommandText = "SELECT COUNT(*) FROM `" + Properties.Settings.Default.databaseName + "`.`test_reference` WHERE Reference_id=" + Properties.Settings.Default.reference_id;
                            Reader = comm.ExecuteReader();
                            Reader.Read();
                            numOfdata = Convert.ToInt32(Reader[0]);
                            con.Close();

                            con.Open();

                            string commtext = "SELECT * FROM `" + Properties.Settings.Default.databaseName + "`.`test_reference` WHERE Reference_id=" + Properties.Settings.Default.reference_id;
                            MySqlDataAdapter mda = new MySqlDataAdapter(commtext, con);

                            DataSet ds = new DataSet();

                            mda.Fill(ds);
                            refDataTable = ds.Tables[0];
                            con.Close();
                        }
                        catch (Exception exc)
                        {

                        }

                        int txtFilePathIndex = Properties.Settings.Default.textFilePathSetting.LastIndexOf("\\");
                        string path = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\" + "SF LWM\\" + Properties.Settings.Default.projectName + "\\" + DateTime.Now.ToString("yyyy MM dd") + "_" + DateTime.Now.ToString("HH mm ss");
                        Properties.Settings.Default.txtFilePath = path;
                        DirectoryInfo f = new DirectoryInfo(path);
                        if (f.Exists == false)
                            f.Create();

                        countRows = 0;
                        fault_count = 0;
                        fault_stitch = "";
                        iswelding = false;
                        current_stitch = 0;
                        samplingVariable = Convert.ToInt32(1 / ((Properties.Settings.Default.samplesPerChannelNumeric * 100) / Properties.Settings.Default.rateNumeric));

                        this.label3.Content = Convert.ToString(Properties.Settings.Default.jobNum - 1);

                        dataTable = new DataTable();

                        chart1.Series[0].Points.Clear();
                        chart2.Series[0].Points.Clear();

                        int numofGraphs = Properties.Settings.Default.physicalChannelCheckedIndex.Length;

                        switch (numofGraphs)
                        {
                            case 0:
                                break;
                            case 1:
                                chart1.ChartAreas[0].AxisX.Maximum = Convert.ToDouble(numOfdata);
                                chart1.ChartAreas[0].AxisX.Minimum = 0;
                                break;
                            case 2:
                                chart1.ChartAreas[0].AxisX.Maximum = Convert.ToDouble(numOfdata);
                                chart1.ChartAreas[0].AxisX.Minimum = 0;
                                chart2.ChartAreas[0].AxisX.Maximum = Convert.ToDouble(numOfdata);
                                chart2.ChartAreas[0].AxisX.Minimum = 0;
                                break;
                        }
                        
                        // Create a new task
                        myTask = new NationalInstruments.DAQmx.Task();

                        // Create a virtual channel
                        myTask.AIChannels.CreateVoltageChannel(Properties.Settings.Default.physicalChannel, "",
                            (AITerminalConfiguration)(-1), Convert.ToDouble(Properties.Settings.Default.minVoltage),
                            Convert.ToDouble(Properties.Settings.Default.maxVoltage), AIVoltageUnits.Volts);

                        // Configure the timing parameters
                        myTask.Timing.ConfigureSampleClock("", Properties.Settings.Default.rateNumeric,
                            SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples, 100000);

                        // Verify the Task
                        myTask.Control(TaskAction.Verify);

                        // Prepare the table for Data
                        InitializeDataTable(myTask.AIChannels, ref dataTable);

                        runningTask = myTask;
                        analogInReader = new AnalogMultiChannelReader(myTask.Stream);
                        analogCallback = new AsyncCallback(AnalogInCallback);

                        // Use SynchronizeCallbacks to specify that the object 
                        // marshals callbacks across threads appropriately.
                        analogInReader.SynchronizeCallbacks = true;
                        analogInReader.BeginReadWaveform(Convert.ToInt32(Properties.Settings.Default.samplesPerChannelNumeric),
                            analogCallback, myTask);
                    }
                    catch (DaqException exception)
                    {
                        // Display Errors
                        MessageBox.Show(exception.Message, "기기 연결을 확인해주세요");
                        runningTask = null;
                        myTask.Dispose();
                    }
                }
                else
                {
                    jobNumGrid.ColumnDefinitions[1].Width = new GridLength(0);
                    jobNumGrid.ColumnDefinitions[0].Width = new GridLength(1, GridUnitType.Star);
                    try
                    {
                        Properties.Settings.Default.jobNum = 1;
                        duration = Properties.Settings.Default.jobDuration * 1000;
                        try
                        {
                            string conStr = "Server=localhost;Database=" + Properties.Settings.Default.databaseName + ";Uid=" + Properties.Settings.Default.databaseID + ";Pwd=" + Properties.Settings.Default.databasePwd;
                            MySqlConnection con = new MySqlConnection(conStr);

                            MySqlCommand comm = con.CreateCommand();
                            MySqlDataReader Reader;
                            con.Open();
                            comm.CommandText = "SELECT MAX(Measure_index) FROM `" + Properties.Settings.Default.databaseName + "`.`measured_data`";
                            Reader = comm.ExecuteReader();
                            Reader.Read();
                            measure_index = Convert.ToInt32(Reader[0]) + 1;
                            con.Close();
                        }
                        catch (Exception exc)
                        {
                            measure_index = 0;
                        }

                        try
                        {
                            string conStr = "Server=localhost;Database=" + Properties.Settings.Default.databaseName + ";Uid=" + Properties.Settings.Default.databaseID + ";Pwd=" + Properties.Settings.Default.databasePwd;
                            MySqlConnection con = new MySqlConnection(conStr);

                            MySqlCommand comm = con.CreateCommand();
                            MySqlDataReader Reader;

                            con.Open();
                            comm.CommandText = "SELECT COUNT(*) FROM `" + Properties.Settings.Default.databaseName + "`.`measured_data`";
                            Reader = comm.ExecuteReader();
                            Reader.Read();
                            measured_id = Convert.ToInt32(Reader[0]) + 1;
                            con.Close();
                        }
                        catch (Exception exc)
                        {
                            measured_id = 0;
                        }

                        numOfdata = Convert.ToInt32((Properties.Settings.Default.rateNumeric / Properties.Settings.Default.samplesPerChannelNumeric) * (duration / 1000));
                        int txtFilePathIndex = Properties.Settings.Default.textFilePathSetting.LastIndexOf("\\");
                        string path = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\" + "SF LWM\\" + Properties.Settings.Default.projectName + "\\" + DateTime.Now.ToString("yyyy MM dd") + "_" + DateTime.Now.ToString("HH mm ss");
                        Properties.Settings.Default.txtFilePath = path;
                        DirectoryInfo f = new DirectoryInfo(path);
                        if (f.Exists == false)
                            f.Create();

                        countRows = 0;
                        fault_count = 0;
                        fault_stitch = "";
                        iswelding = false;
                        current_stitch = 0;
                        samplingVariable = Convert.ToInt32(1 / ((Properties.Settings.Default.samplesPerChannelNumeric * 100) / Properties.Settings.Default.rateNumeric));

                        this.label3.Content = Convert.ToString(Properties.Settings.Default.jobNum - 1);

                        dataTable = new DataTable();

                        chart1.Series[0].Points.Clear();
                        chart2.Series[0].Points.Clear();

                        chart1.ChartAreas[0].AxisX.Maximum = Convert.ToDouble(numOfdata);
                        chart1.ChartAreas[0].AxisX.Minimum = 0;
                        chart2.ChartAreas[0].AxisX.Maximum = Convert.ToDouble(numOfdata);
                        chart2.ChartAreas[0].AxisX.Minimum = 0;

                        // Create a new task
                        myTask = new NationalInstruments.DAQmx.Task();

                        // Create a virtual channel
                        myTask.AIChannels.CreateVoltageChannel(Properties.Settings.Default.physicalChannel, "",
                            (AITerminalConfiguration)(-1), Convert.ToDouble(Properties.Settings.Default.minVoltage),
                            Convert.ToDouble(Properties.Settings.Default.maxVoltage), AIVoltageUnits.Volts);

                        // Configure the timing parameters
                        myTask.Timing.ConfigureSampleClock("", Properties.Settings.Default.rateNumeric,
                            SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples, 100000);

                        // Verify the Task
                        myTask.Control(TaskAction.Verify);

                        // Prepare the table for Data
                        InitializeDataTable(myTask.AIChannels, ref dataTable);

                        runningTask = myTask;
                        analogInReader = new AnalogMultiChannelReader(myTask.Stream);
                        analogCallback = new AsyncCallback(AnalogInCallback2);

                        // Use SynchronizeCallbacks to specify that the object 
                        // marshals callbacks across threads appropriately.
                        analogInReader.SynchronizeCallbacks = true;
                        analogInReader.BeginReadWaveform(Convert.ToInt32(Properties.Settings.Default.samplesPerChannelNumeric),
                            analogCallback, myTask);
                    }
                    catch (DaqException exception)
                    {
                        // Display Errors
                        MessageBox.Show(exception.Message, "기기 연결을 확인해주세요");
                        runningTask = null;
                        myTask.Dispose();
                    }
                }
            }
        }
Exemplo n.º 42
0
        private void AnalogInCallback2(IAsyncResult ar)
        {
            try
            {
                if (runningTask != null && runningTask == ar.AsyncState)
                {
                    // Read the available data from the channels
                    data = analogInReader.EndReadWaveform(ar);

                    analogInReader.BeginMemoryOptimizedReadWaveform(Convert.ToInt32(Properties.Settings.Default.samplesPerChannelNumeric),
                        analogCallback, myTask, data);

                    // Plot your data here
                    dataToDataTable2(data, ref dataTable);

                }
            }
            catch (DaqException exception)
            {
                // Display Errors
                MessageBox.Show(exception.Message);
                runningTask = null;
                myTask.Dispose();
            }
        }