„Függvénygenerátor program myDAQ-al” változatai közötti eltérés
(egy szerkesztő 2 közbeeső változata nincs mutatva) | |||
1. sor: | 1. sor: | ||
+ | == Function generator program with myDAQ == | ||
+ | |||
The following program generates a sinusoidal signal on an analog output using a NationalInstruments DAQ card (for example myDAQ). It uses the built-in sample clock of the device for timing (hardware-timed data generation). | The following program generates a sinusoidal signal on an analog output using a NationalInstruments DAQ card (for example myDAQ). It uses the built-in sample clock of the device for timing (hardware-timed data generation). | ||
9. sor: | 11. sor: | ||
Vmin, Vmax, AOVoltageUnits.Volts); | Vmin, Vmax, AOVoltageUnits.Volts); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | * Documentation of the AOChannels.CreateVoltageChannel method: http://zone.ni.com/reference/en-XX/help/370473J-01/ninetdaqmxfx40ref/html/m_nationalinstruments_daqmx_aochannelcollection_createvoltagechannel_1/ | |
* DevID: string identifying the device and the output terminal. For example: "myDAQ1/ao0". | * DevID: string identifying the device and the output terminal. For example: "myDAQ1/ao0". | ||
* Vmin and Vmax is used to set the range of the analog output. In the case of the myDAQ device, -10, 10 V is the maximum output range. | * Vmin and Vmax is used to set the range of the analog output. In the case of the myDAQ device, -10, 10 V is the maximum output range. | ||
19. sor: | 21. sor: | ||
SampleClockActiveEdge.Rising, SampleQuantityMode.FiniteSamples, numPnts); | SampleClockActiveEdge.Rising, SampleQuantityMode.FiniteSamples, numPnts); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | * Documentation of the ConfigureSampleClock method: http://zone.ni.com/reference/en-XX/help/370473J-01/ninetdaqmxfx40ref/html/m_nationalinstruments_daqmx_timing_configuresampleclock_1/ | |
* SampleRate: double value, defines the number of samples generated in 1 second. The maximum sample rate available using the myDAQ device is 200 kHz. | * SampleRate: double value, defines the number of samples generated in 1 second. The maximum sample rate available using the myDAQ device is 200 kHz. | ||
* SampleQuantityMode.FiniteSamples: sets the data generation to finite mode. Using finite mode, data generation stops automatically after reaching the end of the output data. | * SampleQuantityMode.FiniteSamples: sets the data generation to finite mode. Using finite mode, data generation stops automatically after reaching the end of the output data. |
A lap jelenlegi, 2022. szeptember 16., 12:29-kori változata
Function generator program with myDAQ
The following program generates a sinusoidal signal on an analog output using a NationalInstruments DAQ card (for example myDAQ). It uses the built-in sample clock of the device for timing (hardware-timed data generation).
Creating a Task for handling the analog output:
OutTask = new NationalInstruments.DAQmx.Task(); OutTask.AOChannels.CreateVoltageChannel(DevID, "", Vmin, Vmax, AOVoltageUnits.Volts);
- Documentation of the AOChannels.CreateVoltageChannel method: http://zone.ni.com/reference/en-XX/help/370473J-01/ninetdaqmxfx40ref/html/m_nationalinstruments_daqmx_aochannelcollection_createvoltagechannel_1/
- DevID: string identifying the device and the output terminal. For example: "myDAQ1/ao0".
- Vmin and Vmax is used to set the range of the analog output. In the case of the myDAQ device, -10, 10 V is the maximum output range.
For hardware-timed data generation, the timing of the Task also has to be specified:
OutTask.Timing.ConfigureSampleClock("", SampleRate, SampleClockActiveEdge.Rising, SampleQuantityMode.FiniteSamples, numPnts);
- Documentation of the ConfigureSampleClock method: http://zone.ni.com/reference/en-XX/help/370473J-01/ninetdaqmxfx40ref/html/m_nationalinstruments_daqmx_timing_configuresampleclock_1/
- SampleRate: double value, defines the number of samples generated in 1 second. The maximum sample rate available using the myDAQ device is 200 kHz.
- SampleQuantityMode.FiniteSamples: sets the data generation to finite mode. Using finite mode, data generation stops automatically after reaching the end of the output data.
- numPnts: number of points to be generated (length of output data)
Note: the length of the generated signal: L (sec) = numPts / SampleRate
Finally, an AnalogSingleChannelWriter object is created and associated with the Task handling the output:
analogWriter = new AnalogSingleChannelWriter(OutTask.Stream);
To start generating the signal, first a double array has to be created. Then the array is passed to the AnalogSingleChannelWriter object and the DAQ card starts generating the data. In the below example, a sinusoidal signal is generated.
// Generate data for output double[] outData = new double[numPnts]; for (int i = 0; i < numPnts; i++) { outData[i] = Math.Sin((double)i / numPnts * 2 * Math.PI); } // Start Output analogWriter.WriteMultiSample(true, outData);
After the generation stopped, the resources used by the task has to be released:
OutTask.Dispose();
Note: when using SampleQuantityMode.FiniteSamples, the data generation stops automatically after the last value is generated in the outdata array. In order to repeatedly generate data, these code lines have to execute in a loop or in a timer event.