private void btnGetAnalogIn_Click(object sender, EventArgs e) { Task analogInTask = new Task(); AIChannel myAIChannel; myAIChannel = analogInTask.AIChannels.CreateVoltageChannel("dev1/ai0", "myAIChannel", AITerminalConfiguration.Differential, 0, 5, AIVoltageUnits.Volts); AnalogSingleChannelReader reader = new AnalogSingleChannelReader(analogInTask.Stream); double analogDataIn = reader.ReadSingleSample(); txtAnalogIn.Text = analogDataIn.ToString(); }
public void acquisitionStart() { try { // Acquisition ON if (runningTask == null) { samplingRate = 1000; samplesPerChannel = 1000; myTask = new Task(); myTask.AIChannels.CreateVoltageChannel(@"Dev1/ai0", "aiChannel", AITerminalConfiguration.Differential, -10.0, 10.0, AIVoltageUnits.Volts); myTask.Timing.ConfigureSampleClock("", samplingRate, SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples, samplesPerChannel); runningTask = myTask; reader = new AnalogSingleChannelReader(myTask.Stream); reader.SynchronizeCallbacks = true; reader.BeginMemoryOptimizedReadWaveform(samplesPerChannel, new AsyncCallback(myCallback), myTask, data); } } catch (DaqException ex) { MessageBox.Show(ex.Message); runningTask = null; myTask.Dispose(); } }
public UEDMHardwareControllerAIs(string[] name, string[] channelName) { if (!Environs.Debug) { readAI11 = new Task("Read AI11 -" + name[0]); ((AnalogInputChannel)Environs.Hardware.AnalogInputChannels[channelName[0]]).AddToTask(readAI11, VOLTAGE_LOWER_BOUND, VOLTAGE_UPPER_BOUND); AI11Reader = new AnalogSingleChannelReader(readAI11.Stream); readAI11.Control(TaskAction.Verify); readAI12 = new Task("Read AI12 -" + name[1]); ((AnalogInputChannel)Environs.Hardware.AnalogInputChannels[channelName[1]]).AddToTask(readAI12, VOLTAGE_LOWER_BOUND, VOLTAGE_UPPER_BOUND); AI12Reader = new AnalogSingleChannelReader(readAI12.Stream); readAI12.Control(TaskAction.Verify); readAI13 = new Task("Read AI13 -" + name[2]); ((AnalogInputChannel)Environs.Hardware.AnalogInputChannels[channelName[2]]).AddToTask(readAI13, VOLTAGE_LOWER_BOUND, VOLTAGE_UPPER_BOUND); AI13Reader = new AnalogSingleChannelReader(readAI13.Stream); readAI13.Control(TaskAction.Verify); readAI14 = new Task("Read AI14 -" + name[3]); ((AnalogInputChannel)Environs.Hardware.AnalogInputChannels[channelName[3]]).AddToTask(readAI14, VOLTAGE_LOWER_BOUND, VOLTAGE_UPPER_BOUND); AI14Reader = new AnalogSingleChannelReader(readAI14.Stream); readAI14.Control(TaskAction.Verify); readAI15 = new Task("Read AI15 -" + name[4]); ((AnalogInputChannel)Environs.Hardware.AnalogInputChannels[channelName[4]]).AddToTask(readAI15, VOLTAGE_LOWER_BOUND, VOLTAGE_UPPER_BOUND); AI15Reader = new AnalogSingleChannelReader(readAI15.Stream); readAI15.Control(TaskAction.Verify); } }
public void Read() { try { string[] channelNameList = DaqSystem.Local.GetPhysicalChannels(PhysicalChannelTypes.AI, PhysicalChannelAccess.External); if (channelNameList.Length > 0) { Task task = new Task(); task.AIChannels.CreateVoltageChannel(channelNameList[0], "Voltage", AITerminalConfiguration.Differential, 0.0, 10.0, AIVoltageUnits.Volts); task.Timing.ConfigureSampleClock("", 100000, SampleClockActiveEdge.Rising, SampleQuantityMode.FiniteSamples); task.Control(TaskAction.Verify); AnalogSingleChannelReader airead = new AnalogSingleChannelReader(task.Stream); AnalogWaveform <double> waveform; for (int i = 0; i < repeat; i++) { waveform = airead.ReadWaveform(sampleRate); datalist.AddRange(waveform.GetRawData()); Console.Out.WriteLine("Acquire " + i + "th try"); } StreamWriter writer = new StreamWriter(File.Open("ai.txt", FileMode.Create)); int c = 0; foreach (double d in datalist) { writer.WriteLine(String.Format("{0} {1}", c, d)); c++; } writer.Close(); } } catch (DaqException e) { Console.Out.WriteLine(e.Message); } }
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); }
///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); }
private const double VOLTAGE_UPPER_BOUND = 1.65; // volts public SiliconDiodeTemperatureMonitors(string[] name, string[] channelName) { if (!Environs.Debug) { readCellTemperatureTask = new Task("Read cell temperature -" + name[0]); ((AnalogInputChannel)Environs.Hardware.AnalogInputChannels[channelName[0]]).AddToTask(readCellTemperatureTask, VOLTAGE_LOWER_BOUND, VOLTAGE_UPPER_BOUND); cellTemperatureReader = new AnalogSingleChannelReader(readCellTemperatureTask.Stream); readCellTemperatureTask.Control(TaskAction.Verify); readS1TemperatureTask = new Task("Read S1 temperature -" + name[1]); ((AnalogInputChannel)Environs.Hardware.AnalogInputChannels[channelName[1]]).AddToTask(readS1TemperatureTask, VOLTAGE_LOWER_BOUND, VOLTAGE_UPPER_BOUND); s1TemperatureReader = new AnalogSingleChannelReader(readS1TemperatureTask.Stream); readS1TemperatureTask.Control(TaskAction.Verify); readS2TemperatureTask = new Task("Read S2 temperature -" + name[2]); ((AnalogInputChannel)Environs.Hardware.AnalogInputChannels[channelName[2]]).AddToTask(readS2TemperatureTask, VOLTAGE_LOWER_BOUND, VOLTAGE_UPPER_BOUND); s2TemperatureReader = new AnalogSingleChannelReader(readS2TemperatureTask.Stream); readS2TemperatureTask.Control(TaskAction.Verify); readSF6TemperatureTask = new Task("Read SF6 temperature -" + name[3]); ((AnalogInputChannel)Environs.Hardware.AnalogInputChannels[channelName[3]]).AddToTask(readSF6TemperatureTask, VOLTAGE_LOWER_BOUND, VOLTAGE_UPPER_BOUND); sf6TemperatureReader = new AnalogSingleChannelReader(readSF6TemperatureTask.Stream); readSF6TemperatureTask.Control(TaskAction.Verify); } }
public void Read() { try { string[] channelNameList = DaqSystem.Local.GetPhysicalChannels(PhysicalChannelTypes.AI, PhysicalChannelAccess.External); if (channelNameList.Length > 0) { Task task = new Task(); task.AIChannels.CreateVoltageChannel(channelNameList[0], "Voltage", AITerminalConfiguration.Differential, 0.0, 10.0, AIVoltageUnits.Volts); task.Timing.ConfigureSampleClock("", 100000, SampleClockActiveEdge.Rising, SampleQuantityMode.FiniteSamples); task.Control(TaskAction.Verify); AnalogSingleChannelReader airead = new AnalogSingleChannelReader(task.Stream); AnalogWaveform<double> waveform; for(int i=0;i<repeat;i++){ waveform = airead.ReadWaveform(sampleRate); datalist.AddRange(waveform.GetRawData()); Console.Out.WriteLine("Acquire " + i + "th try"); } StreamWriter writer = new StreamWriter(File.Open("ai.txt", FileMode.Create)); int c = 0; foreach (double d in datalist) { writer.WriteLine(String.Format("{0} {1}",c,d)); c++; } writer.Close(); } } catch (DaqException e) { Console.Out.WriteLine(e.Message); } }
public void Initialize() { // counterTask = new Task(""); // this.counterTask.CIChannels.CreateFrequencyChannel( // currentLeakageCounterChannel.PhysicalChannel, // "", // 0, // 150000, // CIFrequencyStartingEdge.Rising, // CIFrequencyMeasurementMethod.HighFrequencyTwoCounter, // // the units of measurement time are not specified anywhere in the docs :-( // measurementTime, // // this has to be more than four to stop NIDAQ crashing, even though it is not used in this mode! // 100, // CIFrequencyUnits.Hertz // ); // counterTask.Stream.Timeout = (int)(10.1 * 1000 * measurementTime); // leakageReader = new CounterReader(counterTask.Stream); monitorTask = new Task("EDMHCIn" + leakageChannel); ((AnalogInputChannel)Environs.Hardware.AnalogInputChannels[leakageChannel]).AddToTask( monitorTask, 0, 10 ); monitorTask.Control(TaskAction.Verify); leakageReader = new AnalogSingleChannelReader(monitorTask.Stream); }
public void UpdateMonitoring() { AnalogSingleChannelReader reader3 = new AnalogSingleChannelReader(voltageReferenceTask.Stream); double Vref = reader3.ReadSingleSample(); AnalogSingleChannelReader reader1 = new AnalogSingleChannelReader(pressureMonitorTask.Stream); double analogDataIn1 = reader1.ReadSingleSample(); window.monitorPressureSourceChamber.Text = VoltagePressureConversion(analogDataIn1).ToString("E02", CultureInfo.InvariantCulture); AnalogSingleChannelReader reader2 = new AnalogSingleChannelReader(roughVacuumTask.Stream); double analogDataIn2 = reader2.ReadSingleSample(); window.monitorRoughVacuum.Text = VoltageRoughVacuumConversion(analogDataIn2).ToString("E02", CultureInfo.InvariantCulture); AnalogSingleChannelReader reader4 = new AnalogSingleChannelReader(thermistor30KPlateTask.Stream); double analogDataIn4 = reader4.ReadSingleSample(); window.monitor10KTherm30KPlate.Text = VoltageResistanceConversion(analogDataIn4, Vref).ToString("E04", CultureInfo.InvariantCulture); AnalogSingleChannelReader reader5 = new AnalogSingleChannelReader(shieldTask.Stream); double analogDataIn5 = reader5.ReadSingleSample(); window.monitorShield.Text = VoltageResistanceConversion(analogDataIn5, Vref).ToString("E04", CultureInfo.InvariantCulture); AnalogSingleChannelReader reader6 = new AnalogSingleChannelReader(cellTask.Stream); double analogDataIn6 = reader6.ReadSingleSample(); window.monitorColdPlate.Text = VoltageResistanceConversion(analogDataIn6, Vref).ToString("E04", CultureInfo.InvariantCulture); }
public override void TryInitialize() { try { _daqTask.AIChannels.CreateVoltageChannel(PhysicalChannelName, nameToAssignChannel: PhysicalChannelName, ReaderSpecs.TerminalConfig, ReaderSpecs.Range.MinimumValue, ReaderSpecs.Range.MaximumValue, units); _daqTask.Timing.ConfigureSampleClock("", ReaderSpecs.TimingConfig.SampleRate, ReaderSpecs.TimingConfig.ActiveEdge, SampleQuantityMode.FiniteSamples, ReaderSpecs.TimingConfig.SampleSize); DaqStream stream = _daqTask.Stream ?? throw new DaqException(Constants.ErrorMessages.INVALID_STREAM); _reader = new AnalogSingleChannelReader(stream); this.IsInitialized = true; } catch (DaqException ex) { // Log Exception Stop(ex); } }
public Lesker903Gauge(string name, string channelName) { readPressureTask = new Task("Read pressure -" + name); ((AnalogInputChannel)Environs.Hardware.AnalogInputChannels[channelName]).AddToTask(readPressureTask, VOLTAGE_LOWER_BOUND, VOLTAGE_UPPER_BOUND); pressureReader = new AnalogSingleChannelReader(readPressureTask.Stream); readPressureTask.Control(TaskAction.Verify); }
private void Timer_Tick(object sender, EventArgs e) { Task temperatureTask = new Task(); AIChannel myAIChannel; myAIChannel = temperatureTask.AIChannels.CreateThermocoupleChannel ( "Dev1/ai0", "Temperature", -40, 120, AIThermocoupleType.J, AITemperatureUnits.DegreesC, 25 ); AnalogSingleChannelReader reader = new AnalogSingleChannelReader(temperatureTask.Stream); double analogDataIn = reader.ReadSingleSample(); analogDataIn = Math.Round(analogDataIn, 2); myTemperature = analogDataIn; // LOOK OUT!!!! A test to se if ThermoCouple is connected is needed! The Boolean value IsConnected need to be false if so. }
public LeyboldPTR225Gauge(string name, string channelName) { readPressureTask = new Task("Read pressure -" + name); ((AnalogInputChannel)Environs.Hardware.AnalogInputChannels[channelName]).AddToTask(readPressureTask, VOLTAGE_LOWER_BOUND, VOLTAGE_UPPER_BOUND); pressureReader = new AnalogSingleChannelReader(readPressureTask.Stream); readPressureTask.Control(TaskAction.Verify); }
public int OpenChannel(string portLine, string portName) { // Create a new analog inputChannel called "Ainport0" try { analogIn.AIChannels.CreateVoltageChannel(portLine, // The physical name of the channel portName, // The given name to the channel AITerminalConfiguration.Rse, //Input type (Differential, RSE, NRSE) -10.0, 10.0, //Input Voltage Range AIVoltageUnits.Volts); //Input unit //Configure timing specs analogIn.Timing.ConfigureSampleClock("", //external clock source line, "" for internal clock 10.0, // rate of internal/external clock (10hz) SampleClockActiveEdge.Rising, // acquisition on rising or falling edge of ticks SampleQuantityMode.FiniteSamples, // continous or finite samples samplesPerChannel); // number of finite samples to acquire or used for buffer size if continous // Initialise the single analog input channel reader reader = new AnalogSingleChannelReader(analogIn.Stream); return(1); //successful } catch (Exception) { return(0); } }
/// <summary> /// Starts laser read and write tasks /// </summary> static void StartLaserTasks() { _laserWriteTask = new System.Threading.Tasks.Task(() => { Task writeTask = new Task("LaserWrite"); double[] firstSamples = LaserFunction(0, _rate); writeTask.AOChannels.CreateVoltageChannel("Dev2/AO2", "", 0, 10, AOVoltageUnits.Volts); writeTask.Timing.ConfigureSampleClock("", _rate, SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples); writeTask.Stream.WriteRegenerationMode = WriteRegenerationMode.DoNotAllowRegeneration; AnalogSingleChannelWriter dataWriter = new AnalogSingleChannelWriter(writeTask.Stream); dataWriter.WriteMultiSample(false, firstSamples); writeTask.Start(); long start_sample = _rate; while (!_writeStop.WaitOne(100)) { double[] samples = LaserFunction(start_sample, _rate); if (samples == null) { break; } dataWriter.WriteMultiSample(false, samples); start_sample += _rate; } writeTask.Dispose(); Task resetTask = new Task("LaserReset"); resetTask.AOChannels.CreateVoltageChannel("Dev2/AO2", "", 0, 10, AOVoltageUnits.Volts); AnalogSingleChannelWriter resetWriter = new AnalogSingleChannelWriter(resetTask.Stream); resetWriter.WriteSingleSample(true, 0); resetTask.Dispose(); }); _laserReadTask = new System.Threading.Tasks.Task(() => { Task read_task = new Task("laserRead"); read_task.AIChannels.CreateVoltageChannel("Dev2/ai16", "Laser", AITerminalConfiguration.Differential, -10, 10, AIVoltageUnits.Volts); read_task.Timing.ConfigureSampleClock("", _rate, SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples); read_task.Start(); AnalogSingleChannelReader laser_reader = new AnalogSingleChannelReader(read_task.Stream); while (!_readStop.WaitOne(10)) { var nsamples = read_task.Stream.AvailableSamplesPerChannel; if (nsamples >= 10) { double[] read = laser_reader.ReadMultiSample((int)nsamples); lock (_laser_aiv_lock) { foreach (double d in read) { //Simple exponential smoother _laser_aiv = 0.9 * _laser_aiv + 0.1 * d; } } } } read_task.Dispose(); }); _laserWriteTask.Start(); _laserReadTask.Start(); }
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); }
public SourceTabController() { InitReadTimer(); sourceTempReader = CreateAnalogInputReader("4Kthermistor"); cryoWriter = CreateDigitalOutputWriter("cryoCooler"); heaterWriter = CreateDigitalOutputWriter("sourceHeater"); }
public BristolWavemeterApplication() { InitializeComponent(); MainThread = this; //int dllVersion = CLGetDllVersion(); // had to change the target system to x64 (from x86) to make this work, weird (?) HandleBristolWavemeter = CLOpenUSBSerialDevice(Properties.Settings.Default.WavemeterCOMPort); // returns a handle to the Bristol Wavemeter (CL device) bgwGetWL.WorkerSupportsCancellation = true; bgwGetWL.WorkerReportsProgress = true; TaskAI = new Task(); TaskAI.AIChannels.CreateVoltageChannel(string.Format("dev1/ai{0}", Properties.Settings.Default.AnalogInputPiezo), "PiezoVoltageAI", AITerminalConfiguration.Differential, -3, 3, AIVoltageUnits.Volts); ReaderAI = new AnalogSingleChannelReader(TaskAI.Stream); TaskAO = new Task(); TaskAO.AOChannels.CreateVoltageChannel(string.Format("dev1/ao{0}", Properties.Settings.Default.AnalogOutputPiezo), "PiezoVoltageAO", -3, 3, AOVoltageUnits.Volts); //TaskAO.Timing.ConfigureSampleClock("", sampleRate, SampleClockActiveEdge.Rising, SampleQuantityMode.FiniteSamples, numberOfSamples); // I'm asking for 100 Hz, it is 1000 Hz WriterAO = new AnalogSingleChannelWriter(TaskAO.Stream); // remoting server ServiceHost Host; try { Host = new ServiceHost(typeof(WavemeterMATLABObject), new Uri[] { new Uri(String.Format("net.tcp://localhost:{0}", Properties.Settings.Default.ServerPort)) }); Host.AddServiceEndpoint(typeof(IWavemeterMATLABObject), new NetTcpBinding(SecurityMode.None), Properties.Settings.Default.ServerName); Host.Open(); } catch (Exception e) { MessageBox.Show(this, e.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } //Data series for the chart series1 = new System.Windows.Forms.DataVisualization.Charting.Series { Name = "Series1", Color = System.Drawing.Color.Teal, IsVisibleInLegend = false, IsXValueIndexed = true, ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline }; chart1.Series.Add(series1); chart1.ChartAreas[0].AxisY.Maximum = 1570; chart1.ChartAreas[0].AxisY.Minimum = 1520; chart1.ChartAreas[0].AxisY.LabelStyle.Format = "###0.0000"; //Setup the PID controller and interface LaserLockPID = new WavemeterPID(); LaserLockPID.G = Properties.Settings.Default.G; numericUpDownPIDGain.Value = Convert.ToDecimal(Properties.Settings.Default.G); LaserLockPID.Kp = Properties.Settings.Default.Kp; numericUpDownPIDProportional.Value = Convert.ToDecimal(Properties.Settings.Default.Kp); LaserLockPID.Kd = Properties.Settings.Default.Kd; numericUpDownPIDDerivative.Value = Convert.ToDecimal(Properties.Settings.Default.Kd); LaserLockPID.Ki = Properties.Settings.Default.Ki; numericUpDownPIDIntegral.Value = Convert.ToDecimal(Properties.Settings.Default.Ki); //System.Media.SoundPlayer mySoundPlayer = new System.Media.SoundPlayer(LINQS.BristolWavemeter.Properties.Resources.LINQStartupSound); //mySoundPlayer.Play(); }
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); } }
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); }
public double GetValue() { Task analogInTask = new Task(); AIChannel myAIChannel; myAIChannel = analogInTask.AIChannels.CreateVoltageChannel("dev31/ai0", "myAIChannel", AITerminalConfiguration.Rse, 0, 5, AIVoltageUnits.Volts); AnalogSingleChannelReader reader = new AnalogSingleChannelReader(analogInTask.Stream); double analogDataIn = reader.ReadSingleSample(); return(analogDataIn); }
public void OpenChannel(string channel, string channelName) { //create a new analog inputchannel called "Ainport#" analogIn.AIChannels.CreateVoltageChannel(channel, // the physical name of the channel channelName, // the given name to the channel AITerminalConfiguration.Rse, // input type (Differential, RSE, NRSE) -10.0, 10.0, // Input voltage range AIVoltageUnits.Volts); // input unit // initiliase the single analog input channel reader reader = new AnalogSingleChannelReader(analogIn.Stream); }
public DaqAi(string channel) { _myAiChannel = _analogInTask.AIChannels.CreateVoltageChannel( "dev3/" + channel, "myAIChannel", AITerminalConfiguration.Differential, 0, 5, AIVoltageUnits.Volts ); _reader = new AnalogSingleChannelReader(_analogInTask.Stream); }
/// <summary> /// Indlæser en enkelt sample fra NI-DAQ i volt /// </summary> /// <returns> /// Returnerer den indlæste spænding /// </returns> public double indlæsKalibreringsSpænding() { NationalInstruments.DAQmx.Task analogInTask = new NationalInstruments.DAQmx.Task(); AIChannel myAIChannel; myAIChannel = analogInTask.AIChannels.CreateVoltageChannel("Dev1/ai0", "myAIChannel", AITerminalConfiguration.Differential, 0, 5, AIVoltageUnits.Volts); AnalogSingleChannelReader reader = new AnalogSingleChannelReader(analogInTask.Stream); return(reader.ReadSingleSample()); }
private static double ReadAnalog(Task task) { if (disposed) { return(0); } AnalogSingleChannelReader reader = new AnalogSingleChannelReader(task.Stream); double sample = reader.ReadSingleSample(); return(sample); }
private double analogIn3() //2D signal { Task analogInTask = new Task(); AIChannel myAIChannel; myAIChannel = analogInTask.AIChannels.CreateVoltageChannel("dev1/ai1", "myAIChannel", AITerminalConfiguration.Differential, 0, 5, AIVoltageUnits.Volts); AnalogSingleChannelReader reader = new AnalogSingleChannelReader(analogInTask.Stream); double analogDataIn = reader.ReadSingleSample(); return(analogDataIn); }
private double getReferenceTemp() { NationalInstruments.DAQmx.Task analogInTask = new NationalInstruments.DAQmx.Task(); AIChannel myAIChannel; //myAIChannel = analogInTask.AIChannels.CreateVoltageChannel(comboBox1.Text, "myAIChannel", AITerminalConfiguration.Differential, 0, 10, AIVoltageUnits.Volts); myAIChannel = analogInTask.AIChannels.CreateThermocoupleChannel(comboBox1.Text, "myAIChannel", 0, 60, AIThermocoupleType.J, AITemperatureUnits.DegreesC); // (comboBox1.Text, "myAIChannel", AITerminalConfiguration.Differential, 0, 10, AIVoltageUnits.Volts); AnalogSingleChannelReader reader = new AnalogSingleChannelReader(analogInTask.Stream); double analogDataIn = reader.ReadSingleSample(); txtRefTempLastSampleVal.Text = analogDataIn.ToString("0.00"); return(analogDataIn); }
public double ReadTemperature() { var niTask = new NationalInstruments.DAQmx.Task(); AIChannel analogInput = niTask.AIChannels.CreateVoltageChannel( "Dev8/ai0", "Temperature", AITerminalConfiguration.Rse, 1, 5, AIVoltageUnits.Volts ); var reader = new AnalogSingleChannelReader(niTask.Stream); return(PlantCalculations.CalcTemperature(reader.ReadSingleSample())); }
private void button1_Click(object sender, EventArgs e) { DateTime start = DateTime.Now; Task analogInTask = new Task(); AIChannel myAIChannel; myAIChannel = analogInTask.AIChannels.CreateVoltageChannel("dev1/ai0", "myAIChannel", AITerminalConfiguration.Differential, 0, 5, AIVoltageUnits.Volts); AnalogSingleChannelReader reader = new AnalogSingleChannelReader(analogInTask.Stream); double[] test1 = reader.ReadMultiSample(-1); double procedureTime = System.DateTime.Now.Subtract(start).TotalMilliseconds; textBox1.Text = procedureTime.ToString(); }
public double GetCurrentGain() { var niTask = new NationalInstruments.DAQmx.Task(); AIChannel analogInput = niTask.AIChannels.CreateVoltageChannel( "Dev9/ai0", "Gain", AITerminalConfiguration.Differential, 0, 5, AIVoltageUnits.Volts ); var reader = new AnalogSingleChannelReader(niTask.Stream); return(reader.ReadSingleSample()); }
static public double Read_SingelAi(uint linenum) { string ai_port_desc = get_PhysicalAIChannel((int)linenum); using (Task analogReaderTask = new Task()) { // Create channel and name it. string linestr = string.Format("{0}", ai_port_desc); string name = string.Format("ai{0}", linenum); analogReaderTask.AIChannels.CreateVoltageChannel(linestr, name, AITerminalConfiguration.Rse, 0, 5, AIVoltageUnits.Volts); AnalogSingleChannelReader reader = new AnalogSingleChannelReader(analogReaderTask.Stream); double value = reader.ReadSingleSample(); return(value); } }
/// <summary> /// Включение постоянной генерации сигнала. Чтение и контроль ошибок при этом производится в CALLBACK. Для завершения генерации используй метод StopDAQGeneration() /// </summary> public void RunDAQGeneration() { 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(AnalogInCallback); reader = new AnalogSingleChannelReader(inputTask.Stream); reader.SynchronizeCallbacks = true; //reader.BeginReadMultiSample(iInputOutputSamples, inputCallback, inputTask); reader.BeginReadWaveform(iInputOutputSamples, inputCallback, inputTask); //statusDAQtimer.Enabled = true; } catch (Exception ex) { StopTask(); WarningDAQUpdate?.Invoke(ex.Message); } }
/// <summary> /// Tester om Måleenhet er koblet til maskinen. /// </summary> /// <returns>bool som er true dersom tilkoblet, false i motsatt tilfelle.</returns> public static bool connected() { bool connected; // Hvis sensor allerede er i bruk tolkes dette som at sensor er koblet til å i øyeblikket i bruk av tempmåling prosessen. // Dermed avsluttes metoden her og sier ifra til GUI at sensor (sansynelighvis er koblet til). // Dette gjøres for å unngå dobbelt sensorbruk som forårsaker feiltolkning i GUI og tempmåling prosessen. if (Program.sensorInUse) return true; else { Task checkConnection = new Task(); // Tester om programmet klarer å opprette en AIChannel, kun for å se om enhet er koblet til. try { // Dette er en u-elegant måte å teste tilkobling til sensor på. // Men det er desverre den måten vi har tid og know-how til å implementere. // Følgende linje er ikke pålitelig nok til dette bruket. Noenganger kaster ikke dette en exception av en eller annen obskur årsak... checkConnection.AIChannels.CreateThermocoupleChannel("Dev1/ai0", "Temperature", 0, 100, AIThermocoupleType.J, AITemperatureUnits.DegreesC); // ...Derfor må dette gjøres for å garantere en exception dersom ikke sensor er koblet til. AnalogSingleChannelReader reader = new AnalogSingleChannelReader(checkConnection.Stream); reader.ReadSingleSample(); // Lagrer ikke svar fra sensor, fordi det er denne linjen som kaster exception. connected = true; } catch (Exception) { // Bruker ikke error. connected = false; } finally { checkConnection.Dispose(); } return connected; } }
private double ReadAnalogInput(Task task, double sampleRate, int numOfSamples) { //Configure the timing parameters of the task task.Timing.ConfigureSampleClock("", sampleRate, SampleClockActiveEdge.Rising, SampleQuantityMode.FiniteSamples, numOfSamples); //Read in multiple samples AnalogSingleChannelReader reader = new AnalogSingleChannelReader(task.Stream); double[] valArray = reader.ReadMultiSample(numOfSamples); task.Control(TaskAction.Unreserve); //Calculate the average of the samples double sum = 0; for (int j = 0; j < numOfSamples; j++) { sum = sum + valArray[j]; } double val = sum / numOfSamples; return val; }
//-------CITANIE ANALOG------ /// <summary> /// cita hodnotu z Tlakomeru pomocou analogoveho vstupu. /// </summary> /// <returns></returns> public double readTlakomerPR4000() { Task analogInTask = new Task(); AIChannel myAIChannel; myAIChannel = analogInTask.AIChannels.CreateVoltageChannel( prevodnikId + "/ai1", "myAIChannel", AITerminalConfiguration.Differential, 0, 5, AIVoltageUnits.Volts ); AnalogSingleChannelReader reader = new AnalogSingleChannelReader(analogInTask.Stream); double analogDataIn = reader.ReadSingleSample(); return analogDataIn; }
public double ReadAnalogInput(string channelName, bool useCalibration) { AnalogSingleChannelReader reader = new AnalogSingleChannelReader(analogTasks[channelName].Stream); double val = reader.ReadSingleSample(); analogTasks[channelName].Control(TaskAction.Unreserve); if (useCalibration) { try { return ((Calibration)calibrations[channelName]).Convert(val); } catch { MessageBox.Show("Calibration error"); return val; } } else { return val; } }
/// <summary> /// Gjør en temperatur måling. Dersom det oppstår en feil returnerer metoden 999 og skriver til logg. /// </summary> /// <returns>Returnerer temperaturen i double. </returns> public static double temp() { double analogData; Task temperatureTask = new Task(); try { temperatureTask.AIChannels.CreateThermocoupleChannel("Dev1/ai0", "Temperature", 0, 100, AIThermocoupleType.J, AITemperatureUnits.DegreesC); AnalogSingleChannelReader reader = new AnalogSingleChannelReader(temperatureTask.Stream); analogData = reader.ReadSingleSample(); } catch (Exception e) { Logger.Error(e, module); //Logger feil. analogData = 999; //999 vil være en "feilkode" } finally { temperatureTask.Dispose(); } return analogData; }
// overload for reading multiple samples public double ReadAnalogInput(string channel, double sampleRate, int numOfSamples, bool useCalibration) { //Configure the timing parameters of the task analogTasks[channel].Timing.ConfigureSampleClock("", sampleRate, SampleClockActiveEdge.Rising, SampleQuantityMode.FiniteSamples, numOfSamples); //Read in multiple samples AnalogSingleChannelReader reader = new AnalogSingleChannelReader(analogTasks[channel].Stream); double[] valArray = reader.ReadMultiSample(numOfSamples); analogTasks[channel].Control(TaskAction.Unreserve); //Calculate the average of the samples double sum = 0; for (int j = 0; j < numOfSamples; j++) { sum = sum + valArray[j]; } double val = sum / numOfSamples; if (useCalibration) { try { return ((Calibration)calibrations[channel]).Convert(val); } catch { MessageBox.Show("Calibration error"); return val; } } else { return val; } }
public void Start() { proportionalGain = 0; integralGain = 0; // derivativeGain = 0; ui = new MainForm(); ui.controller = this; // get access to ScanMaster and the DecelerationHardwareController RemotingHelper.ConnectScanMaster(); RemotingHelper.ConnectDecelerationHardwareControl(); scanMaster = new ScanMaster.Controller(); hardwareControl = new DecelerationHardwareControl.Controller(); fitter = new DAQ.Analyze.GaussianFitter(); if (!Environs.Debug) { outputTask = new Task("LaserControllerOutput"); laserChannel = (AnalogOutputChannel)Environs.Hardware.AnalogOutputChannels["laser"]; laserChannel.AddToTask(outputTask, -10, 10); outputTask.Control(TaskAction.Verify); laserWriter = new AnalogSingleChannelWriter(outputTask.Stream); inputTask = new Task("LaserControllerInput"); cavityChannel = (AnalogInputChannel)Environs.Hardware.AnalogInputChannels["lockcavity"]; cavityChannel.AddToTask(inputTask, -10, 10); cavityReader = new AnalogSingleChannelReader(inputTask.Stream); inputrefTask = new Task("ReferenceLaserControllerInput"); cavityrefChannel = (AnalogInputChannel)Environs.Hardware.AnalogInputChannels["refcavity"]; cavityrefChannel.AddToTask(inputrefTask, -10, 10); cavityrefReader = new AnalogSingleChannelReader(inputrefTask.Stream); } timerDelegate = new TimerCallback(TalkToHardwareControl); hardwareControlTimer = new System.Threading.Timer(timerDelegate, null, 5000, HARDWARE_CONTROL_TALK_PERIOD); Application.Run(ui); }
private double ReadAnalogInput(Task task) { AnalogSingleChannelReader reader = new AnalogSingleChannelReader(task.Stream); double val = reader.ReadSingleSample(); task.Control(TaskAction.Unreserve); return val; }
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(); } }
public void Start() { flowChannel.AddToTask(outputTask, 0, 5); outputTask.Control(TaskAction.Verify); flowWriter = new AnalogSingleChannelWriter(outputTask.Stream); flowmeterChannel.AddToTask(inputTask, 0, 5); inputTask.Control(TaskAction.Verify); flowReader = new AnalogSingleChannelReader(inputTask.Stream); // make the control window window = new ControlWindow(); window.controller = this; Application.Run(window); }
public void UpdateMonitoring() { AnalogSingleChannelReader reader3 = new AnalogSingleChannelReader(voltageReferenceTask.Stream); double Vref = reader3.ReadSingleSample(); AnalogSingleChannelReader reader1 = new AnalogSingleChannelReader(pressureMonitorTask.Stream); double analogDataIn1 = reader1.ReadSingleSample(); window.monitorPressureSourceChamber.Text = VoltagePressureConversion(analogDataIn1).ToString("E02",CultureInfo.InvariantCulture); AnalogSingleChannelReader reader2 = new AnalogSingleChannelReader(roughVacuumTask.Stream); double analogDataIn2 = reader2.ReadSingleSample(); window.monitorRoughVacuum.Text = VoltageRoughVacuumConversion(analogDataIn2).ToString("E02", CultureInfo.InvariantCulture); AnalogSingleChannelReader reader4 = new AnalogSingleChannelReader(thermistor30KPlateTask.Stream); double analogDataIn4 = reader4.ReadSingleSample(); window.monitor10KTherm30KPlate.Text = VoltageResistanceConversion(analogDataIn4, Vref).ToString("E04", CultureInfo.InvariantCulture); AnalogSingleChannelReader reader5 = new AnalogSingleChannelReader(shieldTask.Stream); double analogDataIn5 = reader5.ReadSingleSample(); window.monitorShield.Text = VoltageResistanceConversion(analogDataIn5, Vref).ToString("E04", CultureInfo.InvariantCulture); AnalogSingleChannelReader reader6 = new AnalogSingleChannelReader(cellTask.Stream); double analogDataIn6 = reader6.ReadSingleSample(); window.monitorColdPlate.Text = VoltageResistanceConversion(analogDataIn6, Vref).ToString("E04", CultureInfo.InvariantCulture); }
internal void getImpedance(double startFreq, double stopFreq, double numPeriods, bool isCurrentControlled, int startChannel, int numChannels, double RCurr, double RMeas, double RGain, double commandVoltage, bool useBandpassFilter, bool useMatchedFilter) { this.numPeriods = numPeriods; this.startChannel = startChannel; this.numChannels = numChannels; this.RCurr = RCurr; this.RGain = RGain; this.RMeas = RMeas; this.commandVoltage = commandVoltage; this.isCurrentControlled = isCurrentControlled; this.useBandpassFilter = useBandpassFilter; this.useMatchedFilter = useMatchedFilter; //StartChannel is 1-based if (startFreq == stopFreq) freqs = new double[1]; else if ((stopFreq/startFreq)%RESOLUTION == 0) //stopFreq is a RESOLUTION multiple of startFreq freqs = new double[Convert.ToInt32(Math.Floor(Math.Log(stopFreq / startFreq) / Math.Log(RESOLUTION))) + 1]; //This determines the number of frequencies counting by doublings else //not an exact multiple freqs = new double[Convert.ToInt32(Math.Floor(Math.Log(stopFreq / startFreq) / Math.Log(RESOLUTION))) + 2]; //This determines the number of frequencies counting by doublings //Populate freqs vector freqs[0] = startFreq; for (int i = 1; i < freqs.GetLength(0); ++i) freqs[i] = freqs[i - 1] * RESOLUTION; if (freqs[freqs.Length - 1] > stopFreq) freqs[freqs.Length - 1] = stopFreq; //Setup tasks impedanceRecord = new Task("Impedance Analog Input Task"); stimDigitalTask = new Task("stimDigitalTask_impedance"); stimAnalogTask = new Task("stimAnalogTask_impedance"); //Choose appropriate input for current/voltage-controlled stimulation String inputChannel = (isCurrentControlled ? "/ai2" : "/ai3"); //if (isCurrentControlled) inputChannel = "/ai2"; //else inputChannel = "/ai3"; impedanceRecord.AIChannels.CreateVoltageChannel(Properties.Settings.Default.ImpedanceDevice + inputChannel, "", AITerminalConfiguration.Rse, -5.0, 5.0, AIVoltageUnits.Volts); //try delaying sampling impedanceRecord.Timing.DelayFromSampleClock = 10; impedanceRecord.Timing.ConfigureSampleClock("", IMPEDANCE_SAMPLING_RATE, SampleClockActiveEdge.Rising, SampleQuantityMode.FiniteSamples); impedanceReader = new AnalogSingleChannelReader(impedanceRecord.Stream); impedanceRecord.Timing.ReferenceClockSource = "OnboardClock"; //Configure stim digital output task if (Properties.Settings.Default.StimPortBandwidth == 32) stimDigitalTask.DOChannels.CreateChannel(Properties.Settings.Default.StimulatorDevice + "/Port0/line0:31", "", ChannelLineGrouping.OneChannelForAllLines); //To control MUXes else if (Properties.Settings.Default.StimPortBandwidth == 8) stimDigitalTask.DOChannels.CreateChannel(Properties.Settings.Default.StimulatorDevice + "/Port0/line0:7", "", ChannelLineGrouping.OneChannelForAllLines); //To control MUXes stimDigitalWriter = new DigitalSingleChannelWriter(stimDigitalTask.Stream); //Configure stim analog output task if (Properties.Settings.Default.StimPortBandwidth == 32) { stimAnalogTask.AOChannels.CreateVoltageChannel(Properties.Settings.Default.StimulatorDevice + "/ao0", "", -10.0, 10.0, AOVoltageUnits.Volts); //Triggers stimAnalogTask.AOChannels.CreateVoltageChannel(Properties.Settings.Default.StimulatorDevice + "/ao1", "", -10.0, 10.0, AOVoltageUnits.Volts); //Triggers stimAnalogTask.AOChannels.CreateVoltageChannel(Properties.Settings.Default.StimulatorDevice + "/ao2", "", -10.0, 10.0, AOVoltageUnits.Volts); //Actual Pulse stimAnalogTask.AOChannels.CreateVoltageChannel(Properties.Settings.Default.StimulatorDevice + "/ao3", "", -10.0, 10.0, AOVoltageUnits.Volts); //Timing } else if (Properties.Settings.Default.StimPortBandwidth == 8) { stimAnalogTask.AOChannels.CreateVoltageChannel(Properties.Settings.Default.StimulatorDevice + "/ao0", "", -10.0, 10.0, AOVoltageUnits.Volts); //Actual pulse stimAnalogTask.AOChannels.CreateVoltageChannel(Properties.Settings.Default.StimulatorDevice + "/ao1", "", -10.0, 10.0, AOVoltageUnits.Volts); //Timing } stimAnalogTask.Timing.ConfigureSampleClock("/" + Properties.Settings.Default.ImpedanceDevice + "/ai/SampleClock", IMPEDANCE_SAMPLING_RATE, SampleClockActiveEdge.Rising, SampleQuantityMode.FiniteSamples); stimAnalogTask.Triggers.StartTrigger.ConfigureDigitalEdgeTrigger("/" + Properties.Settings.Default.ImpedanceDevice + "/ai/StartTrigger", DigitalEdgeStartTriggerEdge.Rising); impedanceRecord.Control(TaskAction.Verify); stimAnalogTask.Timing.ReferenceClockSource = impedanceRecord.Timing.ReferenceClockSource; stimAnalogTask.Timing.ReferenceClockRate = impedanceRecord.Timing.ReferenceClockRate; stimAnalogWriter = new AnalogMultiChannelWriter(stimAnalogTask.Stream); //Verify tasks impedanceRecord.Control(TaskAction.Verify); stimDigitalTask.Control(TaskAction.Verify); stimAnalogTask.Control(TaskAction.Verify); //Setup storage variable impedance = new double[numChannels][]; for (int c = 0; c < numChannels; ++c) { impedance[c] = new double[freqs.GetLength(0)]; for (int f = 0; f < freqs.Length; ++f) impedance[c][f] = double.NaN; } //Setup background worker bgWorker = new BackgroundWorker(); bgWorker.DoWork += new DoWorkEventHandler(bgWorker_DoWork); bgWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bgWorker_RunWorkerCompleted); bgWorker.ProgressChanged += new ProgressChangedEventHandler(bgWorker_ProgressChanged); bgWorker.WorkerSupportsCancellation = true; bgWorker.WorkerReportsProgress = true; //Run worker bgWorker.RunWorkerAsync(); }