Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem of comminucation (analog) with NI 9203 and NI 9265 using NI-DAQmx

Hello, I need to make a bridge between NI devices and an internal software.

 

I've already made one which working perfectly with NI USB 6008 but I can't manage to get/send any value from NI9203 and NI9265  (we also tried to connect the sensor/actuator to the NI USB 6008 and it's working).

I've changed from DAQmxCreateAIVoltageChan to DAQmxCreateAOCurrentChan but it seems I'm still missing something!!!


My problem is only for analog input/output : it's working well with digital which give me the information that the  connection between my bridge and the device is done correctly (I use MAX to get the right name of the port).

 

Here the example of the code I've used :

********* info *****************

deviceName_ = Dev1 por NI6008 or cDAQ1ModX for NI9203 and NI9265 (we replace X by the good number given but MAX)

******************************************************************************

double NIGeneric::analogIn(int channel, __u8 range, bool& nan){
    fflush(stdout);
    double AIn_ReadArray[64];
    int32 sampsPerChannelRead;

    std::string tmp =  deviceName_;
    std::stringstream convert;
    convert << channel;
    tmp.append("/ai").append(convert.str());
    DAQmxCreateTask ("", &taskHandle);
    //DAQmxCreateAIVoltageChan(taskHandle,tmp.c_str() , "", DAQmx_Val_Cfg_Default, 0, 10.0, DAQmx_Val_Volts, NULL);
    DAQmxCreateAOCurrentChan(taskHandle, tmp.c_str(),"", 0, 0.02, DAQmx_Val_Amps, NULL);
    DAQmxStartTask(taskHandle);
    AIn_ReadArray[0] = 0;
    int32 error =DAQmxReadAnalogF64(taskHandle, 1 , 10, DAQmx_Val_GroupByChannel, AIn_ReadArray, 1 , &sampsPerChannelRead, NULL);
    DAQmxStopTask(taskHandle);
    DAQmxClearTask (taskHandle);
    double retval = AIn_ReadArray[0];
  return retval;

}

void NIGeneric::analogOut(int port, __u16 value){
    int32 written = 0;    
    float64 data_v_out = value;
    std::stringstream convert;
    convert << port;
    std::string tmp =deviceName_;
    if(deviceName_.compare("Dev1")==0) tmp = std::string("dev1").append("/ao").append(convert.str());// beeeurrrrrrkkkk
    else tmp.append("/ao").append(convert.str());

    DAQmxCreateTask ("", &taskHandle);
    //DAQmxCreateAOVoltageChan(taskHandle, tmp.c_str(),"",0.0,5.0,DAQmx_Val_Volts,NULL);
    DAQmxCreateAOCurrentChan(taskHandle, tmp.c_str(),"", 0, 0.02, DAQmx_Val_Amps, NULL);
    DAQmxSetSampTimingType(taskHandle, DAQmx_Val_OnDemand);
    DAQmxStartTask(taskHandle);
    DAQmxWriteAnalogF64(taskHandle,1,0,1.0,DAQmx_Val_GroupByChannel,&data_v_out,&written,NULL);
    DAQmxStopTask(taskHandle);
    DAQmxClearTask (taskHandle);
}

********************************************

 

If someone could give me an hint on what missing or where is the wrong information, I'll be more than happy. 🙂

 

Thank You

Mélaine

0 Kudos
Message 1 of 20
(7,323 Views)

Nobody to give me an hint of what is not working?  😞

I need to visit the client this tuesday and they hope I could bring something that's working this time!!!

0 Kudos
Message 2 of 20
(7,302 Views)

Hi,

 

There's an easy way to communicate using DAQmx Tasks, and you can create them using the Measurement Studio or Visual Studio, and the code to perform the communication is automatically created for you.

 

In this video, a NI engineer shows how to do it:

 

http://www.ni.com/video/2565/en/

 

If you have any problem, please inform us.

 

Thiago Matos
Engenharia de Aplicações
National Instruments Brasil
0 Kudos
Message 3 of 20
(7,285 Views)

Thanks, I'm going to look this a bit more but my software is in C++ and NI Mesurement Studio is for dot net (anyway to insert the code in my software, I need to adapt it so perhaps with .net is good enough to make the shift).

 

Otherwise do you see an error in the lines, I published? (I just addapt the code from NI6008 (voltage device) to current devise.

0 Kudos
Message 4 of 20
(7,271 Views)

It's look like I can't use NI Measurement Studio with Visual studio express 😕

 

I juste need an example to read or write with Current output or input (I'll manage after to adapt my code) which work with  NI 9203 and NI 9265 (I don't have them at my office and need to take a full day to try an installation so if I could have something that work (or should work) before going on the experiental place it's better.

 

Do you see any mistake in the argument of the function  ? or somewhere else in the code I wrote here?

DAQmxCreateAOCurrentChan(taskHandle,cDAQ1Mod1,"", 0, 0.02, DAQmx_Val_Amps, NULL);

 

Thanks,

Mélaine

0 Kudos
Message 5 of 20
(7,238 Views)

Hi Mélaine,

 

There are a lot of things to consider, because depending on the conditions, the code you should use is different. If you're using DAQmx, you have a folder in your computer with many examples codes showing how to acquire and generate data considering different conditions. In your Windows, just go to "Start", then "All Programs", after this go to "National Instruments", then "NI-DAQmx", then go to "Text-Based Code Support" and then "NI-DAQmx ANSI C Examples". In this folder you can find examples showing how to acquire and generate different types of data in different ways and conditions.

 

If you have any problem doing it, just tell me.

Thiago Matos
Engenharia de Aplicações
National Instruments Brasil
0 Kudos
Message 6 of 20
(7,211 Views)

Hello,

 

I know this folder it's from there I build my first example for NI6008 but I couldn't find an example with the function DAQmxCreateAOCurrentChan (I'm on linux now for an other project so couldn't check again but I'm pretty sure of what I'm writting)

 

That why I thought that if I just change DAQmxCreateAIVoltageChan by  DAQmxCreateAOCurrentChan (with the corrects arguments) it will be enough (I also found after a little research an example en the net for example http://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=7&ved=0CHEQFjAG&url=http%3A%2F%2Fsoctra... but they don't using the same device (the port adress is Dev1/a0 where for mine is cDAQ1ModX, with X=1,2,3,4 depending of the module)

 

I know that the connection is working because I could interact with the digital device, so my only others possibilities is a problem with the arguments or function to call.

 

My goal is to be able to read the value of a sensor when I call my function or send the order to the actuator when I call an other function (depending also of the device NI 9203 is for reading  and NI 9265 is for sending order).

 

Then I followed the steps of my first post but I couldn't get a success in the communication (which working with a fast labview test).

 

Thanks

0 Kudos
Message 7 of 20
(7,206 Views)

I just didn't understand how could you get it working with digital I/O as you said, considering that NI 9203 and NI 9265 are only analog I/O. Other problem now that you said that you're using Linux is that the drivers a different, so you're not using Measrement Studio and the Linux drivers for DAQmx are different, so the codes and functions used to access it are different, you can't use the same functions as you use in windows because the driver is different.

Thiago Matos
Engenharia de Aplicações
National Instruments Brasil
0 Kudos
Message 8 of 20
(7,202 Views)

Sorry it looks like, I lost you :


I'm not working on linux on this problem (but it's not the only project I'm working on some use Windows  (for example if I want to use NI products) and other Linux. I was just writting this to tell you that I didn't make a check today for examples with DAQmxCreateAOCurrentChan but I did the previous week and at the beginning of this week.

 

For the digital I/O, it's used from different device on the same "armoir", it was just to tell that the address cDAQ1ModX seems to be correct (and it's also what is written here http://zone.ni.com/reference/en-XX/help/370466W-01/mxdevconsid/cdaqphychannels/ ). I didn't write the no of the device for the digital I/O because they working and then it's not an important information to help me.

 

 

So the problem is still using NI device with NI-DAQmx on windows for device with need a call to DAQmxCreateAOCurrentChan

 

Mélaine

 

0 Kudos
Message 9 of 20
(7,199 Views)

If you go the National Instruments site and type this funtion in the search, you'll find a lot of references and examples on how you can use it.

Thiago Matos
Engenharia de Aplicações
National Instruments Brasil
0 Kudos
Message 10 of 20
(7,191 Views)