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!