Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

How to read TDMS file use DDC_GetDat​aValuesStr​ing in C language.

1. Below code is correct, because the numDataValues is one, machine=sibot

char ss[10]={0};
    char *strMachine=new char[1];
    *strMachine=ss[10];
    nullChk (strMachine = (char *) malloc (sizeof (char) * (unsigned int)numDataValues));
    ddcChk (DDC_GetDataValuesString (channels[i], 0, (unsigned int)numDataValues, &strMachine));
    printf ("Channel value for Machine : %s\n", strMachine);

---then show "nel value for Machine : sibot"

 

2. But when the numDataValues is more one, I can't get all the data in the TDMS file, only can get the first one.

eg:

data one is FI,

data two is O

but I only can get FI....

what's wrong?? How to solve it?? The data format as attachment.

0 Kudos
Message 1 of 3
(5,632 Views)

Hi KittyDeng,

 

I guess the problem is from here:

char *strMachine=new char[1];

You allocated a char array of only 1 element which will not hold as many chars.

The best way to solve the problem is to allocate more memory than that of the data, where in your case, you can write:

char *strMachine=new char[20];//or set more than 20

 

Hope this helps.

 

Zhiqiang Tu

 

NISH AE

0 Kudos
Message 2 of 3
(5,608 Views)

Actually, when get the array data, I have modified the code:

ddcChk (DDC_GetNumDataValues (channels[i], &numDataValues));  //获取数据长度

char ss[5]={0};
  char *strCode=new char[numDataValues];
  *strCode=ss[5];
   ddcChk (DDC_GetDataValuesString (channels[i], 0, 7, &strCode));
  printf ("Channel length for strCode : %s\n", strCode);

0 Kudos
Message 3 of 3
(5,606 Views)