Effacer les filtres
Effacer les filtres

How to display "serial device connected" or "not connected"?

19 vues (au cours des 30 derniers jours)
Sohail Ahmed
Sohail Ahmed le 22 Nov 2021
I am interfacing a spectral sensor with PC and getting the data through MATLAB (serial port functions).
I want to add a conditional statement to check whether the device is connected / not connected before getting serial data.
conditional statement ??
spectral3 = serialport('COM4','BaudRate',115200);
  2 commentaires
Sohail Ahmed
Sohail Ahmed le 30 Nov 2021
Is anyone here?? Kindly help........
Sébastien Josset
Sébastien Josset le 22 Déc 2022
Hi Ahmed, hi All,
I strongly suppose you're using the same sensor as I would like to: AS7265x Triad Spectroscopy Sensor (datasheet: AS7265x (sparkfun.com)).
It works well with me using a software serial with an Arduino nano, but I would like to use it directly in the Matlab environment through UART communication (datasheet page 41), but it requires to modify the sensor. Before I do that, I would like to know if you managed to use the sensor this way, and if yes, if you could be so kind and share your code to collect the responses at the 18 different wavelebgths?
Kind Regards
Sebastien

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 30 Nov 2021
serialportlist('available') can tell you whether the port of interest is "available"
serialport() objects appear to try to open the port as soon as you invoke serialport() . They do not have a connection status because serialport() fails if it is not able to open the port. The port stays open until you clear the serialport() object.
This is different than the older serial() objects, which had a specific fopen() and the properties could be examined to see if the serial() object was open.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by