LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Daqmx error, bad usage of Daqmx functions , or bad channel/Task configuration

Hi,
I have a NI 9205 , AI card and AI task at this point, I used the automatic generation of createtask in CVI for the 2 tasks, and I receive an error when running my program.
 NON-FATAL RUN-TIME ERROR:   "DVDXTmain.c", line 57, col 5, thread id 0x0000149C:   Function DAQmxStartTask: (return value == -50103 [0xffff3c49]). The specified resource is reserved. The operation could not be completed as specified. Task Name: TorqueAcquisition721InProject  Status Code: -50103

Here is my code

int main (int argc, char *argv[])
    {
    TaskHandle SpeedTask;
    TaskHandle TorqueTask;


    if (InitCVIRTE (0, argv, 0) == 0)
        return -1;    /* out of memory */
    if ((dvdxt = LoadPanel (0, "DVDXT IHM.uir", DVDXT)) < 0)
        return -1;
    DisplayPanel (dvdxt);
   
    /*Demande a l'utilisateur de choisir un chemin pour l'enregistrement des donnees, si l'utilisateur annule cela aura pour effet d'arreter l'application*/
   
    if (FileSelectPopup ("c:\\", "*.txt", "*.txt", "Choose FilePath for data storage", VAL_LOAD_BUTTON, 0, 0, 1, 1, File_Path)
    != VAL_EXISTING_FILE_SELECTED);
   
    else SetCtrlAttribute(dvdxt, DVDXT_File_Browser_Path, ATTR_CTRL_VAL, File_Path);
             
         
    /*Start, and configure DAQ Acquisition*/
   
//    DAQmxLoadTask("Speed Acquisition 721", &SpeedTask);
    CreateSpeedAcquisition721InProject(&SpeedTask);
//    DAQmxLoadTask("Torque Acquisition 721", &TorqueTask);
    CreateTorqueAcquisition721InProject(&TorqueTask);
    DAQmxStartTask (SpeedTask);
    DAQmxStartTask (TorqueTask);

    do {
        DAQmxReadAnalogF64(SpeedTask, 1024, 10, DAQmx_Val_GroupByScanNumber,SpeedArray, 1024, &samplesPerChan,NULL);
        DAQmxReadAnalogF64(TorqueTask, 1024, 10, DAQmx_Val_GroupByScanNumber,TorqueArray, 1024, &samplesPerChan,NULL);
        //SetPlotAttribute(dvdxt, DVDXT_SpeedTorqGraph, SpeedPlot, ATTR_PLOT_YAXIS, VAL_LEFT_YAXIS);
        PlotY(dvdxt, DVDXT_SpeedTorqGraph, SpeedArray, 1024, VAL_DOUBLE, VAL_THIN_LINE, VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_RED);
        //SetPlotAttribute(dvdxt, DVDXT_SpeedTorqGraph, TorquePlot, ATTR_PLOT_YAXIS, VAL_RIGHT_YAXIS);
        PlotY(dvdxt, DVDXT_SpeedTorqGraph, TorqueArray, 1024, VAL_DOUBLE, VAL_THIN_LINE, VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_GREEN);
    }while(Quit==0);
   
    RunUserInterface ();
    DiscardPanel (dvdxt);
    return 0;
    }
I am a CVI rookie so I don't know if it is the right way to do it, I don't really understand how to use DaqmxErrchk functions and , in this part of the code I 'd like to assign one plot the speed one to the left axis and the other one torque to the right axis but I don't understand how to get the plot handle attribute before actually ploting the curve.
Moreover my interface is not responding when acquisition is running on one task only.

Sorry for my lacks but I have a lot of questions.
Thanks by advance.
Olivier

0 Kudos
Message 1 of 6
(3,766 Views)

I cannot replicate your system since I do not have a similar hardware here, but in my opinion you could avoid some hardware conflict by configuring a single task that acquires both of your channels at a time. You can do it in DAQ Assistant by selecting both channels when defining the new task. This will imply you use one TaskHandle, one creation function and one StartTask only in your program.

As per plotting on a different axis, the plot handle is the value returned by PlotY function, which you need to pass to SetPlotAttribute function.
An alternative to this is calling SetCtrlAttribute (dvdxt, DVDXT_SpeedTorqGraph, ATTR_ACTIVE_YAXIS, VAL_LEFT_YAXIS) (or VAL_RIGHT_YAXIS as required) before any plot.

Finally, your program does not responds to user interface events because while in the do loop you do not permit the system to handle UI events. Try adding a call to ProcessSystemEvents () in the loop so that user interaction on controls can be handles by the system.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 6
(3,753 Views)
Hi, and thanks a lot for answering,
I have already done that (goup channel in a single task), but I'd like to know if there's a function allowing me to put the array from one channel in a buffer, and the array from the other channel in an other buffer, because the daqmxreadanalogf64 put all channel data arrays in the same array, and I d like to plot both array on a graph.
here is my new code,

    DAQmxLoadTask("Speed Torque Acquisition 721", &SpeedTorqueTask);
   
    GetCtrlVal(dvdxt, DVDXT_File_Browser_Path, DataFilePath);
   
    DataFileHandle = OpenFile(File_Path, VAL_WRITE_ONLY, VAL_APPEND, VAL_ASCII);
   
    while(Quit==0)
        {
           
            DAQmxSetReadAttribute(SpeedTorqueTask, DAQmx_Read_ChannelsToRead,"Speed Acquisition 721","Torque Acquisition 721");
           
            DAQmxSetBufferAttribute(SpeedTorqueTask, DAQmx_Buf_Input_BufSize, 1024);
           
            DAQmxStartTask(SpeedTorqueTask);
           
            DAQmxReadAnalogF64(SpeedTorqueTask, 1024, 10.0,DAQmx_Val_GroupByScanNumber, SpeedTorqueArray,2048, &samplesPerChan,NULL);
           
            SetCtrlAttribute (dvdxt, DVDXT_SpeedTorqGraph, ATTR_ACTIVE_YAXIS, VAL_LEFT_YAXIS);
           
            PlotY(dvdxt, DVDXT_SpeedTorqGraph,SpeedTorqueArray,1024,VAL_DOUBLE,VAL_THIN_LINE, VAL_ASTERISK, VAL_SOLID, 1, VAL_RED);
           
            //ArrayToFile("c:\\CVIdata.txt", SpeedTorqueArray, VAL_DOUBLE, 1024, 2, VAL_GROUPS_TOGETHER, VAL_GROUPS_AS_COLUMNS, VAL_SEP_BY_TAB,0 , VAL_ASCII, VAL_APPEND);
           
            //FmtFile(DataFileHandle, "%s", DataBuffer);
           
            //WriteFile(DataFileHandle,DataBuffer, 1024);
           
            DAQmxStopTask(SpeedTorqueTask);
                             
            ProcessSystemEvents();

        }

The other issue with is new code is that I d like to write data to a file, I already have a control which contains the path for the data file, so I have tried to pick up this path by getctrlval function and then write to this file using writefile,  but first I must open the file to get a filehandle which doesn't seem to work correctly, and the issue is that the array is 1024 double values and write file only write strings.

So I don't know how to handle that. Do you have any suggestions.

Although the ProcessSystemEvents function work perfectly thanks

Olivier



0 Kudos
Message 3 of 6
(3,750 Views)
The simplest way to read and plot immediately is to set your Read function using DAQmx_Val_GroupByChannel instead og grouping by scan number: this way, all data related to the first channel are grouped in the first 1024 samples of the array, followed by data from the second channel.
Given this, you can simply plot each time a subset of your data, this way:
 
  PlotY (dvdxt, DVDXT_SpeedTorqGraph, SpeedTorqueArray, 1024, VAL_DOUBLE, VAL_THIN_LINE, VAL_ASTERISK, VAL_SOLID, 1, VAL_RED);
  PlotY (dvdxt, DVDXT_SpeedTorqGraph, SpeedTorqueArray + 1024, 1024, VAL_DOUBLE, VAL_THIN_LINE, VAL_ASTERISK, VAL_SOLID, 1, VAL_BLUE);
 
But if you want to read-plot-stream-to-disk all data supposing to read them back in a future, then grouping by scan number is the best option since you have no fragmentation of data while appending them to the same file. In this case you will need to group data together in a dummy array before plotting to the graph, this way:
 
  Decimate (SpeedTorqueArray, 2048, 2, 0, DummyArray);
  PlotY (dvdxt, DVDXT_SpeedTorqGraph, DummyArray, 1024, VAL_DOUBLE, VAL_THIN_LINE, VAL_ASTERISK, VAL_SOLID, 1, VAL_RED);
  Decimate (SpeedTorqueArray + 1, 2048, 2, 0, DummyArray);
  PlotY (dvdxt, DVDXT_SpeedTorqGraph, DummyArray, 1024, VAL_DOUBLE, VAL_THIN_LINE, VAL_ASTERISK, VAL_SOLID, 1, VAL_BLUE);
 
If you want to save in plain text you have no option other than using ArrayToFile with append option or formatting a string of data and appending it to file already open. These are not the fastest option you can choose: saving in bynary format is significantly faster but implies some extra work when reading back your data. There are several examples on how to write data to a file: use the example finder to look for them.


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 6
(3,746 Views)
Hi,
Thanks for this very usefull answer, but how can I do to plot the to curves at the same time , because it seems to plot one after the other , maybe I did not understand well what you said about the two different ways to plot the array, or maybe theres no way to plot the values at the same time, the thing is with Labview to plot at the same time on a graph you just need to build an array of 2 dimension and wire it to the graph, could it be done under CVI?
My other problem is that I receive an error from the DAQmxReadAnalogF64(SpeedTorqueTask, 1024, 10.0,DAQmx_Val_GroupByChannel, SpeedTorqueArray,2048, &samplesPerChan,NULL);
function, which is described below:
 NON-FATAL RUN-TIME ERROR:   "DVDXTmain.c", line 79, col 13, thread id 0x000016E8:   Function DAQmxReadAnalogF64: (return value == -200279 [0xfffcf1a9]). Attempted to read samples that are no longer available. The requested sample was previously available, but has since been overwritten.  Increasing the buffer size, reading the data more frequently, or specifying a fixed number of samples to read instead of reading all available samples might correct the problem. Property: DAQmx_Read_RelativeTo Corresponding Value: DAQmx_Val_CurrReadPos  Property: DAQmx_Read_Offset Corresponding Value:    Task Name: Speed Torque Acquisition 721  Status Code: -200279
I guess I am not using the right values for buffers.

Thanks

Olivier
0 Kudos
Message 5 of 6
(3,742 Views)

Hi Olivier,

The best place to get you started is by having you use the shipping examples. I’ve attached the KnowledgeBase from ni.com/kb that outlines where they are installed on your computer.

NI-DAQmx Shipping Examples in LabWindows/CVI

There is an example called “ContAcq-IntClk” (in the Analog In » Measure Voltage folder) that uses continuous acquire based on the internal clock. It’s equivalent to the example in LabVIEW. All it lacks is writing data to your file, so you can read about the different options for file reads/writes in the NI LabWindows/CVI Help (Start » All Programs » National Instruments » LabWindows CVI x.x » LabWindows CVI x.x Help) under Library References » NI-DAQmx Library » NI-DAQmx C Functions » Write Functions. These can also be found in the NI-DAQmx C References Help under NI-DAQmx C Functions » Write Functions.

If you keep getting error -200279, you can look at this KB:

Why Do I Get Error -200279 When Writing Continuously Acquired Data to a File?

I hope this helps.

Mark E.
Precision DC Product Support Engineer
National Instruments

0 Kudos
Message 6 of 6
(3,713 Views)