calling shared lib functions - serial port
古いコメントを表示
Big picture: I'm interested in controling a device through MatLab which has a shared library of functions; to open a serial port, get data, and close the port. The data of interest is voltages with time.
I have loaded the library into Matlab successfully, and could use some advice on how to call each function properly in order to work with the incoming data later on in the code. I have attached my current non working code. When I call a c function, do I need to define the variables which are passed into it as defined in c?
I realize anyone attempting helpful hints won't understand the specific function properties, although I could describe variable formats later if needed.
%%load the Ser1ch.dll into Matlab and call header files
loadlibrary ser1ch ser1ch.h addheader SrHelp.h alias A2D
%view functions imported
libfunctionsview A2D
%confirm load was successful
libisloaded A2D
%set up serial port
%s1=serial('COM1');
port=1
%%FUNCTION Ser1chOpen --> c function to open port for A/D board
calllib(A2D, 'Ser1chOpen', port, 'NULL');
%%read data
%%Call Function Ser1chGetData --> c function to get data from board as
%%double pression-32integer
counts=[];
calllib(A2D, 'Ser1chGetData', counts, 'NULL', 'NULL');
%convert counts to voltage
%%Convert count data from A/D Board to Voltages
slope=2.96E-7; %count per volt
volt=slope *count;
%%Close port
calllib(A2D, 'Ser1chClose', port, 'NULL');
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!