attaching callback function to a serialdev object.

9 visualizaciones (últimos 30 días)
Golan Ramati
Golan Ramati el 29 de Mayo de 2023
Comentada: Walter Roberson hace alrededor de 14 horas
I've got a raspberry pi, that control a CNC machine. this machine is running on a version of GRBL for arduino mega.
I can connect to the pi with no issues, and can connect to the GRBL to write\read data to\from.
but, I can't figure out how to attach a callback function that will read in real time data coming from the serial port.
if I'm defining the serial as 'serialdev' object, using the "configureCallback" function returns with: Undefined function 'configureCallback' for input arguments of type 'raspi.internal.SerialDev'.
and I can't define it as 'serialport' object, because the port I'm supposed to enter as an argument, is on a different device...
any help would be very much appreciated.

Respuesta aceptada

Walter Roberson
Walter Roberson el 30 de Mayo de 2023
Callbacks are not supported for serialdev() objects.
Note that this serial port lives on the pi and is for connecting an external device to the pi, not for connecting the pi to the MATLAB host. The request to read from the serialdev() using read() is relayed to the pi and the pi handles the reading into a buffer and then forwards the content to the MATLAB session; likewise when you write(), the buffer-full is sent from the MATLAB host to the pi and the monitor program on the pi is responsible for sending the data out.
Therefore, you cannot use this mechanism to read from the serialdev port in real time -- because it is all getting buffered at the pi.
This is a read-on-demand mechanism, not "reads continually in the background relaying bytes to a buffer on the MATLAB side."
It pretty much follows that if you need high speed processing that you should be writing code that execute on the Pi .
The trade-offs probably change if you use MATLAB Coder to deploy the serialdev() code to the Pi itself; in that case there would be no need of relaying back to the MATLAB host.
  3 comentarios
Bensafi Houari
Bensafi Houari hace alrededor de 21 horas
Hi , i want to implement a control law of a five axis cnc milling machine to the rospberry pi that contains the grbl firmware to maximaize the performance of the machine based on the dynamic model and kinematics related to it , but i don't know the procedure to achieve this or which matlab tool is used to do it ,
Walter Roberson
Walter Roberson hace alrededor de 14 horas
That is a seperate question that you should ask by itself.

Iniciar sesión para comentar.

Más respuestas (0)

Productos


Versión

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by