1

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.

3 Answers 3

3

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 :)

Sign up to request clarification or add additional context in comments.

Comments

0

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.

2 Comments

But it worked for the OP in the C++ program. Presumably, joaocandre used the same access rights.
I've tried calling matlab with root (sudo matlab), but I get the same error. I've also tried to change the read/write permissions of the serial port as suggested in matlabarduino.org/serial-communication.html but the problem persists
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.