Bug when I release a Arduino obj.

3 visualizzazioni (ultimi 30 giorni)
chen xinfeng
chen xinfeng il 8 Apr 2016
Commentato: chen xinfeng il 8 Apr 2016
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`?

Risposte (1)

Walter Roberson
Walter Roberson il 8 Apr 2016
"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 Commento
chen xinfeng
chen xinfeng il 8 Apr 2016
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.

Accedi per commentare.

Categorie

Scopri di più su MATLAB Support Package for Arduino Hardware in Help Center e File Exchange

Tag

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by