10-08-2015 12:22 PM
Hi all
simple system configuration: AI channel is setup using NI max and also using a scale which is setup in NI Max.
Once the system is up and running and the program task started and reading from the DAQ everything is fine. now what i want to do is get the value of a channel and zero the reading that the DAQmx is reading on the channel by chaning the intercept of the linear scale. i tried getting the intercept value and sudtracting the real value from the exisiting intercept and setting the DAQmxSetScaleAttribute with the new linear value and nothing changes on the channel. Possible solutions i have tried stopping and restarting the task but not clearing and reloading the task.
I also tried DAQmxSaveScale but the value in NImax for the intercept does not change either.
is there somehting in the order of calls that has to happen, or can i even change the scale on a task without clearing and reloading the task??
Solved! Go to Solution.
10-08-2015 12:29 PM
nevermind it works .. if there was only a way to delete a post
10-08-2015 12:52 PM
Why delete the question - you could post your solution, maybe it will also help someone else
10-09-2015 02:26 PM
ok this is how i got it to work note again that the system is configured using NImax and the all the AI channels are in one task, also one major feature is that i am using the DAQmxRegisterEveryNSamplesEvent function. also each channel has its own scale.
first find what you need to find is the offset, next you need to recalcualte the max and min for the range of that channel and save everthing.
DAQmxGetScaleAttribute ("1Dist", DAQmx_Scale_Lin_YIntercept, &readOffset); \\get the existing scale value
stopDAQ();
GetCtrlAttribute(panelManual,MANUAL_1POS,ATTR_CTRL_VAL,&actualReading); \\reading off the DAQ
newOffset = (actualReading + readOffset)*-1; \\calcualte offset
err = DAQmxGetChanAttribute (gDAQTaskHandleAI, "1_Unit_Ext_Pos", DAQmx_AI_Max, &max, NULL); \\get NIMAX cahnnel info
err = DAQmxGetChanAttribute (gDAQTaskHandleAI, "1_Unit_Ext_Pos", DAQmx_AI_Min, &min,NULL); \\get NIMAX cahnnel info
newMax= max+newOffset;
max=newMax; \\ this will be ediedited what i did was made max a int to get rid of decimal points
newMin = min+newOffset;
min=newMin; \\ this will be ediedited what i did was made max a int to get rid of decimal points
DAQmxClearTask(gDAQTaskHandleAI); \\clear the task because of the attached DAQmxRegisterEveryNSamplesEvent will thow errors because it is attached to the task
DAQmxLoadTask (DAQMX_TASK_TITLE_AI, &gDAQTaskHandleAI);
err = DAQmxSetScaleAttribute("1_Act_Ext_Dist",DAQmx_Scale_Lin_YIntercept,newOffset);
err = DAQmxSaveScale ("1_Act_Ext_Dist", "1_Act_Ext_Dist", "",DAQmx_Val_Save_Overwrite | DAQmx_Val_Save_AllowInteractiveEditing | DAQmx_Val_Save_AllowInteractiveDeletion);
err = DAQmxSetChanAttribute (gDAQTaskHandleAI, "1_Unit_Ext_Pos", DAQmx_AI_Max, max,NULL);
err = DAQmxSetChanAttribute (gDAQTaskHandleAI, "1_Unit_Ext_Pos", DAQmx_AI_Min, min, NULL);
err = DAQmxSaveTask (gDAQTaskHandleAI, DAQMX_TASK_TITLE_AI, "",
DAQmx_Val_Save_Overwrite |DAQmx_Val_Save_AllowInteractiveEditing | DAQmx_Val_Save_AllowInteractiveDeletion);
DAQmxClearTask(gDAQTaskHandleAI);
DAQmxLoadTask (DAQMX_TASK_TITLE_AI, &gDAQTaskHandleAI);
GetCtrlAttribute(panelDAQ,DAQ_PANEL_SampPerChannel,ATTR_CTRL_VAL,&sampsPerChan);
DAQmxRegisterEveryNSamplesEvent(gDAQTaskHandleAI,DAQmx_Val_Acquired_Into_Buffer,sampsPerChan,0,EveryNSamplesCallback,NULL);
startDAQ();
10-09-2015 02:37 PM
i was cut off from the last message. the information was never saving on the NIMAX but with the code above it does now. the reason i had to
1) clear, was to remove the attahced EverySample routine
2) load so you can read what is on the task
3)set and save
4) clear again this is unclear as to why it doesnt save but after you clear it it does
5) reload the new config
6) restart
it would be nice if you didnt have to clear, and than reload and restart a task to change a channel property. but after i clean up the code above it should be gut enough.