資源簡介
function BackData = ReadTDMSData(ChanNum,StartNum,NumToGet,filefolder,filepath)
%參數(shù)依次為:通道號/開始數(shù)據(jù)號/結(jié)束數(shù)據(jù)號/文件路徑/文件名
對NI官方給出的函數(shù)做了修改,直接返回數(shù)據(jù)值。需要放在ni官方文檔中運(yùn)行,需要改nilibddc.dll和nilibddc_m.h路徑
代碼片段和文件信息
function?BackData?=?ReadTDMSData(ChanNumStartNumNumToGetfilefolderfilepath)
%參數(shù)依次為:通道號/開始數(shù)據(jù)號/結(jié)束數(shù)據(jù)號/文件路徑/文件名
%導(dǎo)入庫和文件
%NilibddcLibInit(filefolderfilepath);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%調(diào)nilibddc庫文件,讀入數(shù)據(jù)文件%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%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.
if?exist(‘NI_TDM_DLL_Path‘‘var‘)==0
????%[dllfiledllfolder]=uigetfile(‘*dll‘‘Select?nilibddc.dll‘);
????dllfile=‘nilibddc.dll‘;
????dllfolder=‘F:\MATLAB?Program\Program\MATLAB_TDM_Example\dev\bin\64-bit‘;
????libname=strtok(dllfile‘.‘);
????NI_TDM_DLL_Path=fullfile(dllfolderdllfile);
end
if?exist(‘NI_TDM_H_Path‘‘var‘)==0
????%[hfilehfolder]=uigetfile(‘*h‘‘Select?nilibddc_m.h‘);
????hfile=‘nilibddc_m.h‘;
????hfolder?=‘F:\MATLAB?Program\Program\MATLAB_TDM_Example\dev\include\64-bit‘;
????NI_TDM_H_Path=fullfile(hfolderhfile);
end
%Prompt?the?user?to?browse?to?the?path?of?the?TDM?or?TDMS?file?to?read
if?isa(filepath‘numeric‘)?&&?isa(filefolder‘numeric‘)
????if?filepath?==?0?&&?filefolder?==?0
????????[filepathfilefolder]=uigetfile({‘*.tdms‘;‘*.tdm‘}‘Select?a?TDM?or?TDMS?file‘);
????end
end
Data_Path=fullfile(filefolderfilepath);
%Load?nilibddc.dll?(Always?call?‘unloadlibrary(libname)‘?after?finished?using?the?library)
loadlibrary(NI_TDM_DLL_PathNI_TDM_H_Path);
%Open?the?file?(Always?call?‘DDC_CloseFile‘?when?you?are?finished?using?a?file)
fileIn?=?0;
[errdummyVardummyVarfile]=calllib(libname‘DDC_OpenFileEx‘Data_Path‘‘1fileIn);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%獲取組數(shù),并對組賦句柄值%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Get?channel?groups
%Get?the?number?of?channel?groups
numgrpsIn?=?0;
[errnumgrps]=calllib(libname‘DDC_GetNumChannelGroups‘filenumgrpsIn);
%Get?channel?groups?only?if?the?number?of?channel?groups?is?greater?than?zero
if?numgrps>0
%Initialize?an?array?to?hold?the?desired?number?of?groups
????pgrps=libpointer(‘int64Ptr‘zeros(1numgrps));
????[errgrps]=calllib(libname‘DDC_GetChannelGroups‘filepgrpsnumgrps);??%得到不同組的句柄值
end??
%%%%%%%%%這段為了獲取numchans%%%%%%%%%%%
?numchansIn?=?0;
[errnumchans]=calllib(libname‘DDC_GetNumChannels‘grps(1)numchansIn);
numgv?=?zeros(numgrpsnumchans);
fo
評論
共有 條評論