Why is my serial port not recognized with MATLAB on Linux or Solaris?

36 views (last 30 days)
I would like to open serial ports with names like '/dev/ttyPS0' on my Linux machine with MATLAB. If I attempt to connect to this serial port
s=serial('ttyPS0')
fopen(s)
I receive the following error: ERROR: ??? Error using ==> serial.fopen at 71 Port: ttyPS0 is not available. No ports are available. Use INSTRFIND to determine if other instrument objects are connected to the requested device.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 26 Jan 2016
MATLAB only automatically recognizes serial port names of the form /dev/ttyS[0-255]. If the serial port is named something else, identifying this serial port with MATLAB would be needed to be done through the java.opts file or by creating a symbolic link to the port which has a standard name.
For example, create a symbolic link named ttyS101 as follows (assuming /dev/ttyS101 does not exist):
ln -s /dev/ttyPS0 /dev/ttyS101
/dev/ttyS101will then be available in addition to the usual ports found.
The other way to have MATLAB recognize the port name is by creating a file named java.opts. In this file, include the following line:
-Dgnu.io.rxtx.SerialPorts=/dev/ttyPS0
where "/dev/ttyPS0" is the name of your serial port. (To enter multiple ports/file descriptors separate them by colons :). Put the java.opts file in the userpath directory in MATLAB, and navigate to that directory before starting MATLAB.
This will work for dozens of serial port types in Linux and Solaris. There are many serial port types supported that show up as unique device files. As a rough number, there are 50x256 possible serial ports in a Linux system. MATLAB only automatically checks 2% of those (/dev/ttyS[0-255]).

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!