Borrar filtros
Borrar filtros

Bug when I release a Arduino obj.

2 visualizaciones (últimos 30 días)
chen xinfeng
chen xinfeng el 8 de Abr. de 2016
Comentada: chen xinfeng el 8 de Abr. de 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`?

Respuestas (1)

Walter Roberson
Walter Roberson el 8 de Abr. de 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 comentario
chen xinfeng
chen xinfeng el 8 de Abr. de 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.

Iniciar sesión para comentar.

Categorías

Más información sobre MATLAB Support Package for Arduino Hardware en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by