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