LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with TDMS in Matlab

Hi,
 
I am trying to write a TDM or TDMS File in Matlab. Reading files seems to be straight forward and there is an example on the NI web site. Only when I try to write I am getting an error. I am using the TDM DLL.
Here is the code
 

dllpath=

'C:\Program Files\Matlab\R2007a\toolbox\TDMS\dev\bin\nilibddc'

hpath=

'C:\Program Files\Matlab\R2007a\toolbox\TDMS\dev\include\nilibddc.h'

loadlibrary(dllpath,hpath);

pfile = libpointer(

'int32Ptr', 0);

result=calllib(

'nilibddc','DDC_CreateFile','C:\temp\test.tdm','TDM','test file','test file', 'test title','author',pfile)

if

result==-6212

result=calllib(

'nilibddc','DDC_OpenFileEx', 'C:\temp\test.tdm', 'TDM', 1, pfile)

end

pgroup=libpointer(

'int32Ptr', 0);

calllib(

'nilibddc','DDC_AddChannelGroup',pfile.Value,'Model3','PLS Model for M345V in Mobile',pgroup)

calllib(

'nilibddc','DDC_SaveFile',pfile.Value);

calllib(

'nilibddc','DDC_CloseFile',pfile.Value);

unloadlibrary(

'nilibddc');

When I try to add a group I am getting:

DDC_InvalidFileHandle = -6206

Error.

Once I save the files I also can't open them.

 

Any suggestions?

 
0 Kudos
Message 1 of 18
(7,760 Views)
This is the LabVIEW forum.  Are  you trying to call matlab functions using LV?
Message 2 of 18
(7,747 Views)

>> This is the LabVIEW forum.  Are  you trying to call matlab functions using LV?

I am trying to save a file in Matlab and read it from LabView. TDM or TDMS files have the right structure so it would be nice to use them.

Maybe there is someone in the comunity, who also worked with MATLAB and had a similar problem.

 

 

0 Kudos
Message 3 of 18
(7,732 Views)
Message 4 of 18
(7,719 Views)
There's an example here that lets Matlab read data from a TDMS file that was created in LabVIEW.  The page mentions that it only supports *reading from* but not *writing to* a TDMS file.  It's not entirely clear to me whether that's a restriction built into the dll itself or whether it's a caution that the example demonstrates reads but not writes.   Or perhaps the restriction is a result of how the file handle is opened -- I *do* know that in LabVIEW one can select either read-only or read-write access when opening the file.  Perhaps the example (or the dll) will only open TDMS files in read-only mode?
 
Here's another link that distinguishes between a C dll that's advertised as providing both read and write capability and a separate line item referring back to the previously linked page about reading from Matlab (no mention of writing).
 
-Kevin P.
ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
Message 5 of 18
(7,679 Views)


IstDerHolger wrote:
I am trying to write a TDM or TDMS File in Matlab.


Oops, I must have misunderstood something.
 
Is the TDM / TDMS file written to using Matlab or using Labview?  I just read Kevin's reply which discussed using LV to write to the file.
 
0 Kudos
Message 6 of 18
(7,670 Views)
I also found the example M-file to read TDMS files in LabView. And this works just fine.
But I also would like to write or modify TDMS files in Matlab and read them in LabView and this seems to cause problems.
 
So maybe someone worked on a similar project and has a solution.
 
To write and read structured data from and to Matlab would be very convenient for me.
 
 
 
 
0 Kudos
Message 7 of 18
(7,620 Views)
Hi IstDerHolger,

Reading and writing TDM/TDMS files from The MathWorks, Inc. MATLAB(R) software environment using the TDM C DLL is not officially supported by National Instruments.  If you can reproduce the same error from a C program, feel free to post the example and we can take a look at it.

MATLAB(R) is a registered trademark of The MathWorks, Inc.

Regards,
Message 8 of 18
(7,615 Views)
Hi IstDerHolger,

I looked into the issue a bit further and noticed a few things:
The header file included with the read example only defines a subset of the functions that are actually available in the DLL. If you instead download and use the header file from TDM C DLL download linked on the example page, you will see the rest of the functions. You will have to modify the header file slightly:

/*
typedef struct _DDCFile                DDCFile;
typedef struct _DDCChannelGroup        DDCChannelGroup;
typedef struct _DDCChannel            DDCChannel;

typedef DDCFile*                    DDCFileHandle;
typedef DDCChannelGroup*            DDCChannelGroupHandle;
typedef DDCChannel*                    DDCChannelHandle;
*/

typedef long                    DDCFileHandle;
typedef long                    DDCChannelGroupHandle;
typedef long                    DDCChannelHandle;


Notice that the struct typedefs were replaced with long typedefs of the same name. This is so that
The MathWorks, Inc. MATLAB(R) software environment can understand the parameter types of the functions you are calling.

Also, in the original code you posted, the 2nd call to calllib might cause a problem when you try to save later:

result=calllib('nilibddc','DDC_OpenFileEx', 'C:\temp\test.tdm', 'TDM', 1, pfile)

It is my understanding that this will open the file in read only mode. If you want to write and save the file, you should pass 0 for the 5th parameter.

Again,
reading and writing TDM/TDMS files from The MathWorks, Inc. MATLAB(R) software environment using the TDM C DLL is not officially supported by National Instruments and the method I've described above has not been tested or guaranteed to work.

MATLAB(R) is a registered trademark of The MathWorks, Inc.

Regards,
0 Kudos
Message 9 of 18
(7,472 Views)
Hi everyone!

I was just running the "Read_TDMData" example from the NI support page in Matlab 7.0.0 (R14) and it's not working for me!

After selecting .dll's and .tdm files I get the following error message:

> ??? Error using ==> calllib
> Parameter must be a string
>
> Error in ==> Read_TDMData at 39
> err=calllib('nilibddc','DDC_GetFileStringPropertyLength',pfile.Value,DDC_FILE_NAME,pfilenamelen);

Has anyone of you encountered this error yet? I'm quite new to LabView <-> Matlab coding so I'm stuck at the moment and thankful for every useful hint.

Thanks in Advance




0 Kudos
Message 10 of 18
(7,007 Views)