LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Reading network variables as strings

I'm just learning LabWindows/CVI, but I am an experienced C programmer.  I have setup several Network Variables for testing using the NI Distributed System Manager.  My LabWindows program has no problem reading int and double data types, but I have one variable typed as a string and I seem unable to read the value.  I used the CNVCreateSubscriber to create my callback.  When I change the string value, my callback fires as expected, and the type is correctly set as CNVstring.  However, when I try to use CNVGetArrayDataValue, I do not receive my string, but rather I generate run time errors referring to array size issues.  My receiving array is 500 characters, and the network variable only contains 12 characters, so there should be no problem.  Any ideas?

 

Here's my callback routine which correctly reads the int and double, but fails on the string:

 

void CVICALLBACK NetDataCallbackDBL (void * handle, CNVData data, void * callbackData)
{
int    er;
char l[500];
CNVDataType ty;
unsigned long dm;

    CNVGetDataType(data, &ty, &dm);                //Get data handle, type, and dimensions for this call
    switch (ty)
    {
        case CNVDouble:
            CNVGetScalarDataValue (data, ty, &TestDBL);                  //Get floating point data
            sprintf(l, "Double=%8.2f", TestDBL++);
            InsertTextBoxLine (panelHandle, PANEL_MIKESTEXT, -1, l);           //Report data on screen in text box
            CNVSetScalarDataValue (data, ty, TestDBL);
            break;
            
        case CNVInt32:
            CNVGetScalarDataValue (data, ty, &TestINT32);                //Get int data
            sprintf(l, "Int=%d", TestINT32++);
            InsertTextBoxLine (panelHandle, PANEL_MIKESTEXT, -1, l);              //Report in text box
            CNVSetScalarDataValue (data, ty, TestINT32);
            break;
            
        case CNVString:
            CNVGetArrayDataValue (data, ty, l, dm);                           //FAIL!!!  I have tried with dm and with a constant for the size
            InsertTextBoxLine (panelHandle, PANEL_MIKESTEXT, -1, l);         //Report in text box
            break;
    }
        
}

0 Kudos
Message 1 of 2
(3,343 Views)

OK, never mind.  Apparently, even though the docs say in several places that strings are treated as arrays of chars (pretty standard), for network variables strings are actually treated as scalars.  Using the CNVGetScalarDataValue function gets the string, but you have to use a double indirect pointer to get it there. Bizarre, but ok now that I understand it!  The docs could use a bit more clarity on this point.

Message 2 of 2
(3,335 Views)