Bug when I release a Arduino obj.
조회 수: 3 (최근 30일)
이전 댓글 표시
How can I release a `arduino` except clear
I have some code like this!
a=arduino('com5','uno');
%give 'a' to other vars.
set(uicontrol('str','anything'),'UserData',a);
%Use `uicontrol` just to demo a long-live obj/handle.
%arduino do something
...
...
Now I want to restart/re-get my Arduino, and get ERROR
clear all;
a2=arduino('com5','uno');
%get msg like this:
% Failed to open serial port COM5 to communicate with Arduino board Uno...
To restart/re-get my Arduino, I known that I am suggested to use ` clear a;` first! But I known it's less-efficient, no-convenient to use `clear a;` or `clear all;`
I just WANT TO use delete and re-get Arduino, but REJECTED.
delete(a);
%get msg like this:
% Error to use arduino/delete.
Must I do have to type `edit arduino.m`, and change the permission of `delete`?
댓글 수: 0
답변 (1개)
Walter Roberson
2016년 4월 8일
"Must I do have to type `edit arduino.m`, and change the permission of `delete`?"
Yes. delete() is not appropriate for an arduino object, so if you want to be able to delete it you will need to change the implementation code for arduino.m
When you "clear" an object, you remove the variable and possibly trigger releasing the object if MATLAB detects that the reference count is now 0. There is no possibility of ending up with a variable that represents a deleted arduino object.
When you "delete" an object, the variable that held the object still exists afterwards, so the variable needs to be changed internally to "deleted arduino object", because the user is permitted to reference a variable that refers to an object that has been deleted.
a = arduino();
delete(a) %supposing it was permitted
disp(a) %Valid MATLAB. It would have to say deleted arduino object or something like that
b = arduino();
clear b
disp(b) %NOT valid MATLAB. b was cleared, the variable itself does not exist
참고 항목
카테고리
Help Center 및 File Exchange에서 MATLAB Support Package for Arduino Hardware에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!