Serial Communication in Maltab using Linux 64 Bit

37 ビュー (過去 30 日間)
hhn_jb
hhn_jb 2015 年 7 月 9 日
コメント済み: Ravi Kiran Aggadi 2022 年 6 月 8 日
I use Matlab 2015a (64 Bit) on a Ubuntu Linux distribution system. I want to build a communication to a device with a RS232 port. For this task I use a USB to RS232 converter cabel. In Linux I get the information, that the cable is connected to ttyUSB0. But if i want to start the communication over Matlab with:
s = serial('/dev/ttyUSB0', 'BaudRate', 9600);
fopen(s)
I get the error:
Error using serial/fopen (line 72)
Open failed: Port: /dev/ttyUSB0 is not available. ....
I tested this process on a WIN System and there is no problem. The communication runs pretty well. Have anyone experieances with Linux/Matlab and serial communication?
  1 件のコメント
William Harwin
William Harwin 2017 年 3 月 9 日
This is in fact a Linux permissions problem rather than a Matlab problem. To test permissions see if there is a difference between
sudo stty -a -F /dev/ttyUSB0
and
stty -a -F /dev/ttyUSB0
If the latter says 'permission denied' or similar then you are probably not a member of the relevant group. The group on the USB port can be seen by using
ls -l /dev/ttyUSB0
and can be changed via
sudo usermod -aG groupname username
e.g.
sudo -aG dialout harrypotter
Check membership via the `group' command (a reboot may be necessary)

サインインしてコメントする。

回答 (2 件)

Álvaro Cortés Sánchez-Migallón
Álvaro Cortés Sánchez-Migallón 2022 年 5 月 20 日
I followed other way. I got exactly the same error (Over Manjaro distribution) and of course is about permissions:
  • From terminal:
sudo chmod +777 /run/lock
sudo chmod +777 /dev/ttyACM0
  • From Matlab:
% Scan all serial ports
serialPorts = serialportlist
% Get serial port i want as serial communication
ACM0 = serial(serialPorts(1))
% Open file (now works)
fopen(ACM0)
% Read data all data available
data = fread(ACM0, ACM0.BytesAvailable);
  1 件のコメント
Ravi Kiran Aggadi
Ravi Kiran Aggadi 2022 年 6 月 8 日
Thanky you! the solution that you have mentioned helpd me in resolving the problem.

サインインしてコメントする。


Dasharath Gulvady
Dasharath Gulvady 2015 年 7 月 21 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by