Borrar filtros
Borrar filtros

How can I send data to a different serial port when a callback event occurs on another serial port?

1 visualización (últimos 30 días)
I am trying to send data via USB serial port when an event occurs on another serial port.
I am getting the following warning:
Warning: The BytesAvailableFcn is being disabled. To enable the callback property either connect to the hardware with FOPEN or set the BytesAvailableFcn property.

Respuestas (1)

Walter Roberson
Walter Roberson el 24 de Mzo. de 2014
s1 = serial('COM1', .....);
s2 = serial('COM7', .....);
set(s1, 'BytesAvailableFcn', @(src, evt) fwrite(s2, fread(s1, s1.BytesAvailable)) );
fopen(s2);
fopen(s1);
  2 comentarios
David Dijemeni
David Dijemeni el 24 de Mzo. de 2014
I tried
time = datestr(now,0); s1 = serial('COM1', .....); s2 = serial('COM7', .....); set(s1, 'BytesAvailableFcn', @(myfunction, time) fwrite(s2, fread(s1, s1.BytesAvailable)) ); fopen(s2); fopen(s1);
It didnt work. Please am I doing anything wromg?
Kevin Hajek
Kevin Hajek el 2 de Sept. de 2015
I'm seeing the same error message, but I am trying to use the serial object in the callback. If you happened to find a solution, please share it here. I'll keep looking around.

Iniciar sesión para comentar.

Categorías

Más información sobre Low-Level File I/O en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by