public AnalogInputChannel(String name, String physicalChannel, AITerminalConfiguration terminalConfig, Double calibration) { this.name = name; this.physicalChannel = physicalChannel; this.terminalConfig = terminalConfig; this.calibration = calibration; }
public AnalogInputChannel(String name, String physicalChannel, AITerminalConfiguration terminalConfig, Double calibration) { this.name = name; this.physicalChannel = physicalChannel; this.terminalConfig = terminalConfig; this.calibration = calibration; }
protected void AddAnalogInputChannel( String name, String physicalChannel, AITerminalConfiguration terminalConfig ) { analogInputChannels.Add(name, new AnalogInputChannel(name, physicalChannel, terminalConfig)); }
public int ReadAnalogChannel(string lines, string name, AITerminalConfiguration config, ref double[] channelData, double min, double max) { //Create a task such that it will be disposed after //we are done using it. Task analogReadTask = new Task(); AIChannel ch = null; //channelData = new double[analogReadTask.AIChannels.Count]; //double[] channelData2 = new double[analogReadTask.AIChannels.Count]; double[] channelData2 = null; if (max == 0) { max = 10; } try { //If min > ai.Minimum And max < ai.Maximum Then //Create a virtual channel ch = analogReadTask.AIChannels.CreateVoltageChannel(lines, "", config, min, max, AIVoltageUnits.Volts); //Verify the Task analogReadTask.Control(TaskAction.Verify); //InitializeDataTable(myTask.AIChannels, DataTable) channelData = new double[analogReadTask.AIChannels.Count]; channelData2 = new double[analogReadTask.AIChannels.Count]; AnalogMultiChannelReader reader = new AnalogMultiChannelReader(analogReadTask.Stream); analogReadTask.Start(); channelData2 = reader.ReadSingleSample(); analogReadTask.Stop(); for (int i = 0; i < analogReadTask.AIChannels.Count; i++) { Debug.Print(channelData2[0].ToString("#0.00")); } //return 0; //Else //End If //Update the Acquired Sample Table //dataToDataTable(data, DataTable) //acquisitionDataGrid.DataSource = DataTable } catch (DaqException ex) { DaqError(ex.Message); } finally { //analogReadTask.Dispose(); Array.Copy(channelData2, channelData, analogReadTask.AIChannels.Count); channelData = channelData2; } return(0); }
public void StartDAQ(double a) { triggerSlope = AnalogEdgeStartTriggerSlope.Rising; sensitivityUnits = AIAccelerometerSensitivityUnits.MillivoltsPerG; terminalConfiguration = (AITerminalConfiguration)(-1); excitationSource = AIExcitationSource.Internal; inputCoupling = AICoupling.AC; myTask = new NationalInstruments.DAQmx.Task(); AIChannel aiChannel; SPmax = a; double Vmin = -5; double Vmax = 5; double sen = 100; double EVN = 0.004; double[] chan = new double[4] { 1, 1, 0, 0 }; //// indexP = 0; iii = 0; //// SW_RMSData = new StreamWriter(System.Environment.CurrentDirectory + "\\logData\\RMSData.txt"); SW_State = new StreamWriter(System.Environment.CurrentDirectory + "\\logData\\State.txt"); SW_State2 = new StreamWriter(System.Environment.CurrentDirectory + "\\logData\\State2.txt"); SW_RawData = new StreamWriter(System.Environment.CurrentDirectory + "\\logData\\RawData.txt"); for (int i = 0; i < chan.Length; i++) { if (chan[i] == 1) { aiChannel = myTask.AIChannels.CreateAccelerometerChannel("cDAQ1Mod1/ai" + Convert.ToString(i), "", terminalConfiguration, Vmin, Vmax, sen, sensitivityUnits, excitationSource, EVN, AIAccelerationUnits.G); aiChannel.Coupling = inputCoupling; } } myTask.Timing.ConfigureSampleClock("", Convert.ToDouble(12800), SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples, Convert.ToInt32(1280)); myTask.Control(TaskAction.Verify); runningTask = myTask; analogInReader = new AnalogMultiChannelReader(myTask.Stream); analogCallback = new AsyncCallback(AnalogInCallback); analogInReader.SynchronizeCallbacks = true; analogInReader.BeginReadWaveform(Convert.ToInt32(1280), analogCallback, myTask); }
public int ReadWaveformAnalogChannel(string lines, string name, AITerminalConfiguration config, ref AnalogWaveform <double>[] channelData, double min, double max, int nsamples) { //Create a task such that it will be disposed after //we are done using it. Task analogReadTask = new Task(); AIChannel ch = null; AnalogWaveform <double>[] channelData2 = new AnalogWaveform <double> [analogReadTask.AIChannels.Count]; if (max == 0) { max = 10; } if (nsamples == 0) { nsamples = -1; } try { //If min > ai.Minimum And max < ai.Maximum Then //Create a virtual channel ch = analogReadTask.AIChannels.CreateVoltageChannel(lines, "", config, min, max, AIVoltageUnits.Volts); //Verify the Task analogReadTask.Control(TaskAction.Verify); //InitializeDataTable(myTask.AIChannels, DataTable) AnalogMultiChannelReader reader = new AnalogMultiChannelReader(analogReadTask.Stream); analogReadTask.Start(); channelData2 = reader.ReadWaveform(nsamples); analogReadTask.Stop(); Debug.Print(String.Format("0x{0:X}", channelData2)); return(0); //Else //End If //Update the Acquired Sample Table //dataToDataTable(data, DataTable) //acquisitionDataGrid.DataSource = DataTable } catch (DaqException ex) { DaqError(ex.Message); } finally { analogReadTask.Dispose(); Array.Copy(channelData2, channelData, analogReadTask.AIChannels.Count); channelData = channelData2; } return(0); }
protected void AddAnalogInputChannel( String name, String physicalChannel, AITerminalConfiguration terminalConfig ) { analogInputChannels.Add(name, new AnalogInputChannel(name, physicalChannel, terminalConfig)); }
/// <summary> /// 启动AI采集任务 /// </summary> public void TryArm() { if (AIState != Status.Idle) { throw new Exception("If you want to arm, the AI state must be 'Idle'!"); } else { if (aiTask == null) { try { //autoMapper //createMap时,输出enum直接是输入enum的值,所以不对 //不createMap时,使用name匹配,是我们需要的,输出enum是对应name的值,但是必须保证输入和输出enum的name完全对应 var config = new MapperConfiguration(cfg => { }); IMapper mapper = new Mapper(config); AITerminalConfiguration niTerminalConfig = mapper.Map <AITerminalConfiguration>(TerminalConfig); //Create a task that will be disposed after it has been used aiTask = new NationalInstruments.DAQmx.Task(); //Create a virtual channel aiTask.AIChannels.CreateVoltageChannel(channel, "", niTerminalConfig, MinimumVolt, MaximumVolt, AIVoltageUnits.Volts); //Trigger type switch (AITriggerType) { //softTrigger = start directly case TriggerType.SoftTrigger: break; case TriggerType.DigitalTrigger: var digitalTriggerEdge = mapper.Map <DigitalEdgeStartTriggerEdge>(AITriggerEdge); aiTask.Triggers.StartTrigger.ConfigureDigitalEdgeTrigger(TriggerSource, digitalTriggerEdge); break; case TriggerType.AnalogTrigger: var analogTriggerEdge = mapper.Map <AnalogEdgeStartTriggerSlope>(AITriggerEdge); aiTask.Triggers.StartTrigger.ConfigureAnalogEdgeTrigger(TriggerSource, analogTriggerEdge, AnalogTriggerLevel); break; default: break; } ////Timing SampleQuantityMode sampleQuantityMode = mapper.Map <SampleQuantityMode>(AISamplesMode); var sampleClockActiveEdge = mapper.Map <SampleClockActiveEdge>(ClkActiveEdge); //经过测试,对于aiTask.Timing.ConfigureSampleClock //有限采样时,采样SamplesPerChannel 个点 //连续采样时,一直采集,直到手动停止 aiTask.Timing.ConfigureSampleClock(ClkSource, SampleRate, sampleClockActiveEdge, sampleQuantityMode, SamplesPerChannel); //Verify the Task aiTask.Control(TaskAction.Verify); //将所有通道名赋给AllActiveChannels AllActiveChannels = new List <string>(); var channelCollection = aiTask.AIChannels; int numOfChannels = channelCollection.Count; for (int currentChannelIndex = 0; currentChannelIndex < numOfChannels; currentChannelIndex++) { AllActiveChannels.Add(channelCollection[currentChannelIndex].PhysicalName); } AIState = Status.Ready; //idle -> ready OnStatusChanged(); //SoftTrigger means start the task directly //if (AITriggerType == TriggerType.SoftTrigger) //{ // AIState = Status.Running; //} //read stream reader = new AnalogMultiChannelReader(aiTask.Stream); reader.SynchronizeCallbacks = false; aiReaderCallback = new AsyncCallback(aiCallback); reader.BeginReadMultiSample(ReadSamplePerTime, aiReaderCallback, aiTask); } catch (DaqException ex) { //ex.Message goError(); } } } }
public AnalogInputChannel(String name, String physicalChannel, AITerminalConfiguration terminalConfig) { this.name = name; this.physicalChannel = physicalChannel; this.terminalConfig = terminalConfig; }
public static double ReadVoltage(string port_num, int count = 50, int milliseconds = 100, string dev_name = "Dev1", AITerminalConfiguration configuration = AITerminalConfiguration.Rse) { if (RuntimeConfiguration.Mode.HasFlag(RuntimeMode.VirtualNI)) { return(0); } dev_name = RefactorDevName(dev_name); Task task = new Task(); task.AIChannels.CreateVoltageChannel(string.Format("{0}/{1}", dev_name, port_num), "", configuration, -10, 10, AIVoltageUnits.Volts); AnalogSingleChannelReader reader = new AnalogSingleChannelReader(task.Stream); task.Start(); Thread.Sleep(milliseconds); double[] samples = reader.ReadMultiSample(count); double sample = samples.Average(); task.Stop(); task.Dispose(); return(sample); }
public AnalogInputChannel(String name, String physicalChannel, AITerminalConfiguration terminalConfig) { this.name = name; this.physicalChannel = physicalChannel; this.terminalConfig = terminalConfig; }