LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Get tdms Channel names in matlab

I have to use matlab for signal analysis. For this I have to convert the tdms files into mat files. It almost worked perfectly with the  tdms matlab example from the NI homepage. But actually I've the problem to get the channelnames so that I can assign the channel data to the specific variablename (==channelname).
How can I get the channelname as a string out of my tdms file in matlab?

Thanks a lot!
0 Kudos
Message 1 of 47
(7,004 Views)
Mechi,
the readme file offers the following commands which are supported by the dll:
DDC_GetChannelProperty -> DDC_Channel_Name

If this is not working a simple workaround would be to use a separate channel containing the channel names of all other.

Please let me know the result.
Thanks,
ThSa






0 Kudos
Message 2 of 47
(6,957 Views)
We now have example code online for using TDMS and TDM in Matlab specifically. It does contain a mechanism to list group names and channel names:
http://digital.ni.com/public.nsf/allkb/0EEADA99DC7D00A4862572E30037C3A2

Hope that helps,
Herbert
0 Kudos
Message 3 of 47
(6,940 Views)
Thank you for your replies!
I used the specified example form the NI-Homepage for building my own script. Therefore I modificated it so that it can read tdms. But I didn't find the capability getting the channel names...Smiley Sad So I tried the DDC_GetChannelProperty yesterday and it worked particulary.  Unfortunatly now I don't know how to convert result into a string... (My C-/matlab skills are very poor)

%Declaration
    pchan = libpointer('uint64Ptr', 0);

%Call in a for loop
    calllib('nilibddc', 'DDC_GetChannelProperty', pchannel.Value(chnindex), 'name', pchan, 64);

%Result:
>> pchan.Value

ans =

    13846386960326497 (uint64)

But how can I make from this array of integer a string with letters?!
If I declare the pointer as 'stringPtr', the function returns an empty string...

%******************************************************************************************************************

Another thing made me wondering: In the example there is a "switch-case" to prepare the buffer for the needed datatype. When reading a tdms the switch-value is '30'- For that value there isn't a case so I added the case 30 with the buffervaluetype:

case 30
                pdata = libpointer('doublePtr', 1:pdatalen.Value);

This works but maybe this causes the problem specified above?!




regards

Jens

P.S.: Meanwhile I found another way to get the information I needed through a VI and the "Math Interface Toolkit"  using the generated dll in matlab. The vi opens the tdms file,  reads the data and  channelnames and then passing it through a array to matlab. This works great on my computer... unfortunatly our customers/ partners don't have LabView nor the Interface Toolkit so I would like to use the matlab 'nilibddc'
0 Kudos
Message 4 of 47
(6,934 Views)
Morning Mechi,

to use the Math Interface Toolkit was my first mind but with this solution you would be very constricted.
Your approach is quiet well but you have one simple flaw.

Use the following code to get the channel names:

                names = libpointer('uint8Ptr',1:10);
                calllib('nilibddc', 'DDC_GetChannelProperty', pchannel.Value(chnindex), 'Name', names, 10);
                disp ('channel:');
                disp (char(names.Value));

The expression "1:10" allocates an array for 10 characters (if you have longer channel names don't forget to increase this number otherwise you will get a truncated name) and because of the fact that Matlab uses the byte character and not the string character use uint8Ptr instead of 64. The last index in the function call DDC_GetChannelProperty (in this example 10) should match the array length.

To convert the byte array to a readable string use char(variablename).

Hope that helps,
ThSa
0 Kudos
Message 5 of 47
(6,919 Views)
FANTASTIC Smiley Very Happy

Thank you!!
0 Kudos
Message 6 of 47
(6,906 Views)

Hi,

When I use the program loadTDM, it works with the.tdm file Demo1.tdm that comes with the program. However, it doesen't work if I replace this file  with my own data aquisition file. Matlab gives me the following error.

Warning: The library class 'nilibddc' already exists.  Use a classname alias.
> In loadlibrary at 254
  In loadTDM at 16
??? No appropriate method or public field Value for class handle.

Error in ==> loadTDM at 84
    calllib('nilibddc', 'DDC_GetDataValues', pchannel.Value(chnindex), 0, pdatalen.Value, pdata);

 I am not sure what the error message means. Even when I use this program to convert a .tdms file I obtained by running the example Express write data (time and frequency).vi, it still gives me the same error.

Thank you,

Sunitha.

 

 

0 Kudos
Message 7 of 47
(6,854 Views)
Sunitha,
sorry for the delayed reply, I was out of town last week.
I am not sure what causes this error, but I can test it on my machine with Diadem or LabVIEW to see whether a general problem exists or not.

FYI:
To get information about the status of every calllib command simply use the following syntax in front of it (this one is only valuable when the Matlab compiler runs without a failure):
[error]=calllib (.....);
disp (error);
or
[error]=calllib (....)


Thanks,
ThSa
0 Kudos
Message 8 of 47
(6,811 Views)

Hi,

My company has Matlab 6.1. I am wondering if it will work with 6.1?

0 Kudos
Message 9 of 47
(6,692 Views)

Hi Thomas,

 

Can we store the data in form of arrays, where array name is same as channel name? (Each channel is a 1 dimensional array).

I tried doing this in the following way:

AA(chnindex,:)=pdata.Value;

but i couldnt get the array name same as channel name.

 

I will really appreciate if you can help me out.

 

Thanks very much

 

0 Kudos
Message 10 of 47
(6,641 Views)