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

24 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
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:
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]).
  1 Comment
Raymond Chiu
Raymond Chiu on 8 Jun 2016
Default permission were insufficient. Implemented symlink and java.opts as described by Mathworks support. #chmod 777 /dev/ttyUSB0 Ubuntu 16.04 + PL2303 serial-over USB device (dev/ttyUSB0). MATLAB>> instrhwinfo('serial') should return your serial device.

Sign in to comment.

More Answers (2)

John on 6 Aug 2014
Edited: Walter Roberson on 10 Jan 2018
This doesn't seem to work on Ubuntu 64-bit. Since i need a fixed port in my code for each of many devices, I created a symbolic serial port link by creating a lower-numbered rules file and adding this line:
SUBSYSTEM=="usb", ATTR{idVendor}=="0403", ATTR{idProduct}=="6001", ATTRS{serial}=="A7045P4Z", MODE="0666", SYMLINK+="ttyUSB99"
The new link shows up as expected in /dev when the device is plugged in.
But Matlab cannot open this symbolic link even though it is of the correct format. How can I open this link?
"Open failed: Port: /dev/ttyUSB99 is not available. Available ports:
/dev/ttyUSB0, /dev/ttyUSB2, /dev/ttyS4.
Use INSTRFIND to determine if other instrument objects are connected
to the requested device."

Maximilian Sgodda
Maximilian Sgodda on 10 Jan 2018
Hi together. I had the same problem. Please take a looking, if there is write and read permission for the lock-file Matlab wants to create.
It is under the root directory. /lock and there you can find a symbolic link to /run/lock. You can see it with ls -l This file "lock" under the /run directory. check with ls -l if there are the permissions set. If not set it with " sudo chmod 666"
Changing this worked for me under RHEL7. Hope it helps.
If somebody know why this happened or if it isnt recommended to change it, please feel free to comment.
  1 Comment
Tom Egan
Tom Egan on 12 Apr 2019
This also appears to be the solution under Fedora Core 29. My inner sysadmin feels
sudo chmod ugo+w /run/lock
is somehow very wrong.

Sign in to comment.


Find more on Application Deployment 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!