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

5 ビュー (過去 30 日間)
Sohail Ahmed
Sohail Ahmed 2021 年 11 月 22 日
コメント済み: Sohail Ahmed 2021 年 11 月 30 日
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);
  1 件のコメント
Sohail Ahmed
Sohail Ahmed 2021 年 11 月 30 日
Is anyone here?? Kindly help........



Walter Roberson
Walter Roberson 2021 年 11 月 30 日
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.
  1 件のコメント
Sohail Ahmed
Sohail Ahmed 2021 年 11 月 30 日
Thanks.... I think this will help....


その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by