Hi everyone,
data is send to my laptop by a device through a usb port. How often the data is send depends on de sample time that i choose, it can vary from very 0.05s to ones very 30s.
i want matlab to get the data every time that the device sends it to my laptop. I am not that familiar with matlab and hope you can help me out a bit.
this is what i have so far...:
board = serial('COM3', 'BaudRate', 38400, 'DataBits',8);
fopen(board);
S = fscanf(board);
with S I get (I think) the oldest value stored in the input buffer every time i run fscanf
Thanks in advance!
Paul

답변 (1개)

Walter Roberson
Walter Roberson 2015년 5월 18일

0 개 추천

Set a BytesAvailableFcn callback on the serial port object.

댓글 수: 5

paul kaam
paul kaam 2015년 5월 18일
Could you perhaps explain this a little bit more? I have difficulty implementing this function.
many thanks
Guillaume
Guillaume 2015년 5월 18일
See the examples in the doc here and here. Basically, instead of asking the serial port for data, you wait for it to execute your function (callback) whenever data can be read.
paul kaam
paul kaam 2015년 6월 24일
Many thanks Guillaume!
Unfortunately i have a matlab version from my university and are not able to view the documents!! is it possible you send it to me?
with kind regards,
No, that would be a violiation of Mathworks copyright.
You can access the same documentation from within matlab by typing:
web(fullfile(docroot, 'matlab/matlab_external/bytesavailablefcn.html'))
and
web(fullfile(docroot, 'matlab/matlab_external/events-and-callbacks.html'))
paul kaam
paul kaam 2015년 6월 26일
many thank!

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

카테고리

도움말 센터File Exchange에서 Use COM Objects in MATLAB에 대해 자세히 알아보기

질문:

2015년 5월 18일

편집:

2015년 6월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by