Verfasst am: 11.06.2010, 11:27
Titel: Matlab Fehler im Programm
Hallo,
ich muss in Matlab eine tdms einlesen. Die kommt von dem Programm Diadem.
Der Hersteller hat folgenden Code +Dateien zur Verfügung gestellt, der zum Einlesen der Datei benötigt wird:
Code:
clc;
%Check if the paths to 'nilibddc.dll' and 'nilibddc_m.h' have been
%selected. If not, prompt the user to browse to each of the files.
ifexist('NI_TDM_DLL_Path','var')==0 [dllfile,dllfolder]=uigetfile('*dll','Select nilibddc.dll');
NI_TDM_DLL_Path=fullfile(dllfolder,dllfile);
end ifexist('NI_TDM_H_Path','var')==0 [hfile,hfolder]=uigetfile('*h','Select nilibddc_m.h');
NI_TDM_H_Path=fullfile(hfolder,hfile);
end
%Prompt the user to browse to the path of the TDM or TDMS file to read.
[filepath,filefolder]=uigetfile({'*.tdm';'*.tdms'},'Select TDM or TDMS File');
Data_Path=fullfile(filefolder,filepath);
[pathstr, name, ext, versn] = fileparts(Data_Path);
%Apply the appropriate file type to 'ftype', depending on whether a TDM or
%TDMS file was selected. Here, 'ftype' is used in the 'DDC_OpenFileEx' function.
ifstrcmp(ext,'.tdms')
ftype='TDMS';
else
ftype='TDM';
end
%Load nilibddc.dll(Always call 'unloadlibrary('nilibddc')' after finished using
%the library.)
loadlibrary(NI_TDM_DLL_Path,NI_TDM_H_Path);
%Open the TDM or TDMS file (Read Only)(Always call 'DDC_CloseFile' after finished creating or
%reading a file.)
pfile = libpointer('int32Ptr', 0);
calllib('nilibddc','DDC_OpenFileEx',Data_Path,ftype,1,pfile);
%Read and Display File Name
DDC_FILE_NAME=libpointer('stringPtr','name');
pfilenamelen=libpointer('uint32Ptr',0);
%Get the length of the 'DDC_FILE_NAME' string property
err=calllib('nilibddc','DDC_GetFileStringPropertyLength',pfile.Value,DDC_FILE_NAME,pfilenamelen);
if err==0 %Only proceed if File Name is found
%Initialize a string of the length of the file name
pfilename=libpointer('stringPtr',blanks(pfilenamelen.Value));
calllib('nilibddc','DDC_GetFileProperty',pfile.Value,DDC_FILE_NAME,pfilename,pfilenamelen.Value+1);
disp(['File Name: ' pfilename.Value]);
end
%Read and Display File Description
DDC_FILE_DESCRIPTION=libpointer('stringPtr','description');
pfiledesclen=libpointer('uint32Ptr',0);
%Get the length of the 'DDC_FILE_DESCRIPTION' string property
err=calllib('nilibddc','DDC_GetFileStringPropertyLength',pfile.Value,DDC_FILE_DESCRIPTION,pfiledesclen);
if err==0 %Only proceed if File Description is found
%Initialize a string of the length of the file description
pfiledesc=libpointer('stringPtr',blanks(pfiledesclen.Value));
calllib('nilibddc','DDC_GetFileProperty',pfile.Value,DDC_FILE_DESCRIPTION,pfiledesc,pfiledesclen.Value+1);
disp(['File Description: ' pfiledesc.Value]);
end
%Read and Display File Title
DDC_FILE_TITLE=libpointer('stringPtr','title');
pfiletitlelen=libpointer('uint32Ptr',0);
%Get the length of the 'DDC_FILE_TITLE' string property
err=calllib('nilibddc','DDC_GetFileStringPropertyLength',pfile.Value,DDC_FILE_TITLE',pfiletitlelen);
if err==0 %Only proceed if File Titleis found
%Initialize a string of the length of the file title
pfiletitle=libpointer('stringPtr',blanks(pfiletitlelen.Value));
calllib('nilibddc','DDC_GetFileProperty',pfile.Value,DDC_FILE_TITLE,pfiletitle,pfiletitlelen.Value+1);
disp(['File Title: ' pfiletitle.Value]);
end
%Read and Display File Author
DDC_FILE_AUTHOR=libpointer('stringPtr','author');
pfileauthlen=libpointer('uint32Ptr',0);
%Get the length of the 'DDC_FILE_AUTHOR' string property
err=calllib('nilibddc','DDC_GetFileStringPropertyLength',pfile.Value,DDC_FILE_AUTHOR,pfileauthlen);
if err==0 %Only proceed if File Author is found
%Initialize a string of the length of the file author
pfileauth=libpointer('stringPtr',blanks(pfileauthlen.Value));
calllib('nilibddc','DDC_GetFileProperty',pfile.Value,DDC_FILE_AUTHOR,pfileauth,pfileauthlen.Value+1);
disp(['File Author: ' pfileauth.Value]);
end
%Read and Display File Timestamp
DDC_FILE_DATETIME=libpointer('stringPtr','datetime');
pyear=libpointer('uint32Ptr',0);
pmonth=libpointer('uint32Ptr',0);
pday=libpointer('uint32Ptr',0);
phour=libpointer('uint32Ptr',0);
pminute=libpointer('uint32Ptr',0);
psecond=libpointer('uint32Ptr',0);
pmsecond=libpointer('doublePtr',0);
pwkday=libpointer('uint32Ptr',0);
err=calllib('nilibddc','DDC_GetFilePropertyTimestampComponents',pfile.Value,DDC_FILE_DATETIME,pyear,pmonth,pday,phour,pminute,psecond,pmsecond,pwkday);
if err==0 %Only proceed if File Timestamp is found
disp(['File Timestamp: ' num2str(pmonth.Value) '/' num2str(pday.Value) '/' num2str(pyear.Value) ', ' num2str(phour.Value) ':' num2str(pminute.Value) ':' num2str(psecond.Value) ':' num2str(pmsecond.Value)]);
end
%Get Channel Groups
DDC_CHANNELGROUP_NAME=libpointer('stringPtr','name');
DDC_CHANNELGROUP_DESCRIPTION=libpointer('stringPtr','description');
DDC_CHANNEL_NAME=libpointer('stringPtr','name');
%Get the number of Channel Groups
pnumgrps=libpointer('uint32Ptr',0);
calllib('nilibddc','DDC_GetNumChannelGroups',pfile.Value,pnumgrps);
%Get Channel Groups only if the number of Channel Groups is greater than
%zero
if pnumgrps.Value>0
pgrps=libpointer('int32Ptr',zeros(1,pnumgrps.Value));
calllib('nilibddc','DDC_GetChannelGroups',pfile.Value,pgrps,pnumgrps.Value);
end for i=1:pnumgrps.Value %For each Channel Group
%Get Channel Group Name
pgrpnamelen=libpointer('uint32Ptr',0);
err=calllib('nilibddc','DDC_GetChannelGroupStringPropertyLength',pgrps.Value(i),DDC_CHANNELGROUP_NAME,pgrpnamelen);
if err==0 %Only proceed if Channel Group Name is found
pgrpname=libpointer('stringPtr',blanks(pgrpnamelen.Value));
calllib('nilibddc','DDC_GetChannelGroupProperty',pgrps.Value(i),DDC_CHANNELGROUP_NAME,pgrpname,pgrpnamelen.Value+1);
else
pgrpname=libpointer('stringPtr','');
end
%Get Channel Group Description
pgrpdesclen=libpointer('uint32Ptr',0);
err=calllib('nilibddc','DDC_GetChannelGroupStringPropertyLength',pgrps.Value(i),DDC_CHANNELGROUP_DESCRIPTION,pgrpdesclen);
if err==0 %Only proceed if Channel Group Description is found
pgrpdesc=libpointer('stringPtr',blanks(pgrpdesclen.Value));
calllib('nilibddc','DDC_GetChannelGroupProperty',pgrps.Value(i),DDC_CHANNELGROUP_DESCRIPTION,pgrpdesc,pgrpdesclen.Value+1);
end
%Get Channels
pnumchans=libpointer('uint32Ptr',0);
%Get the number of Channels in this Channel Group
calllib('nilibddc','DDC_GetNumChannels',pgrps.Value(i),pnumchans);
%Get Channels only if the number of Channels is greater than zero
if pnumchans.Value>0
pchans=libpointer('int32Ptr',zeros(1,pnumchans.Value));
calllib('nilibddc','DDC_GetChannels',pgrps.Value(i),pchans,pnumchans.Value);
end
for j=1:pnumchans.Value %For each Channel in group
%Get Channel Name
pchannamelen=libpointer('uint32Ptr',0);
err=calllib('nilibddc','DDC_GetChannelStringPropertyLength',pchans.Value(j),DDC_CHANNEL_NAME,pchannamelen);
if err==0 %Only proceed if Channel Name is found
pchanname=libpointer('stringPtr',blanks(pchannamelen.Value));
calllib('nilibddc','DDC_GetChannelProperty',pchans.Value(j),DDC_CHANNEL_NAME,pchanname,pchannamelen.Value+1);
channames{j}=pchanname.Value;
else
channames{j}='';
end
%Get Channel Data Type
ptype=libpointer('voidPtr',uint8(0));
calllib('nilibddc','DDC_GetDataType',pchans.Value(j),ptype);
%Get Channel Value if Data Typeis 'Double'(10) if ptype.Value==10
pnumvals=libpointer('uint64Ptr',0);
calllib('nilibddc','DDC_GetNumDataValues',pchans.Value(j),pnumvals);
pvals=libpointer('doublePtr',zeros(1,pnumvals.Value));
calllib('nilibddc','DDC_GetDataValues',pchans.Value(j),0,pnumvals.Value,pvals);
chanvals(:,j)=(pvals.Value)'; %#ok<AGROW>
end
Die nilibddc.dll und nilibddc_m.h Datei habe ich einmalig angegeben und wenn ich mit F10 Debuge werden die Pfade einwandfrei wieder gegeben unf funktioniert alles prima:
Erst ab der Zeile:
Code:
%Load nilibddc.dll(Always call 'unloadlibrary('nilibddc')' after finished using
%the library.)
loadlibrary(NI_TDM_DLL_Path,NI_TDM_H_Path)
ich bin sehr an diesem Thema interessiert. Es steht, dass dieser Beitrag 2008 eingestellt wurde. Es wundert mich aber, weil ich mich an mehrere Kunden erinnere die bei MathWorks den Verbesserungsvorschlag zum Einlesen von TDM Files gestellt haben.
Zitat:
Dieses Beispiel wurde mit den MATLAB-Versionen R2007a, R2007b und R2008a getestet.
Was ist hier das verwendete Release?
Ich probiere das Ganze gerne aus, habe aber selber keine TDM Datei zur Verfügung. Kann ich eine per Email bekommen?
OK, das ist zumindest eine wertvolle Information für andere Nutzer. Wie gesagt, wenn ich ein TDM File hätte würde ich gerne einen Test durchführen und auch dafür sorgen, dass eine 64 Bit-fähige Version zur Verfügung gestellt wird.
finde das selbstverständlich, da ich in anderen Foren helfend unterwegs bin ärgert mich das immer, wenn jemand eine "Lösung" gefunden hat, aber es nicht sagt.
Ich schicke dir gleich eine E-Mail mit den notwendigen Daten!
Vielen Dank schonmal für deine Bemühungen.
Christian
EDIT: Deine angegebene E-Mail Adresse stimmt nicht mehr? Meine Mail an dich ist eben zurückgekommen
ok vielen dank für den Test, dann weiß ich wenigstens, dass das Programm funktioniert. (habe auch win7 prof 64bit)
Du hast auch das Programm aus meinem Link genommen für das Einlesen der Daten?
Bin etwas ratlos, da er an der besagten Stelle einfach das Prgramm beendet vermute ich mal es könnte an lese/schreibrechten liegen?! weil im debugging-modus ist der pfad korrekt hinterlegt.
ich habe mich mal als admin angemeldet und hätte ja eigentlich alle Rechte, aber auch da bricht er an der Stelle ab.
Sehr merkwürdig.
Trotzdem vielen Dank für den Test!
Ich habe jetzt mal R2009b angefordert und installiert und jetzt erhalte ich folgende Fehlermeldung (hätte ich doch bei r2009a auch erhalten müssen?! vielleicht übersehen -sry)
??? Error using ==> loadlibrary at 281
Microsoft Visual C++ 2005 or 2008 is required to use this feature.
Error in ==> ReadFile at 30
loadlibrary(NI_TDM_DLL_Path,NI_TDM_H_Path);
Das Problem:
Microsoft Visual C++ 2005 und 2008 ist bei mir installiert.
Vielleicht kennst du den Grund?
Freak
Gast
Beiträge: ---
Anmeldedatum: ---
Wohnort: ---
Version: ---
Verfasst am: 03.05.2011, 12:48
Titel:
Hallo habe genau das Problem. Hat jemand eine Lösung?
Wäre sehr dankbar dafür.
Einstellungen und Berechtigungen
Du kannst Beiträge in dieses Forum schreiben. Du kannst auf Beiträge in diesem Forum antworten. Du kannst deine Beiträge in diesem Forum nicht bearbeiten. Du kannst deine Beiträge in diesem Forum nicht löschen. Du kannst an Umfragen in diesem Forum nicht mitmachen. Du kannst Dateien in diesem Forum posten Du kannst Dateien in diesem Forum herunterladen
MATLAB, Simulink, Stateflow, Handle Graphics, Real-Time Workshop, SimBiology, SimHydraulics, SimEvents, and xPC TargetBox are registered trademarks and The MathWorks, the L-shaped membrane logo, and Embedded MATLAB are trademarks of The MathWorks, Inc.