public void shot() { try { using (Task myTask = new Task()) { if (checkShot()) { myTask.AOChannels.CreateVoltageChannel("Dev1", "aoChannel", Convert.ToDouble(-10), Convert.ToDouble(10), AOVoltageUnits.Volts); AnalogSingleChannelWriter writer = new AnalogSingleChannelWriter(myTask.Stream); writer.WriteSingleSample(true, Convert.ToDouble(0)); System.Threading.Thread.Sleep(1); writer.WriteSingleSample(true, Convert.ToDouble(5)); System.Threading.Thread.Sleep(1); writer.WriteSingleSample(true, Convert.ToDouble(0)); shotAvailable = false; //Timer On // Create a timer with 2.5 sec interval. aTimer = new System.Timers.Timer(2500); // Hook up the Elapsed event for the timer. aTimer.Elapsed += OnTimedEvent; aTimer.AutoReset = false; aTimer.Enabled = true; } } } catch (DaqException ex) { } }
public override void AcquisitionStarting() { //connect to the hardware controller hardwareControl = new DecelerationHardwareControl.Controller(); // initialise the output hardware, full scale -10 to 10 volts outputTask = new Task("analog output"); if (!Environs.Debug) { AnalogOutputChannel oc = (AnalogOutputChannel)Environs.Hardware.AnalogOutputChannels[(string)settings["channel"]]; oc.AddToTask(outputTask, -10, 10); writer = new AnalogSingleChannelWriter(outputTask.Stream); if (!Blocked()) { writer.WriteSingleSample(true, 0); } } scanParameter = 0; //go gently to the correct start position if (((string)settings["scanMode"] == "up" || (string)settings["scanMode"] == "updown") && !Blocked()) { rampOutputToVoltage((double)settings["start"]); } if (((string)settings["scanMode"] == "down" || (string)settings["scanMode"] == "downup") && !Blocked()) { rampOutputToVoltage((double)settings["end"]); } }
public void Apply_Voltage(Parameters Parameters_Instance, double voltage) { MainWindow.WindowInstance.Dispatcher.BeginInvoke(new MainWindow.Append_Log_Delegate(MainWindow.WindowInstance.Append_Log), "Applling voltage " + voltage.ToString() + "\n" ); try { outputTask = new Task("OutputTask"); outputTask.AOChannels.CreateVoltageChannel(Parameters_Instance.Output_Channel, "", Parameters_Instance.Output_Channel_MinVoltage, Parameters_Instance.Output_Channel_MaxVoltage, AOVoltageUnits.Volts); outputTask.Control(TaskAction.Verify); // TODO:: check if timing is necessary Output_Writer_Single = new AnalogSingleChannelWriter(outputTask.Stream); Output_Writer_Single.WriteSingleSample(true, voltage); outputTask.Done += new TaskDoneEventHandler(Apply_Voltage_Done); } catch (Exception ex) { StopTask(); MessageBox.Show(ex.Message); } finally { if (outputTask != null) { outputTask.Stop(); outputTask.Dispose(); outputTask = null; } } }
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); }
private void bgwGetWL_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; // Do the work (i.e. get the wavelength) while (true) { if (worker.CancellationPending == true) { e.Cancel = true; break; } else { Wavelength = CLGetLambdaReading(HandleBristolWavemeter); PiezoVoltage = ReaderAI.ReadSingleSample(); if (IsLockEnabled) { double newPiezoVoltage = LaserLockPID.AddDataPoint(Wavelength, BristolWavemeter.Properties.Settings.Default.AcquisitionPeriod, PiezoVoltage); using (Task myTask = new Task()) { myTask.AOChannels.CreateVoltageChannel(string.Format("dev1/ao{0}", Properties.Settings.Default.AnalogOutputPiezo), "PiezoVoltageAO", -3, 3, AOVoltageUnits.Volts); AnalogSingleChannelWriter myWriter = new AnalogSingleChannelWriter(myTask.Stream); myWriter.WriteSingleSample(true, Convert.ToDouble(newPiezoVoltage)); } IsLocked = (Math.Abs(LaserLockPID.LastWavelengthError) < Properties.Settings.Default.LockThreshold); labelPiezoVoltage.ForeColor = (Math.Abs(newPiezoVoltage) >= 2.9) ? Color.Red : Color.Black; } worker.ReportProgress(5); // report 5% progress Thread.Sleep(BristolWavemeter.Properties.Settings.Default.AcquisitionPeriod); } } }
/// <summary> /// Method for outputing a voltage on the DAQ /// </summary> /// <param name="task">NI-DAQ output task</param> /// <param name="voltage">Voltage to output. /// Note must be between the limits outMax and outMin. /// The range is limited elsewhere in the code</param> private void SetAnalogOutput(Task task, double voltage) { AnalogSingleChannelWriter writer = new AnalogSingleChannelWriter(task.Stream); writer.WriteSingleSample(true, voltage); task.Control(TaskAction.Unreserve); }
public override void AcquisitionStarting() { // initialise the output hardware outputTask = new Task("analog output"); if (!Environs.Debug) { AnalogOutputChannel oc = (AnalogOutputChannel)Environs.Hardware.AnalogOutputChannels[(string)settings["channel"]]; oc.AddToTask(outputTask, oc.RangeLow, oc.RangeHigh); writer = new AnalogSingleChannelWriter(outputTask.Stream); writer.WriteSingleSample(true, 0); } scanParameter = 0; //go gently to the correct start position if ((string)settings["scanMode"] == "up" || (string)settings["scanMode"] == "updown") { if ((string)settings["flyback"] == "overshoot") { rampOutputToVoltage((double)settings["overshootVoltage"]); } rampOutputToVoltage((double)settings["start"]); } if ((string)settings["scanMode"] == "down" || (string)settings["scanMode"] == "downup") { if ((string)settings["flyback"] == "overshoot") { rampOutputToVoltage((double)settings["overshootVoltage"]); } rampOutputToVoltage((double)settings["end"]); } }
public override void AcquisitionStarting() { // initialise the output hardware outputTask = new Task("analog output"); if (!Environs.Debug) { AnalogOutputChannel oc = (AnalogOutputChannel) Environs.Hardware.AnalogOutputChannels[(string)settings["channel"]]; oc.AddToTask(outputTask, oc.RangeLow, oc.RangeHigh); writer = new AnalogSingleChannelWriter(outputTask.Stream); writer.WriteSingleSample(true, 0); } scanParameter = 0; //go gently to the correct start position if ((string)settings["scanMode"] == "up" || (string)settings["scanMode"] == "updown") { if ((string)settings["flyback"] == "overshoot") rampOutputToVoltage((double)settings["overshootVoltage"]); rampOutputToVoltage((double)settings["start"]); } if ((string)settings["scanMode"] == "down" || (string)settings["scanMode"] == "downup") { if ((string)settings["flyback"] == "overshoot") rampOutputToVoltage((double)settings["overshootVoltage"]); rampOutputToVoltage((double)settings["end"]); } }
/// <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 void SetLaserVoltage(double voltage) { outputLaserTask.Start(); //outputLaserTask.Stop(); laserWriter.WriteSingleSample(true, voltage); outputLaserTask.Stop(); //outputLaserTask.Start(); }
public int WriteAnalogChannel(string lines, string name, int freq, int samples, int cycles, string sigtype, double ampl, double min, double max) { int res = 0; Task analogWriteTask = new Task(); AOChannel ch; if (max == 0) { max = 10; } try { // Create the task and channel //myTask = New Task() ch = analogWriteTask.AOChannels.CreateVoltageChannel(lines, "", min, max, AOVoltageUnits.Volts); // Verify the task before doing the waveform calculations analogWriteTask.Control(TaskAction.Verify); // Calculate some waveform parameters and generate data //Dim fGen As New FunctionGenerator( _ // analogWriteTask.Timing, _ // freq.ToString, _ // samples.ToString, _ // cycles.ToString, _ // sigtype, _ // ampl.ToString) //Configure the sample clock with the calculated rate //analogWriteTask.Timing.ConfigureSampleClock( _ // "", _ // fGen.ResultingSampleClockRate, _ // SampleClockActiveEdge.Rising, _ // SampleQuantityMode.ContinuousSamples, 1000) // Write the data to the buffer AnalogSingleChannelWriter writer = new AnalogSingleChannelWriter(analogWriteTask.Stream); //writer.WriteMultiSample(False, fGen.Data) //Dim res As IAsyncResult //res = writer.BeginWriteMultiSample(False, fGen.Data, AddressOf _WriteAnalogChannelComplete, 0) analogWriteTask.Start(); writer.WriteSingleSample(false, 2.5); //Start writing out data //analogWriteTask.Start() analogWriteTask.Stop(); } catch (DaqException ex) { DaqError(ex.Message); res = -1; } finally { analogWriteTask.Dispose(); } return(res); }
public override void AdjustOutput() { Input = sensor.ReadSensor(); //read the sensor OutputEstimate(); //estimate the output based on errors if (OutPut > 10.0) { writer.WriteSingleSample(true, 10.0); //write the new output. Output min and max are default +-10.0V } else if (OutPut < -10.0) { writer.WriteSingleSample(true, -10.0); } else { writer.WriteSingleSample(true, OutPut); } }
private void configureAnalogOutput() { analogOutputTask = new Task("phase lock analog output"); AnalogOutputChannel outputChannel = (AnalogOutputChannel)Environs.Hardware.AnalogOutputChannels["phaseLockAnalogOutput"]; outputChannel.AddToTask(analogOutputTask, VCO_LOW, VCO_HIGH); analogWriter = new AnalogSingleChannelWriter(analogOutputTask.Stream); analogWriter.WriteSingleSample(true, VCO_CENTRAL); // start out with the central value }
//set Analog AO0 - voltage level public void set_voltage_AO(double volt_AO) { using (Task myTask = new Task()) { AOChannel myAOChannel; myAOChannel = myTask.AOChannels.CreateVoltageChannel("dev1/ao0", "myAOChannel", 0, 5, AOVoltageUnits.Volts); AnalogSingleChannelWriter writer = new AnalogSingleChannelWriter(myTask.Stream); writer.WriteSingleSample(true, volt_AO); } }
//This takes in a voltage. A bit cheezy, but I needed the laser // voltage to be set as soon value as soon as it gets configured. public void ConfigureSetLaserVoltage(double voltage) { outputLaserTask = new Task("FeedbackToLaser"); laserChannel = (AnalogOutputChannel)Environs.Hardware.AnalogOutputChannels[laserChannelName]; laserChannel.AddToTask(outputLaserTask, -10, 10); outputLaserTask.Control(TaskAction.Verify); laserWriter = new AnalogSingleChannelWriter(outputLaserTask.Stream); laserWriter.WriteSingleSample(true, voltage); outputLaserTask.Start(); }
//This takes in a voltage. A bit cheezy, but I needed the laser // voltage to be set as soon value as soon as it gets configured. public void ConfigureSetLaserVoltage(double voltage) { outputLaserTask = new Task("FeedbackToLaser" + laserChannelName); laserChannel = (AnalogOutputChannel)Environs.Hardware.AnalogOutputChannels[laserChannelName]; laserChannel.AddToTask(outputLaserTask, laserChannel.RangeLow, laserChannel.RangeHigh); outputLaserTask.Control(TaskAction.Verify); laserWriter = new AnalogSingleChannelWriter(outputLaserTask.Stream); laserWriter.WriteSingleSample(true, voltage); //outputLaserTask.Start(); }
public void SetValue(double analogDataOut) { Task analogOutTask = new Task(); AOChannel myAOChannel; myAOChannel = analogOutTask.AOChannels.CreateVoltageChannel("dev31/ao0", "myAOChannel", 0, 5, AOVoltageUnits.Volts); AnalogSingleChannelWriter writer = new AnalogSingleChannelWriter(analogOutTask.Stream); writer.WriteSingleSample(true, analogDataOut); }
double phaseErrorInDegrees = 10;//changed to non-zero starting value so we can check phase lock is running with blockhead private void UpdateLock() { lock (lockParameterLockObject) { //calculate the new oscillator frequency // calculate the slope double[] lockXVals = new double[lockPhaseData.Count]; for (int i = 0; i < lockPhaseData.Count; i++) { lockXVals[i] = i; } double slope; //, intercept, err; ArrayList lockPhaseDataDouble = new ArrayList(); foreach (int p in lockPhaseData) { lockPhaseDataDouble.Add((double)p); } double[] lockYVals = (double[])lockPhaseDataDouble.ToArray(Type.GetType("System.Double")); //CurveFit.LinearFit(lockXVals, lockYVals, FitMethod.LeastSquare, out slope, out intercept, out err); slope = (lockYVals[lockYVals.Length - 1] - lockYVals[0]) / (lockXVals[lockXVals.Length - 1] - lockXVals[0]); // proportional gain oscillatorFrequency -= accumulatedPhaseDifference * PROPORTIONAL_GAIN; // derivative gain oscillatorFrequency -= slope * DERIVATIVE_GAIN; // limit the output swing if (oscillatorFrequency > OSCILLATOR_TARGET_RATE + OSCILLATOR_DEVIATION_LIMIT) { oscillatorFrequency = OSCILLATOR_TARGET_RATE + OSCILLATOR_DEVIATION_LIMIT; } if (oscillatorFrequency < OSCILLATOR_TARGET_RATE - OSCILLATOR_DEVIATION_LIMIT) { oscillatorFrequency = OSCILLATOR_TARGET_RATE - OSCILLATOR_DEVIATION_LIMIT; } // write to the synth or VCO if (cm == ControlMethod.synth) { redSynth.Frequency = oscillatorFrequency / 1000000; } if (cm == ControlMethod.analog && !Environs.Debug) { analogWriter.WriteSingleSample(true, VCO_CENTRAL + (oscillatorFrequency - OSCILLATOR_TARGET_RATE) / VCO_CAL); } // update the plot phaseErrorInDegrees = (double)phasePlotData[phasePlotData.Count - 1]; oscillatorPlotData.Add(oscillatorFrequency / 1000); lockPhaseData.Clear(); } }
public SDLPS500Controller(string device, string aoName) { _controlOutput = 0; _powerCashValid = true; _powerCashed = 0; //Set up task and channel writer _aoTask = new Task("LaserOutput"); _aoTask.AOChannels.CreateVoltageChannel(device + "/" + aoName, "LasOut", 0, 5, AOVoltageUnits.Volts); _aoWriter = new AnalogSingleChannelWriter(_aoTask.Stream); //Set output to 0 _aoWriter.WriteSingleSample(true, 0); }
private void rampOutputToVoltage(double voltage) { for (int i = 1; i <= (int)settings["rampSteps"]; i++) { if (!Environs.Debug) { writer.WriteSingleSample(true, scanParameter - (i * (scanParameter - voltage) / (int)settings["rampSteps"])); } Thread.Sleep((int)settings["rampDelay"]); } scanParameter = voltage; }
public void SetGain(double gain) { var niTask = new NationalInstruments.DAQmx.Task(); var analogOutput = niTask.AOChannels.CreateVoltageChannel( "Dev8/ao0", "SetGain", 0, 5, AOVoltageUnits.Volts ); var writer = new AnalogSingleChannelWriter(niTask.Stream); writer.WriteSingleSample(true, gain); }
public void setValue(double value) { try { myChannelWriter.WriteSingleSample(true, value); } catch (DaqException exception) { if (MessageBox.Show("Can't connect to USB-DAQ. Continue? ", "Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Error) == DialogResult.Cancel) { Environment.Exit(0); } } }
public void Dispose() { if (IsDisposed) { return; } if (_aoTask != null) { _aoWriter.WriteSingleSample(true, 0); _aoTask.Dispose(); _aoTask = null; } IsDisposed = true; }
public void SetSetPoint(double temperature) { var gain = PlantCalculations.CalcTemperatureToVolt(temperature); var niTask = new NationalInstruments.DAQmx.Task(); var analogOutput = niTask.AOChannels.CreateVoltageChannel( "Dev9/ao1", "SV", 1, 5, AOVoltageUnits.Volts ); var writer = new AnalogSingleChannelWriter(niTask.Stream); writer.WriteSingleSample(true, Math.Min(Math.Max(gain, 1), 5)); }
//아날로그 출력 public void Output(double data, ref string ErrorMsg) { try { writer.WriteSingleSample(true, data); } catch (DaqException de) { ErrorMsg = de.Message; } catch (Exception e) { ErrorMsg = e.Message; } }
private void RampToVoltage(double v) { int steps = 20; int delayAtEachStep = 50; double laserVoltage = hardwareControl.LaserFrequencyControlVoltage; double stepsize = (v - laserVoltage) / steps; for (int i = 1; i <= steps; i++) { laserVoltage += stepsize; laserWriter.WriteSingleSample(true, laserVoltage); hardwareControl.LaserFrequencyControlVoltage = laserVoltage; Thread.Sleep(delayAtEachStep); } outputTask.Control(TaskAction.Unreserve); }
public ThorlabsLDC240Controller(string device, string aoCurrent, string doOnOff) { _laserOn = false; _current = 0; //Set up tasks and channel writers _onOffTask = new Task("LaserOnOff"); _onOffTask.DOChannels.CreateChannel(device + "/" + doOnOff, "OnOff", ChannelLineGrouping.OneChannelForAllLines); _onOffWriter = new DigitalSingleChannelWriter(_onOffTask.Stream); _currentTask = new Task("LaserCurrent"); _currentTask.AOChannels.CreateVoltageChannel(device + "/" + aoCurrent, "Current", 0, 10, AOVoltageUnits.Volts); _currentWriter = new AnalogSingleChannelWriter(_currentTask.Stream); //Set current to 0 _currentWriter.WriteSingleSample(true, 0); //The laser controller only reacts to edges on the TTL line - so to gain control briefly switch on, then off _onOffWriter.WriteSingleSampleSingleLine(true, true); Thread.Sleep(100); _onOffWriter.WriteSingleSampleSingleLine(true, false); }
public static void WriteVoltage(string port_num, double value, int milliseconds = 100, string dev_name = "Dev1") { if (RuntimeConfiguration.Mode.HasFlag(RuntimeMode.VirtualNI)) { return; } dev_name = RefactorDevName(dev_name); Task task = new Task(); task.AOChannels.CreateVoltageChannel(string.Format("{0}/{1}", dev_name, port_num), "", -10, 10, AOVoltageUnits.Volts); AnalogSingleChannelWriter writer = new AnalogSingleChannelWriter(task.Stream); task.Start(); Thread.Sleep(milliseconds); writer.WriteSingleSample(false, value); task.Stop(); task.Dispose(); }
private void btnWriteAnalogOut_Click(object sender, EventArgs e) { Task analogOutTask = new Task(); AOChannel myAOChannel; myAOChannel = analogOutTask.AOChannels.CreateVoltageChannel("dev1/ao0", "myAOChannel", 0, 5, AOVoltageUnits.Volts); AnalogSingleChannelWriter writer = new AnalogSingleChannelWriter(analogOutTask.Stream); double analogDataOut; analogDataOut = Convert.ToDouble(txtAnalogOut.Text); writer.WriteSingleSample(true, analogDataOut); // kullanacaðýmýz zaman Form1 nesne1 = new Form1(); }
public void SendScanTriggerAndWaitUntilDone() { scanStop = false; pdData = new double[2, rampV.Length]; for (int i = 0; i < rampV.Length; i++) { cavityWriter.WriteSingleSample(true, rampV[i]); double[] pds = photodiodesReader.ReadSingleSample(); pdData[0, i] = pds[0]; pdData[1, i] = pds[1]; //Thread.Sleep(2); lock (scanStopLock) { if (scanStop) { return; } } } }
public void Dispose() { if (IsDisposed) { return; } if (_onOffTask != null) { _onOffWriter.WriteSingleSampleSingleLine(true, false); _onOffTask.Dispose(); _onOffTask = null; } if (_currentTask != null) { _currentWriter.WriteSingleSample(true, 0); _currentTask.Dispose(); _currentTask = null; } IsDisposed = true; }
public void Write(string output, double outputVoltage) { try { Task analogOutTask = new Task(); AOChannel myAOChannel = analogOutTask.AOChannels.CreateVoltageChannel( Device + "/" + output, "myAOChannel", Settings.Vmin, Settings.Vmax, AOVoltageUnits.Volts ); AnalogSingleChannelWriter writer = new AnalogSingleChannelWriter(analogOutTask.Stream); writer.WriteSingleSample(true, outputVoltage); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
//Writes the outputsignal to port ao0 public static void WriteOutput(double signal) { double analogData; var signalTask = new NationalInstruments.DAQmx.Task(); try { analogData = signal; signalTask.AOChannels.CreateVoltageChannel(deviceName + "/ao0", "Signal", 0, 5, AOVoltageUnits.Volts); var writer = new AnalogSingleChannelWriter(signalTask.Stream); writer.WriteSingleSample(true, analogData); } catch (Exception e) { lastException = Convert.ToString(e); } finally { signalTask.Dispose(); } }
public override void AcquisitionStarting() { //connect to the hardware controller hardwareControl = new DecelerationHardwareControl.Controller(); // initialise the output hardware, full scale -10 to 10 volts outputTask = new Task("analog output"); if (!Environs.Debug) { AnalogOutputChannel oc = (AnalogOutputChannel)Environs.Hardware.AnalogOutputChannels[(string)settings["channel"]]; oc.AddToTask(outputTask, -10, 10); writer = new AnalogSingleChannelWriter(outputTask.Stream); if (!Blocked()) writer.WriteSingleSample(true, 0); } scanParameter = 0; //go gently to the correct start position if (((string)settings["scanMode"] == "up" || (string)settings["scanMode"] == "updown") && !Blocked()) rampOutputToVoltage((double)settings["start"]); if (((string)settings["scanMode"] == "down" || (string)settings["scanMode"] == "downup") && !Blocked()) rampOutputToVoltage((double)settings["end"]); }
//Overload for using a calibration before outputting to hardware public void SetAnalogOutput(string channelName, double voltage, bool useCalibration) { AnalogSingleChannelWriter writer = new AnalogSingleChannelWriter(analogTasks[channelName].Stream); double output; if (useCalibration) { try { output = ((Calibration)calibrations[channelName]).Convert(voltage); } catch (DAQ.HAL.Calibration.CalibrationRangeException) { MessageBox.Show("The number you have typed is out of the calibrated range! \n Try typing something more sensible."); throw new CalibrationException(); } catch { MessageBox.Show("Calibration error"); throw new CalibrationException(); } } else { output = voltage; } try { writer.WriteSingleSample(true, output); analogTasks[channelName].Control(TaskAction.Unreserve); } catch (Exception e) { MessageBox.Show(e.Message); } }
private void configureAnalogOutput() { analogOutputTask = new Task("phase lock analog output"); AnalogOutputChannel outputChannel = (AnalogOutputChannel) Environs.Hardware.AnalogOutputChannels["phaseLockAnalogOutput"]; outputChannel.AddToTask(analogOutputTask, VCO_LOW, VCO_HIGH); analogWriter = new AnalogSingleChannelWriter(analogOutputTask.Stream); analogWriter.WriteSingleSample(true, VCO_CENTRAL); // start out with the central value }
public void SetAnalogOutput(string channel, double value, bool useCalibration) { analogWriter = new AnalogSingleChannelWriter(analogTasks[channel].Stream); bool changeIt = true; double output = 0.0; if (useCalibration) { try { output = ((Calibration)calibrations[channel]).Convert(value); } catch (DAQ.HAL.Calibration.CalibrationRangeException) { MessageBox.Show("The number is outside the calibrated range. The value will not be updated."); changeIt = false; } catch { MessageBox.Show("Calibration error"); changeIt = false; } } else { output = value; } if (changeIt) { try { analogWriter.WriteSingleSample(true, output); analogTasks[channel].Control(TaskAction.Unreserve); } catch (Exception e) { MessageBox.Show(e.Message); } } }
// ---------------ZAPIS ANALOG----------- /// <summary> /// Metoda nastavuje/zapisuje cez AD prevodnik hodnotu value. /// </summary> /// <param name="value"></param> public void setAnalogOutput(double value) { Task analogOutTask = new Task(); AOChannel myAOChannel; myAOChannel = analogOutTask.AOChannels.CreateVoltageChannel( prevodnikId + "/ao1", "myAOChannel", 0, 5, AOVoltageUnits.Volts ); AnalogSingleChannelWriter writer = new AnalogSingleChannelWriter(analogOutTask.Stream); writer.WriteSingleSample(true, value); }
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); } }