我正在尝试通过 USB(运行 Arch Linux)与 Arduino 建立串行通信。我可以通过 C++ 程序并使用 boost::asio
以直接的方式完成它,但最近我安装了 Matlab 并遇到了一些问题。我设法使用 s0=serial('/dev/ttyACM0')
创建串行对象,但是当我调用 fopen(s0)
时,我收到以下错误:
Error using serial/fopen (line 72)
Open failed: Port: /dev/ttyACM0 is not available. No ports are available.
最佳答案
这是我在 Arch Linux 64 位上的 Matlab R2014a 中进行串口通信的方法:
1a) 按照此处描述的步骤操作: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) 检查 gtkterm 中的连接是否有效(选择端口 ttyACM0)
2) 另外(仅对 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.
我是如何得到这个解决方案的:
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.
希望对您有所帮助! 干杯:)
关于c++ - 无法在 Matlab UNIX 上打开串口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26504127/