joaocandre
joaocandre

Reputation: 1745

Can't open serial port on Matlab UNIX

I'm trying to establsih serial communication with an Arduino through USB (running Arch Linux). I can do it in a straightforward way trough a C++ program and using boost::asio, but recently I installed Matlab and been encoutering some issues. I manage to create the serial object with s0=serial('/dev/ttyACM0') but when I call fopen(s0) I get the following error:

Error using serial/fopen (line 72)
Open failed: Port: /dev/ttyACM0 is not available. No ports are available.

Upvotes: 1

Views: 1541

Answers (3)

SLKun
SLKun

Reputation: 21

Just make soft link from /dev/ttyACM0 to /dev/ttyS[0-255].

   ln -sf /dev/ttyACM0 /dev/ttyS100 # for example

Below Matlab R2017a may face this issue.

Detailed Description can find here:

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

Hope this can be helped.

Upvotes: 0

user5161769
user5161769

Reputation: 31

Here is what I did to get serial port communication work in Matlab R2014a on Arch Linux 64 bit:

1a) follow the steps described here: http://www.matlabarduino.org/serial-communication.html:

sudo chmod 777 /dev/ttyACM0 Alternatively, add your user to the group uucp: > sudo gpasswd --add username uucp

sudo nano $MATLABROOT/bin/$ARCH/java.opts --> add: -Dgnu.io.rxtx.SerialPorts=/dev/ttyS0:/dev/ttyUSB0:/dev/ttyACM0

1b) check that the connection works in gtkterm (select port ttyACM0)

2) additionally (critical only for Matlab):

sudo chmod 777 /run/lock /run/lock was symlinked from /var/lock on my distro, so you might have to do this with the latter dir (was 755); alternatively, you can manage access rights to /run/lock/ by ACL.

How I got to this solution:

sudo strace -p 4668 -f -s100 2>&1 | grep -C3 --color -i -e /dev -e serialports -e uucp -p: process ID == second column from > sudo ps -aux | grep -i matlab Then, in Matlab type >> sps=instrhwinfo('serial') (which in my case always returned a structure of empty cell-arrays) and monitor the output of strace.

Hope that helps! cheers :)

Upvotes: 3

Malvin
Malvin

Reputation: 1

By default, only root can use the serial port.

And you can add your id to the serial group "dialout", so you can use the serial port.

Upvotes: 0

Related Questions