12-20-2013 08:25 AM
Sorry but I already did that before writing this post :
http://search.ni.com/nisearch/app/main/p/bot/no/ap/global/lang/es/pg/1/q/DAQmxCreateAOCurrentChan/ give me 8 answers : 3 answer are doubled then in reality I'm getting 5 answers :
- one with give me the definition of the function -> use it to understand what is the meaning of arguments
- one with the list of function to create Create Analog Output Channel -> not very useful
- one with the mapping of the NI-DAQmx -> not very useful
- one with an other question on this forum but I'm thinking a bit too old because one of the argument are not the same thant in the definition function DAQmx_Val_CurrentUnits2_Amps, instead of DAQmx_Val_Amps or DAQmx_Val_FromCustomScale. Anyway I look an try to follow what was written without success
- and the ultimate is a link to this question on the forum. -> didn't give my any hint 😉
Is there a other research page than the one on the top of the page which could give me example? (obviously I also look on google to check if I could not find an answer in an other forum/website)
Regards,
Mélaine
12-30-2013 09:57 AM
I'm going to sum up :
I want to be able to communicate with device NI 9203 and NI 9265 with NI-DAQmx. After reading the documentation it seems than I need to use a analog method
DAQmxCreateAOCurrentChan(taskHandle, tmp.c_str(),"", 0, 0.02, DAQmx_Val_Amps, NULL);
and
DAQmxReadAnalogF64(taskHandle, 1 , 10, DAQmx_Val_GroupByChannel, AIn_ReadArray, 1 , &sampsPerChannelRead, NULL);
I used in argument what seems for me the more correct (after looking for example on the net), but I couldn't success to get or send informations. As I can communicate with other device, I'm supposing that some argument are not correct but so far I couldn't find which one are not good.
So my question is :
- are my arguments are good?
- do you see any mistake in my reasonment or my arguments?
- are they an other way to communicate?
Thanks for any explicit answer which could help me
Mélaine
01-06-2014 06:53 AM
I have a doubt about your code,
DAQmxCreateAOCurrentChan(taskHandle, tmp.c_str(),"", 0, 0.02, DAQmx_Val_Amps, NULL);
Where you declared tmp.c_str(), in this place you should declare the physical channel name, is this your physical channel name of your communication? To create the the communication you should follow this:
DAQmxCreateAOCurrentChan ("Here you put your Task Handle", "Here you put the Physical Channel", "Here you put the Name To Assign To Channel", Here you put the Min Value, Here you put the Max Value, Here the Units, "Here you put the Custom Scale Name");
01-06-2014 07:49 AM
No sorry the problem is not here,
as I wrote it in my first post,
deviceName_ = Dev1 por NI6008 or cDAQ1ModX for NI9203 and NI9265 (we replace X by the good number given but MAX)
std::string tmp = deviceName_;
then the tmp get the correct physical channel name of my communication (I checked it many times).
I'm developping a generic software and it's working with all other device I tried so the problem is not there it's just a developping writting (not this method but other for digital communication and DAQmxCreateAIVoltageChan).
So the problem is not on this point (I also tried written in hard but doubt without getting better result)
01-06-2014 08:07 AM - edited 01-06-2014 08:10 AM
It seems that your code is right considering the way you declared the communication, so I tried to use your code simulating your device here, but it returned me compilation errors, so I created a task using CVI (NI tool to use C language to communicate with our hardware) to generate the signal under your conditions and it returned me this code:
DAQTaskInProject.h
//**************************************************************************
//* WARNING: This file was automatically generated. Any changes you make *
//* to this file will be lost if you generate the file again. *
//**************************************************************************
#ifndef DAQTASKINPROJECT_INCLUDE
#define DAQTASKINPROJECT_INCLUDE
#include <NIDAQmx.h>
#ifdef __cplusplus
extern "C" {
#endif
//**************************************************************************
//* This generated function configures your DAQmx task. *
//* *
//* Follow these steps to use this generated function: *
//* 1) Define a task handle variable in your program. *
//* 2) Call the generated function. *
//* 3) Use the returned task handle as a parameter to other DAQmx *
//* functions. *
//* 4) Clear the task handle when you finish. *
//* *
//* TaskHandle task = 0; *
//* CreateDAQTask(&task); *
//* <use the DAQmx task handle> *
//* DAQmxClearTask(task); *
//* *
//**************************************************************************
int32 CreateDAQTaskInProject(TaskHandle *taskOut1);
#ifdef __cplusplus
}
#endif
#endif // ifndef DAQTASKINPROJECT_INCLUDE
DAQTaskInProject.c
//**************************************************************************
//* WARNING: This file was automatically generated. Any changes you make *
//* to this file will be lost if you generate the file again. *
//**************************************************************************
#include <ansi_c.h>
#include <NIDAQmx.h>
#define DAQmxErrChk(functionCall) if( (DAQmxError=(functionCall))<0 ) goto Error; else
//**************************************************************************
//* This generated function configures your DAQmx task. *
//* *
//* Follow these steps to use this generated function: *
//* 1) Define a task handle variable in your program. *
//* 2) Call the generated function. *
//* 3) Use the returned task handle as a parameter to other DAQmx *
//* functions. *
//* 4) Clear the task handle when you finish. *
//* *
//* TaskHandle task = 0; *
//* CreateDAQTask(&task); *
//* <use the DAQmx task handle> *
//* DAQmxClearTask(task); *
//* *
//**************************************************************************
int32 CreateDAQTaskInProject(TaskHandle *taskOut1)
{
int32 DAQmxError = DAQmxSuccess;
TaskHandle taskOut;
DAQmxErrChk(DAQmxCreateTask("DAQTaskInProject", &taskOut));
DAQmxErrChk(DAQmxCreateAOCurrentChan(taskOut, "Dev2/ao0",
"CurrentOut", 0, 0.02,
DAQmx_Val_Amps, ""));
DAQmxErrChk(DAQmxSetChanAttribute(taskOut, "CurrentOut",
DAQmx_AO_DataXferReqCond, DAQmx_Val_OnBrdMemHalfFullOrLess));
DAQmxErrChk(DAQmxCfgSampClkTiming(taskOut, "",
1000, DAQmx_Val_Rising,
DAQmx_Val_ContSamps, 100));
DAQmxErrChk(DAQmxSetWriteAttribute(taskOut, DAQmx_Write_RegenMode, DAQmx_Val_AllowRegen));
*taskOut1 = taskOut;
Error:
return DAQmxError;
}
01-06-2014 08:24 AM
You can't use my code, it's a c++ class and I just copy/paste a little part of the .cpp file (missing the rest of the file and the .h)
Holy s*****,
after reading your code, I just notice on problem in my code (for the input part) :
I'm using the method DAQmxCreateAOCurrentChan instead of DAQmxCreateAIVoltageChan
That is the FIRST problem. I'm going to fix that and test again, if it's work, it'll be perfect.
After I'll need to find the problem with the output method but it's the first step 🙂
Thank, I could test it in the laboratory this thursday and give a feed back.
04-29-2014 08:08 PM
Hi,
I'm new at NI forum community. I'm researcher in structural dynamics and recently I started working using a NI9234 and compactDAQ. I want to develop a small program in VC++ or LabView to read accelerations. Because I'm new in this community I dont know how to creat a new topic, can someone help me?
Best regards, escus4
05-05-2014 04:21 PM
Hi
did you manage to write your reader?
Here a type of example code (simplified) I'm using for test with could work for you : I'm reading the value of 4 ports (one at each time but you can read more than one with one request I'm thinking) and doing it 10 iterations.
#include "NIDAQmx.h"
#include <stdint.h>
#include <string>
#include <iostream>
#include <sstream>
#include <windows.h>
#include <winbase.h>
int main (int argc, char **argv) {
TaskHandle taskHandle;
int loop = 10;
while(loop){
int port = 0;
while(port<4){
double AIn_ReadArray[64];
int32 sampsPerChannelRead;
std::stringstream convert;
convert << port;
std::string tmp ="cDAQ1Mod1";
tmp.append("/ai").append(convert.str());
DAQmxCreateTask ("", &taskHandle);
DAQmxCreateAICurrentChan(taskHandle,tmp.c_str(),"",DAQmx_Val_Cfg_Default,0.0,0.02,DAQmx_Val_Amps,DAQmx_Val_Default,138,NULL);
/*********************************************/
// DAQmx Read Code
/*********************************************/
DAQmxStartTask(taskHandle);
AIn_ReadArray[0] = 0;
int32 error =DAQmxReadAnalogF64(taskHandle, 1 , 10, DAQmx_Val_GroupByChannel, AIn_ReadArray, 1 , &sampsPerChannelRead, NULL);
//printf(" Entree analogique 0 = %lf Volts \n", AIn_ReadArray[0]);
//printf(" Entree analogique 1 = %lf Volts \n", AIn_ReadArray[1]);
//printf(" Entree analogique 2 = %lf Volts \n", AIn_ReadArray[2]);
//printf(" Entree analogique 3 = %lf Volts \n\n", AIn_ReadArray[3]);
DAQmxStopTask(taskHandle);
DAQmxClearTask (taskHandle);
double retval = AIn_ReadArray[0];
DAQmxStopTask(taskHandle);
DAQmxClearTask (taskHandle);
port++;
}
loop--;
Sleep(2000);
}
}
05-05-2014 05:23 PM
I'm going to test this code & I will post afterwards.
I think i can manage myself to save the readings to a txt file.
Thanks a lot
05-08-2014 02:52 PM
it worked well.
Thanks a lot again 😉