Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Do I have to use measurement Studio to use C#?

I was wondering if anyone could help me with using NIDAQ with C# but without having to buy Measurement Studio. My company has an Acquisition program that was done in VB6 which uses a C++ DLL to do all the processing and acquisition, I would like to convert the program to C# and .NET but don't have very much/any experience using the DAQ and .net.
Is there any kind of a tutorial or walkthrough  on how to do this?

Any Help would be great, thanks in advance
0 Kudos
Message 1 of 7
(4,095 Views)
Hello

Since you are in the process of creating a new DAQ application from scratch, I would recommend that you using the DAQmx .NET API that ships with the DAQmx driver. Checking out the daq quick guide after installing DAQmx (found under Start >> Programs >> National Instruments >> NI-DAQ).

This and this post has some information as well.

You can find the most current version of the NI-DAQ driver from here.

The DAQmx driver installs C# and VB.NET shipping examples as well for reference. The Help is fully integrated into VS 2003 and contains the function reference and concept topics as well.
Bilal Durrani
NI
0 Kudos
Message 2 of 7
(4,068 Views)
The C# examples I have won't compile. For instance I can't compile

c:\Program Files\National Instruments\MeasurementStudioVS2003\DotNET\Examples\DAQmx\Analog In\Measure Voltage\AcqOneVoltageSample\Cs\MainForm.cs

I get a message like ' the type or namespace name DAQmx does not exist in the class or namespace NationalInstruments.'

Can you tell me how to compile them?

Thanks,

Peter


0 Kudos
Message 3 of 7
(3,921 Views)
Peter,

That problem usually means, either you don't have the DAQmx drivers installed, or they are not properly installed. Please double check and verify that they are installed. You may also want to try to reinstall them, and/or update to the newest version while you are at it. You can find that latest DAQmx drivers here. Try that, and let us know how it goes.

-GDE
0 Kudos
Message 4 of 7
(3,905 Views)

I reinstalled the driver and I still can't get the examples to compile. Let me be more specific about what I am doing.

I tried to compile the example file C:\Program Files\National Instruments\MeasurementStudioVS2003\DotNET\Examples\DAQmx\Analog Out\Generate Voltage\GenVoltageUpdate\Cs\MainForm.cs  using the c# compiler that comes standard with XP. In my case this is located at C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\csc.exe.

I get the following error : the type or namespace 'DAQmx' does not exist in the class or namespace 'NationalInstruments'


Thanks for your help.

Peter

0 Kudos
Message 5 of 7
(3,894 Views)

Peter,

I think the problem is that you need to reference the DAQ assemblies. These are located at:

C:\Program Files\National Instruments\MeasurementStudioVS2003\DotNET\Assemblies\Current\NationalInstruments.DAQmx.dll

 

Try adding that reference, and see if that helps out at all.

 

-GDE

0 Kudos
Message 6 of 7
(3,867 Views)

Dear GDE,

Referencing the assemblies solved the problem. Thanks.

I had to put NationalInstruments.Common.dll and NationalInstruments.DAQmx.dll in the same directory as my code to get it to compile.  When I did this with the example programs provided by National Instruments they did not compile. I am not sure why. The examples programs are quite long because they are windows applications. I just want to set and read voltages so I wrote the short program below which I did get to compile.

using System;
using NationalInstruments.DAQmx;
class daq{

 public static void Main() {

  //Set the voltage of analog output AO0 on Dev1 to 2.33 Volts
  Task writeAO0Task = new Task();
  writeAO0Task.AOChannels.CreateVoltageChannel("/Dev1/ao0", "aoChannel",-10, 10, AOVoltageUnits.Volts);
  AnalogSingleChannelWriter AO0writer = new AnalogSingleChannelWriter(writeAO0Task.Stream);
  AO0writer.WriteSingleSample(true, 2.33);

  //Read the voltage at analoginput AI0 on Dev1
  int samplefrequency = 100000;
  int numberofsamples = 10000;
  Task readAI0Task = new Task();
  readAI0Task.AIChannels.CreateVoltageChannel("/Dev1/ai0","aichannel", (AITerminalConfiguration)(-1),-10,10,AIVoltageUnits.Volts); 
  readAI0Task.Timing.ConfigureSampleClock("",samplefrequency, SampleClockActiveEdge.Rising, SampleQuantityMode.FiniteSamples, numberofsamples);
  readAI0Task.Control(TaskAction.Verify);
  AnalogSingleChannelReader AI0reader = new AnalogSingleChannelReader(readAI0Task.Stream);
  double [] data = AI0reader.ReadMultiSample(numberofsamples);
  double avg = 0;
  double avgsquared = 0;
  for (int i=0; i<numberofsamples; i++) {
    avg = avg + data[i];
    avgsquared = avgsquared + data[i]*data[i];
  }
  double stddev = System.Math.Sqrt(avgsquared/numberofsamples-avg*avg/(numberofsamples*numberofsamples));
  avg=avg/numberofsamples;
  Console.WriteLine("The voltage at Dev1/AI0 is "+avg+" +/- "+stddev);
  writeAO0Task.Dispose();
  readAI0Task.Dispose();
 }
}

0 Kudos
Message 7 of 7
(3,843 Views)