필터 지우기
필터 지우기

Bug when I release a Arduino obj.

조회 수: 3 (최근 30일)
chen xinfeng
chen xinfeng 2016년 4월 8일
댓글: chen xinfeng 2016년 4월 8일
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`?

답변 (1개)

Walter Roberson
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
  댓글 수: 1
chen xinfeng
chen xinfeng 2016년 4월 8일
It's very nice of you,
Maybe I should modify the `arduino.m` for opening `delete()` permission.
But, it's not healthy-way, which will cause incompatible for team-works. I'm still searching for other solutions.

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

카테고리

Help CenterFile 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!

Translated by