Quantcast
Channel: Measurement Studio for .NET Languages topics
Viewing all 1999 articles
Browse latest View live

How to determine bridge type choices for any given cDAQ module

$
0
0

I'm trying to create a UI wrapper for some generic NI channel information.  Some of the modules are force/pressure bridge-type modules, such as the NI 9236.  There are a number of bridge choices (AIBridgeConfiguration), ranging from no bridge, quarter bridge ... up to full bridge.  I know how to set the value, but I can't figure out how to determine what the valid choices are for each module using the NI driver.  Looking through the choices for the DAQmx.Device class, I just don't see anything.  Can anyone help me with this?


Detect a TC-01 Being Plugged In

$
0
0

Can somebody please point me to an example (C#) of detecting the TC-01 USB being plugged into the computer. I have a program that monitors the temperature and reports it with the test data for each test. If the thermocouple throws an exception when it is instantiated I try to get out gracefully. But if the user then finds the usb and plugs it in, how can I detect that? I would think I have to subscribe to windows events then check for a thermocouple. 

 

I do not use LabView. Its just straight C#.

 

Thank you,

The right thread use with NI DAQ measurement

$
0
0

I'm using NI daq for some measurements and i don't have a clue how to use it with thread and for loop

my point is: i have 3 different frequencies, that stored in array , i need that after clicking a START button, function will generate first frequency and will red it and store data to the file, after this it move to second frequency and to same job, and after this will do measurement with third frequency and stop

Example:

for(int i=0; i< 3; i++)

{

   Measurement function();

}

 

I have this code:

//start button function click
private void cmd_start_Click(object sender, EventArgs e)
        {
            cmd_start.Enabled = false;
            taskRunning = true;

            for (int i = 0; i < matrix_data.Count; i++)
            {
                // Change the mouse to an hourglass for the duration of this function.
                Cursor.Current = Cursors.WaitCursor;
                pass_freq = matrix_data[i].freq;
                try
                {
                    // Create the master and slave tasks
                    inputTask = new Task("inputTask");
                    outputTask = new Task("outputTask");

                    // Configure both tasks with the values selected on the UI.
                    inputTask.AIChannels.CreateVoltageChannel("Dev1/ai0",
                        "",
                        AITerminalConfiguration.Differential,
                        inputMinValNumeric,
                        inputMaxValNumeric,
                        AIVoltageUnits.Volts);

                    outputTask.AOChannels.CreateVoltageChannel("Dev1/ao0",
                        "",
                        Convert.ToDouble(outputMinValNumeric),
                        Convert.ToDouble(outputMaxValNumeric),
                        AOVoltageUnits.Volts);

                    // Set up the timing
                    inputTask.Timing.ConfigureSampleClock("",
                        Convert.ToDouble(rateNumeric),
                        SampleClockActiveEdge.Rising,
                        SampleQuantityMode.FiniteSamples,
                        Convert.ToInt32(samplesNumeric));

                    outputTask.Timing.ConfigureSampleClock("",
                        Convert.ToDouble(rateNumeric),
                        SampleClockActiveEdge.Rising,
                        SampleQuantityMode.FiniteSamples,
                        Convert.ToInt32(samplesNumeric));

                    // Set up the start trigger

                    string deviceName = "Dev1";
                    string terminalNameBase = "/" + GetDeviceName(deviceName) + "/";
                    //        outputTask.Triggers.StartTrigger.ConfigureDigitalEdgeTrigger(terminalNameBase + "ai/StartTrigger", triggerEdge);

                    // Verify the tasks
                    inputTask.Control(TaskAction.Verify);
                    outputTask.Control(TaskAction.Verify);

                    // Write data to each output channel
                    FunctionGenerator fGen = new FunctionGenerator(/*Convert.ToString(frequencyNumeric)*/matrix_data[i].freq,
                        Convert.ToString(samplesNumeric),
                        Convert.ToString(Convert.ToDouble(frequencyNumeric) / (rateNumeric / samplesNumeric)),
                        "Sine Wave",
                        amplitudeNumeric.ToString());

                    output = fGen.Data;

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

                    // Officially start the task
                    StartTask();
                    // Start reading as well
                    inputCallback = new AsyncCallback(InputRead);
                    reader = new AnalogSingleChannelReader(inputTask.Stream);
                    //reader1 = new AnalogMultiChannelReader(inputTask.Stream);
                    // Use SynchronizeCallbacks to specify that the object 
                    // marshals callbacks across threads appropriately.
                    reader.SynchronizeCallbacks = true;

                    outputTask.Done += new TaskDoneEventHandler(outputTask_Done);
                    inputTask.Done += new TaskDoneEventHandler(inputTask_Done);
                   

                    reader.BeginReadMultiSample(Convert.ToInt32(samplesNumeric), inputCallback, inputTask);
                    outputTask.Start();
                    inputTask.Start();
                    // Setup the Task Done event
                    outputTask.WaitUntilDone();
                    inputTask.WaitUntilDone();
                    //lock (runningTask);
                }
                catch (Exception ex)
                {
                    StopTask();
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    inputTask.Dispose();
                    outputTask.Dispose();
                    cmd_start.Enabled = true;
                    cmd_Stop.Enabled = false;
                }
            }
        }

private void InputRead(IAsyncResult ar)
        {

            try
            {
                if (runningTask != null && runningTask == ar.AsyncState)
                {
                    // Read the data
                    double[] data = reader.EndReadMultiSample(ar);

                    // Display the data
                    for (int i = 0; i < inputDataTable.Rows.Count && i < data.Length; i++)
                    {
                        inputDataTable.Rows[i][0] = data[i];
                        WriteTextAsync(data[i].ToString(), tx, pass_freq);
                    }
                    for (int i = data.Length; i < inputDataTable.Rows.Count; i++)
                    {
                        inputDataTable.Rows[i][0] = DBNull.Value;
                    }

                    // Set up next callback
                    reader.BeginReadMultiSample(Convert.ToInt32(samplesNumeric), inputCallback, inputTask);
                }
            }
            catch (Exception ex)
            {
                StopTask();
                MessageBox.Show(ex.Message);
            }
        }

static async void WriteTextAsync(string text, string Name, string freq)
        {
            // Set a variable to the My Documents path.
            //string mydocpath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            string mydocpath = @"E:\code\imp_main\daq_data\WriteData_" + Name +"_" + freq + ".csv";

            // Write the text asynchronously to a new file named "WriteTextAsync.txt".
            using (StreamWriter outputFile = new StreamWriter(mydocpath, true))
            {
                await outputFile.WriteAsync(text+'\n');
            }
        }

with this code i have only last frequency saved to file

and i want to get 3 files with 3 frequencies as well

how i can each time get another frequency?

 

where i'm wrong in the code?

 

thanks for answers

 

Install INF file during installation of the setup package made by Measurement Studio Installer Builder

$
0
0

Hi,

 

We need to install a .INF file during the installation of the setup package made by Measurement Studio Installer Builder. But we have no idea how to do it with Measurement Studio Installer Builder. Any idea regarding this please?

 

RealFFT problem

$
0
0

Hi guys:

            I used measurement studio  2015. Sampling from ADC to get 1024  data(singals: 30~100HZ 1~5Vpp sin wave) ,saved to excel. imported  from excel to make FFT. according to the filter examples .

codes as following:

void CalculateFFTFunction(double []waveform)
{
//waveform data size
int datasize = waveform.Length;

//number of samples for FFT data
int fftnumofSamples = datasize/2;
xwaveform = new double[fftnumofSamples];
magnitudes = new double[datasize];
subsetOfMagnitudes = new double[fftnumofSamples];
phases = new double[datasize];
subsetOfPhases = new double[fftnumofSamples];
logMagnitudes = new double[fftnumofSamples];
FFTValue = new ComplexDouble[datasize];
int i;

try
{
// Calculate the FFT of waveform array.
FFTValue = NationalInstruments.Analysis.Dsp.Transforms.RealFft(waveform);

// Get the magnitudes and phases of FFT array..
NationalInstruments.ComplexDouble.DecomposeArrayPolar(FFTValue, out magnitudes, out phases);

double scalingFactor = 1.0/(double)datasize;

double deltaFreq = samplingRateNumericEdit.Value * scalingFactor;
textEdit1.EditValue = samplingRateNumericEdit.Value;
double maxvalue= new double();
double imaxvalue=new double();


subsetOfMagnitudes[0] = magnitudes[0] * scalingFactor;

// It's sufficient to plot just the half of numberOfSamples points to show the FFT.
// Because the other half will be just the mirror image of the first half.
for(i=1; i<fftnumofSamples; i++)
{
// Generating xwaveform with respect to which magnitude and phase will be plotted.
xwaveform[i] = deltaFreq * i;
subsetOfMagnitudes[i] = magnitudes[i]*scalingFactor*Math.Sqrt(2.0); // Storing only half the magnitudes array.
maxvalue = ArrayOperation.GetMax(subsetOfMagnitudes);
imaxvalue = ArrayOperation.GetIndexOfMax(subsetOfMagnitudes);

subsetOfPhases[i] = phases[i]; // Storing only half of the phases array.
}

// Display mode: linear or exponential
switch(displayModeComboBox.SelectedIndex)
{
// Plot the magnitudes and the phases.
default:
case 0: // Linear mode.
magnitudePlot.YAxis.Caption = "Magnitude VRMS";
magnitudePlot.PlotXY(xwaveform, subsetOfMagnitudes);
phasePlot.PlotXY(xwaveform, subsetOfPhases);
break;
case 1: // Exponential mode.
for(i=0; i<fftnumofSamples; i++)
{
logMagnitudes[i] = 20.0*System.Math.Log10(magnitudes[i]);
}
magnitudePlot.YAxis.Caption = "Magnitude in dB";
magnitudePlot.PlotXY(xwaveform, logMagnitudes);
phasePlot.PlotXY(xwaveform, subsetOfPhases);
break;
}
}
catch (Exception exp)
{
MessageBox.Show(exp.Message);
}
}

Attached the wave, signal is 80hz 1vpp Sinwave  

but i found the magnitude and frequcney valule  are incorrect.  Is there anyone who can give me some advice? Thank you for your advice.

Program Becomes Less Responsive During Successive Runs

$
0
0

Hi all,

I hope this is the correct place to post this question.

I'm having something strange happen. I'm using VB.NET 2010 and Measurement Studio 2010 to acquire, display and (optionally) log data to a file. I'm starting off simple: a function generator sending a signal into my DAQ on a single channel. The program reads the signal, displays it in a WaveformGraph and logs the data into a TDMS file. It works great. Here's the interface (below).

DAQ_Pic.jpg

But I'm getting some strange behavior. [NOTE: It does not seem to matter if I am logging data to a file or not.] I can start the process and after some time stop it. Then start it a second time. When I click the stop button the second time, the process will stop, but after several seconds have gone by. If I start the process a third time, and click the stop button, the program will not respond at all. The data continues to be updated in the graph and will not stop. The UI is unresponsive. This happens whether it is run from the IDE or the compiled EXE.

 

Using the TASK manager to monitor resource use I have noticed that during the data acquisition process, the resource use is almost zero. When I stop the process (click the STOP button), "devenv.exe" and "DAQ_Test_1.vshost.exe" (the program) use a good bit of resources. When I restart the program the 2nd and 3rd time the CPU usage goes back down to basically zero.

DAQ_Pic2.jpg

 

Here is my code (variables are declared elsewhere):

----------------------------------------------------------------------------------------------------------------

btnStart_Click:

'Create a new analog input task for reading sensor data

aiTask = New Task

 

'Create new analog input channels for the task

aiTask.AIChannels.CreateVoltageChannel("/Dev1/ai0", "", AITerminalConfiguration.Differential, -10.0, 10.0, AIVoltageUnits.Volts)

 

'Configure the timing to use the hardware/internal clock

aiTask.Timing.ConfigureSampleClock("", CDbl(txtScanRate.Text), SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples, CDbl(txtScanRate.Text))

 

'Create a channel reader object

aiSingleChannelReader = New AnalogSingleChannelReader(aiTask.Stream)

 

'If logging data to a file

If Switch_LogData.Value = True Then

aiTask.ConfigureLogging(SaveFilePath, TdmsLoggingOperation.OpenOrCreate, LoggingMode.LogAndRead, "Group Name")

End If

 

 'Start acquiring the waveform data

aiSingleChannelReader.BeginReadWaveform(CInt(txtNumberOfPoints.Text), New AsyncCallback(AddressOf TestCallBack), Nothing)

 

'enable/disable the start/stop buttons

btnStart.enabled = false

btnStop.enabled = true

----------------------------------------------------------------------------------------------------------------

TestCallBack sub

 

'Get the data and put it into the variable

data = aiSingleChannelReader.ReadWaveform(CInt(txtNumberOfPoints.Text))

 

'Plot the data in the WaveformGraph

WaveformGraph1.PlotWaveform(data)

WaveformGraph1.Refresh()

 

'Set the callback to perform another read

aiSingleChannelReader.BeginReadWaveform(CInt(txtNumberOfPoints.Text), New AsyncCallback(AddressOf TestCallBack), aiTask)

----------------------------------------------------------------------------------------------------------------

 

btnStop_Click

'Stop the running task

aiTask.Stop()

'Cleanup

aiTask.Dispose()

 

'enable/disable the start/stop buttons

btnStart.enabled = true

btnStop.enabled = false

 ---------------------------------------------------------------------------------------------------------------

 

Start the 1st time & stop: it works great.

Start the 2nd time & stop: wait several seconds, then stop.

Start 3rd time: starts, but will not stop. The UI is unresponsive.

 

I've tried moving my start and stop button enable/disable to other parts of the subroutine (perhaps this has something to do with it?), but that makes no difference.

 

This is being done on a desktop running Windows XP SP3. I have also tried the code on a laptop running Windows 7 Professional. It makes no difference.

 

Does anyone have any ideas what might be causing this?

 

I can provide my whole program if someone thinks they might want to see it.

 

Thanks.

Necessary DLLS for developing a .net NI DAQ control

$
0
0

To distribute the final program that uses a NI thermocouple (TC-01) do I have to install NI-DAQmx on each machine that is going to run my program?

Internal routing DIO

$
0
0

Hello,

 

I am working with NI 6612 PCIe and C#. I am aware of the possible internal routes of my card. I managed to connect my DIO-lines physically and could successful monitor a signal signal I generated on Oscilloscope. Basically, I had some sort of this:

 

CTR0 Out => Pulsetrain => physical wire => CTR2 src=> Read (e.g. Count edges)

 

Now my problem is how to address the internal routes of my card properly. I would like to be able to monitor any digital signal I have created  but without any physical wire.

 

Thank you in advance


The scatter graph stops re-painting

$
0
0

I have an application running under Win10. For some reason the scattergraph stops updating. I am using a delegate to append data from a different thread. Normally works fine, but for some reason stops re-paining the graph after a random number of appends.

 

I appreciate any help.

 

Thanks!

Interfacing NI 6255 with ansi C

$
0
0

Hello,

 

I would like to interface NI 6255 using ANSI C and sample at least one of the channels. Can anyone share any sample code or give any recommendation?

 

Regards

Measurement studio 2015 installer does not recognise Device Drivers Disc

$
0
0

Good morning,

 

I am trying to install Measurement Studio 2015 on a new Machine. It is already loaded with LabView 2012 SP1, NiDaqmx 9.8.0 (which our company uses)

In order to some C# applications work on this new machine we need Measurement Studio Integrated with Visual Studio 2010 (preferably). I tried finding an Installer for Measurement Studio 2012 but did not have any luck. I am now trying to install Measurement Studio 2015.

 

The installation process has gone as far as asking for NI Drivers Disc, how ever I have tried the following:

 - Ni Drivers DVD (Feb 2013)

 - Ni Drivers DVD (Aug 2013)

 - Ni Drivers DVD extracted to hard drive (Aug and Feb 2013)

 - Ni Drivers .Zip (Aug 2013, from NI website)

 

but the installer does not recognize any of these! It just says that the media does not contain necessary files. I am going to download the latest version of Drivers and try that, but any idea what the issue could be? the message does not specify any particular version of Drivers Disc.

 

Best,

Y-Axis scales for WaveformChart

$
0
0

Greetings,

 

I have a waveform graph in which I am plotting two sets of data (method plotymultiple).  I have the Y-scales' behavior properties set up exactly the same (default values).  One scale (torque) is scaling properly, but the other one (speed) is not.  Is it because I'm calling plotYmultiple method on the data?  How should I do this to get the simple results that I want?

 

Thanks,

D

Problem Finding a cDAQ with DaqSystem.Local.AddNetworkDevice

$
0
0

I was able to connect to a virtual cDAQ that I created with some .NET code and was able to stream data to the screen.  For the next step, I am trying to connect to a true cDAQ on my LAN.  I used the following code:

 

DaqSystem.Local.AddNetworkDevice("100.100.11.29", "cDAQ9139", 100);

 

And it comes back with an exception with the following reason:

 

An unhandled exception of type 'NationalInstruments.DAQmx.DaqException' occurred in NationalInstruments.DAQmx.dll

Additional information: Retrieving properties from the network device failed. Make sure the device is connected.

 

I can find the cDAQ using MAX at that address, and it says that it is running.  Could this be a firewall issue, or am I just missing something?

 

Thanks - Wil

NI DAQmax [ USB 6501]

$
0
0

Dear All, 

Am currently NI DAQMAX for reading and writing digital inputs and outputs.

now am facing one problem.

 

i have to read the data from channel1 like (Dev1/port1/line1). in this i have to read the data.

but how to find the data coming from hardware. like when am writing data from other port then reply data coming from port  (Dev1/port1/line1). so how to read it and i have find it how many data come from connected hardware to this port??

 

Help me out 

Is NI-DMM .NET class libraries 15.2 compatible with DMM Driver 17?

$
0
0

It looks like there is no NI-DMM .NET Class Libraries 17 to go along with NI-DMM 17.0.  The latest version of NI-DMM .NET Class Libraries is 15.2.  Is version 15.2 of the NI-DMM .NET Class Libraries compatible with version 17.0 of the NI-DMM Driver?


How to Programmatically Determine Available NI DAQ Device with C#

$
0
0

I have multiple NI devices installed on my system and I would like to get a list of these devices, how can I get the list of these devices with C#?

How can I get the devices' and modules' name

$
0
0

I can get devices and modules' physical channel (I use cDAQs)  but I wonder if there is any way to get what these cDAQ devices are?

"Dev1" --> NI 9074, cDAQ Modules: NI 9225, NI 9227

"Dev2" --> NI 9078, cDAQ Modules: NI 9234, NI 9234

 

How to write DO lines respectively?

$
0
0

Hello,

I have a PCI-6509 card and I want to control any of those 96 lines in real time.

I just take the first 4 DO for example.

 

            digitalWriteTask = new Task();
            digitalWriteTask.DOChannels.CreateChannel("Dev2/port1/line0:3", "myDOChannel",
                        ChannelLineGrouping.OneChannelForEachLine);
            myDigitalWriter = new DigitalSingleChannelWriter(digitalWriteTask.Stream);

It seems impossible to change line1 without interferencing other three lines since we need a bool[4] on the writer.

Read and Write is not an option in my case. Do I really have to create 96 Tasks and DO channels to be able to control these 96 lines separately? Is there any other way? 

 

One or more devices do not support multidevice tasks

$
0
0

I am in vs2015 with NationalInstruments.DAQmx library file development, when I add multiple devices being given: 'One or more devices do not support multidevice tasks'. How do I add multiple devices? My code is as follows:

 

myAsyncCallback = new AsyncCallback(AnalogInCallback);
_myTask = new Task();
_myTask.AIChannels.CreateThermocoupleChannel("Dev1/ai0", "", 0.0, 100.0, AIThermocoupleType.K, AITemperatureUnits
.DegreesC);
_myTask.AIChannels.CreateThermocoupleChannel("Dev2/ai1", "", 0.0, 100.0, AIThermocoupleType.K, AITemperatureUnits
.DegreesC);
_myTask.AIChannels.CreateThermocoupleChannel("Dev3/ai2", "", 0.0, 100.0, AIThermocoupleType.K, AITemperatureUnits
.DegreesC);

_myTask.Timing.ConfigureSampleClock("", Convert.ToDouble(1),SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples,1000);

Visual Basic 2010 build problem - National Instruments.Common targeting AMD64

$
0
0

My Visual Basic program uses some Measurement Studio controls and all works well on my development machine.  Having added a Setup Project I get an error message

 

File 'NationalInstruments.Common.Native.dll' targeting 'AMD64' is not compatible with the project's target platform 'x86'

 

How do I change it to target a generic "x86"?

 

Thanks.

Viewing all 1999 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>