c++ - 无法在 Matlab UNIX 上打开串口

标签 c++ matlab serial-port

我正在尝试通过 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/

相关文章:

c++ - 在 C++ 中使用 setw 和 setprecision 时如何显示带有值的 $ 符号

c++ - 何时以及如何在 C++ 中初始化静态数据?

c# - 使用c#从串口部分接收消息

python - 在 python 中快速绘制数据

c++ - 设置处理器与将在 Linux 上运行的 C++ 的关联

c++ - 关于模板类的 C++ 动态转换

Matlab:如何找到满足特定要求的矩阵的行索引?

matlab - 小矩阵乘以大矩阵

matlab - Matlab session 之间的低延迟变量共享?

c - 当有一些数据要读取时,select() 会阻塞