how to read strings with multiple null (\0) terminators when using calllib functions
이전 댓글 표시
Hi everyone,
I've got a problem reading data from a device using external C dlls and calllib function.
The alias .m header file is something as below:
int ws_read_configdata ( const char * name , char * buffer , int buffersize , int * nread );
% fcns.name{fcnNum}='ws_read_configdata'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'cstring', 'cstring', 'int32', 'int32Ptr'};fcnNum=fcnNum+1;
or in the real .h file, as:
% *@param name [in] Previously created WaveShaper name
% *@param buffer [out] buffer to hold configuration data
% *@param buffersize [in] buffer size
% *@param nread [out] configuration data read in bytes
% *@return status code
% */
% int ws_read_configdata(const char* name, char* buffer, int buffersize, int* nread);
The matlab code I used to retrieve the data from the device is like:
bufsize = 10000000;
bufread = 0;
buf = blanks(bufsize);
[rc, a, b, c] = calllib(libname, 'ws_read_configdata', wsname, bufptr, bufsize, 0);
which returns me in variable b, only the first eight CHARS ['37CB39A6']. The remaining of the data is unreachable. The other returned values are shown below
rc = 0; % error check code, 0 = success
a = 58113; % serial number of device
b = '37CB39A6'; % returned data, WRONG! ONLY FIRST EIGHT CHARS
d = 6061152; % bytes that have been read
when I tried to use libpointers like:
bufsize = 10000000;
bufread = libpointer('int32Ptr', bufsize);
buf = blanks(bufsize);
bufptr = libpointer('string', buf);
[rc, a, bufptr.value, c] = calllib(libname, 'ws_read_configdata', wsname, bufptr, bufsize, bufread);
the problem remains the same.
rc = 0;
a = 58113;
bufptr.value = '37CB39A6';
c = 6061152;
yet now
bufread.value = 6061152
The content retrieved data by other methods (using executable file) is like

that is to say, the there are \0 characters in the data.
Any ideas how can I deal with this issue?
Thanks
Deming
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Acquisition Using Image Acquisition Explorer에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!