How can I read the serial port continuously and trigger a third party device based on what is read?

4 views (last 30 days)
Hello,
I have configured my microcontroller to output a "ping" onto the serial port COM3 whenever it encounters a TTL. I would now like to have MATLAB read that "ping" whenever it occurs. When MATLAB recognizes this "ping" I want MATLAB to trigger a third party device that is connected to the laptop via an ethernet connection.
Can anyone throw some light on how this can be accomplished?
Thank you.
P.S: I am trying along the following lines but getting MATLAB to continuously read the "ping" is becoming a little tricky.
clear all
close all
clc
s = serial('COM3','BaudRate',9600,'Terminator','CR/LF');
fopen(s)
A = fscanf(s);
while j < 1000
if (strcmp(A,'Ping'))
x = 0:0.1:pi;
y = square(x);
plot(y);
drawnow;
end
j = j + 1;
end
fclose(s)
delete(s)
clear s

Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!