Callback function pointer in Matlab

I am trying to call a function from Matlab NI daqmx toolbox:
function [status, callbackData] = DAQmxRegisterEveryNSamplesEvent(uint64 task, int32 everyNsamplesEventType, uint32 nSamples, uint32 options, DAQmxEveryNSamplesEventCallbackPtr callbackFunction, void* callbackData)
This function requires a callbackFunction pointer as input but I have no idea how to create that in Matlab and matlab function handle doesn't work for it. Could anyone help me with this issue?

답변 (1개)

Image Analyst
Image Analyst 2019년 12월 23일

0 개 추천

You put an @ symbol in front of the argument when you call it. For example calling it might look like
[status, callbackData] = DAQmxRegisterEveryNSamplesEvent(task, everyNsamplesEventType,...
nSamples, options, DAQmxEveryNSamplesEventCallbackPtr, @MyCallbackFunction, callbackData)
where you've assigned values for the other arguments. Then you'd define that MyCallbackFunction() function somewhere, like
function results = MyCallbackFunction()
% code...
% The function needs to know what will be given to it when DAQmxRegisterEveryNSamplesEvent() gives stuff to it
% and what kind of data DAQmxRegisterEveryNSamplesEvent() expects to get back after MyCallbackFunction has been executed.

댓글 수: 3

Qi Pian
Qi Pian 2019년 12월 23일
funtion handle like @function doesn't work.
I got this error when replacing function pointer with function handle:
" Error using DAQmxRegisterEveryNSamplesEvent
Expected input number 5, callbackFunction, to be one of these types:
int32
Instead its type was function_handle.
Error in DAQmxRegisterEveryNSamplesEvent (line 9)
validateattributes(callbackFunction, {'int32'}, {'scalar'},
'DAQmxRegisterEveryNSamplesEvent', 'callbackFunction', 5);"
Image Analyst
Image Analyst 2019년 12월 23일
Then I don't know. Try calling NI tomorrow and asking for sample code.
Qi Pian
Qi Pian 2019년 12월 23일
Thanks a lot!

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Instrument Control Toolbox Supported Hardware에 대해 자세히 알아보기

제품

질문:

2019년 12월 23일

댓글:

2019년 12월 23일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by