LabWindows/CVI

Table of Contents
  • LabWindows/CVI Fundamentals
  • Creating Applications
  • Distributing Applications
  • Library Reference
  • Programmer Reference
  • Hardware Information

Network Stream Data

Network stream data (CNSData) is an object in the LabWindows/CVI Network Streams Library that encapsulates complex data types. National Instruments recommends that you use a native C data type instead of network stream data when performance is critical.

An example of using network stream data is an application that streams a C structure. The following example shows how to convert a C structure to network stream data and vice versa.

typedef struct {

int int_data;
double double_data;
char * description;

} structData;

CNSData ToCNSData(structData data)
{

CNSData cnsData, cnsArray[3];

CNSDataCreateScalar(CNSTypeInt32, &cnsArray[0], data.int_data);
CNSDataCreateScalar(CNSTypeDouble, &cnsArray[1], data.double_data);
CNSDataCreateScalar(CNSTypeString, &cnsArray[2], data.description);

// Create the CNSData containing the struct
CNSDataCreateStruct(cnsArray, 3, &cnsData);

// Discard the intermediate CNSData objects
CNSDataDiscard(cnsArray[0]);
CNSDataDiscard(cnsArray[1]);
CNSDataDiscard(cnsArray[2]);

// Return the CNSData containing the struct
return cnsData;

}

structData FromCNSData(CNSData cnsData)
{

structData data;
CNSData cnsArray[3];

// Unpack the CNSData structure
CNSDataGetStructFields(cnsData, cnsArray, 3);

// Get the data from the CNSData objects
CNSDataGetScalarValue(cnsArray[0], &data.int_data);
CNSDataGetScalarValue(cnsArray[1], &data.double_data);
CNSDataGetScalarValue(cnsArray[2], &data.description); // needs to be freed using CNSFreeMemory

// Discard the intermediate CNSData objects
CNSDataDiscard(cnsArray[0]);
CNSDataDiscard(cnsArray[1]);
CNSDataDiscard(cnsArray[2]);

return data;

}

Log in to get a better experience