0

I am working on the project that detects the connection between MATLAB with bluetooth module HC-05. MATLAB will display something such as "no signal" when HC-05 is out of range of the bluetooth. My idea is that send the character in ASCII from HC-05 to MATLAB, so if the HC-05 is out of range of bluetooth connection, MATLAB will not receive any thing from HC-05. So, it will display "no signal".
However, my code below only display:

Warning: The specified amount of data was not returned within the Timeout period for 'read'. 'serialport' unable to read any data. For more information on possible reasons, see serialport Read Warnings.

So based on the code below, I need help to consider the warning above as the error show MATLAB will display the announce "no signal" instead of the warning. Or is there any other way to display announcement when MATLAB disconnect with Bluetooth module HC-05?

bt=[];
bt=serialport('COM11',9600)

    while(1)
        pause(0.5)
      
            re_char="";
          
           writeline(bt,'q');
        try
           rec_char = read(bt,2,"char");
            disp(rec_char);
          
        catch
            disp("no signal");
        end
      
    end
greybeard
  • 2,249
  • 8
  • 30
  • 66

0 Answers0