Discussion:
Problem with TDMS in Matlab
(too old to reply)
IstDerHolger
2007-11-02 16:40:11 UTC
Permalink
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?
 
JoeLabView
2007-11-05 22:10:23 UTC
Permalink
Have you looked at this thread?
<a href="http://forums.ni.com/ni/board/message?board.id=60&amp;message.id=5126" target="_blank">http://forums.ni.com/ni/board/message?board.id=60&amp;message.id=5126</a>
JoeLabView
2007-11-05 22:11:57 UTC
Permalink
IstDerHolger wrote:
I am trying to write a TDM or TDMS File in Matlab.


Oops, I must have misunderstood something.
&nbsp;
Is the TDM / TDMS file written to using Matlab or using Labview?&nbsp; I just read Kevin's reply which discussed using LV to write to&nbsp;the file.
&nbsp;
proc_control
2007-11-08 20:40:07 UTC
Permalink
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.
&nbsp;
So maybe someone worked on a similar project and has a solution.
&nbsp;
To&nbsp;write and read&nbsp;structured data from and to Matlab&nbsp;would be&nbsp;very convenient for me.
&nbsp;
&nbsp;
&nbsp;
&nbsp;
B.Wagner
2008-06-06 16:10:05 UTC
Permalink
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:&gt; ??? Error using ==&gt; calllib&gt; Parameter must be a string&gt;&gt; Error in ==&gt; Read_TDMData at 39&gt; 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 &lt;-&gt; Matlab coding so I'm stuck at the moment and thankful for every useful hint.Thanks in Advance
CMal
2008-06-06 21:40:06 UTC
Permalink
Hi B.Wagner,
&nbsp;
The "Read_TDMData.m" example was written and tested with versions R2007a, R2007b, and R2008a.&nbsp; These versions are capable of handling libpointer strings and strings somewhat interchangeably, which I do not believe version R14 does as well.&nbsp; If you try replacing 'DDC_FILE_NAME' with 'DDC_FILE_NAME.Value', then this line should execute properly.&nbsp; I cannot guarantee that the two examples provided will work as expected with anything earlier than R2007a, since I haven't tested them with those earlier versions, so please let me know if you encounter any other issues or if the above solution doesn't work.
&nbsp;
Chris M
B.Wagner
2008-06-09 11:40:05 UTC
Permalink
Hi Chris M. Thanks fot the fast help.&nbsp; I don't encounter the error anymore after I expanded all the DDC_FILE_xx expressions (thus Name, Description, Title, Author and Datetime) by the '.Value' term. The only thing that astonishes me a bit is that there's not a single outpout. The program simply runs, finishes and leaves me a blank screen. Is the example made like this on purpose (no title, date or graph for the values) or is it another incompatibility with my system?B.Wagner
B.Wagner
2008-07-24 16:40:04 UTC
Permalink
Hi Chris M.,after working on a different project I returned to my tdms-Stream. As I wrote in my last message the inital error when using the 'ReadTDMData'-example disappeared after I made the changes you proposed. I didn't worry much about the blank screen when testing the routine with the 'SineData.tdm' file since I blamed my older Matlab-version for it.Lately I perfomed a test with one of my proper .tdms recordings (see file attached) and I get the following error message right after loading the file:&gt;&gt; ??? error using ==&gt; calllib&gt;&gt; Array must be numeric or logical or a pointer to one.&gt;&gt;&gt;&gt; Error in ==&gt; Read_TDMData at 43&gt;&gt;&nbsp;&nbsp;&nbsp; calllib('nilibddc','DDC_GetFileProperty',pfile.Value,DDC_FILE_NAME.Value,pfilename,pfilenamelen.Value+1);Is there an error in my recording or is it again a problem with my Matlab Version??greetingsB.Wagner


100m25C.lvm.zip:
http://forums.ni.com/attachments/ni/170/343713/1/100m25C.lvm.zip
Jennifer_R
2008-07-29 00:10:06 UTC
Permalink
Hi B.Wagner,
It looks like the file you attached is a .lvm file, not a TDM or TDMS file.&nbsp; Is that what you are reading from?&nbsp; Do you have a .tdm or .tdms file you can post that gives the same error?
B.Wagner
2008-08-04 14:40:09 UTC
Permalink
Hi Jennifer R.

Oops...looks like I attached the wrong file....sorry for that...here's the tdms....

Greetings

B.Wagner


calib212.zip:
http://forums.ni.com/attachments/ni/170/346355/1/calib212.zip
Jennifer_R
2008-08-06 11:40:05 UTC
Permalink
Hi B.Wagner,
I was able to read the file in Excel, using the <a href="http://zone.ni.com/devzone/cda/epd/p/id/2944" target="_blank">TDM Excel Add-In</a>, so the data seems to have been logged correctly.
B.Wagner
2008-08-06 14:10:07 UTC
Permalink
Hi Jennifer R.,


O.K....so it appears to be a problem with my 'ancient' Matlab version :-/ . I'll try to get a newer one. Thanks for the help!

B.Wagner

proc_control
2008-08-06 13:10:05 UTC
Permalink
I wasn't aware of this, but NI has included an example in Matlab to write TDM files. I just tried it out and it works perfectly.
Thanks a lot!
Loading...