问题描述
我正在尝试打开 Scilab 与Arduino之间的串行通信.但是,Linux Ubuntu始终在/dev/tty**ACM0**
端口中识别Arduino.当我在Scilab中编写h=openserial(1,"9600,n,8,1)
时,我知道我是在说要在Linux中打开与COM1
或/dev/tty**S0**
的串行通讯.
I'm trying to open a serial communication between Scilab and Arduino. However, Arduino is always recognized by Linux Ubuntu in the /dev/tty**ACM0**
port. When I write h=openserial(1,"9600,n,8,1)
in Scilab I know that I'm saying to it, to open a serial comunication to COM1
or /dev/tty**S0**
in Linux.
但是,例如,如果我使用h=openserial(N,"9600,n,8,1)
,假设使用N=port number
,则在Windows中将始终具有COMN,而在Linux中将始终具有COMN.
But, for example, if I use h=openserial(N,"9600,n,8,1)
, assuming N=port number
, I will always have COMN, in Windows and /dev/tty**S**(N-1)
in Linux.
如何在Linux的Scilab中通过/dev/tty**ACM0**
端口打开串行通讯?
How do I open a serial comunication through /dev/tty**ACM0**
port in Scilab for Linux?
推荐答案
查看 Scilab串行通信工具箱回购中的="nofollow"> openserial.sci
,
Looking at the openserial.sci
from the Serial Communication Toolbox for Scilab repo,
function h=openserial(p,smode,translation,handshake,xchar,timeout)
//port name
if ~exists("p","local") then p=1; end
if type(p)==1 | type(p)==8 then
if p<=0 then error("port number must be greater than zero"); end
if getos() == "Windows" then
port="COM"+string(p)+":"
else
port="/dev/ttyS"+string(p-1)
end
elseif type(p)==10
port=p
else
error("port to open must be either a number or a string")
end
端口始终设置为/dev/ttyS<PORT_NUMBER>
.因此,在本地工具箱文件中,您可以尝试将openserial.sci
中的以下行编辑为类似这样的内容:
The port is always set to /dev/ttyS<PORT_NUMBER>
. So in your local toolbox files, you could try editing the following lines in openserial.sci
to something like this:
function h=openserial(p,smode,translation,handshake,xchar,timeout)
//port name
if ~exists("p","local") then p=1; end
if type(p)==1 | type(p)==8 then
if p<=0 then error("port number must be greater than zero"); end
if getos() == "Windows" then
port="COM"+string(p)+":"
else
port="/dev/ttyS"+string(p-1)
end
elseif type(p)==10
port=p
elseif type(p)=="ACM0"
port="/dev/ttyACM0"
else
error("port to open must be either a number or a string")
end
,然后按如下所示调用openserial:
and then call openserial as follows:
h=openserial("ACM0","9600,n,8,1)
还要确保/dev/ttyACM0
是正确的设备节点.这是ls -l
的示例输出,您可以运行以确认:
Also make sure that /dev/ttyACM0
is the correct device node. This is a sample output from ls -l
, that you can run to confirm:
$ ls -l /dev/ttyACM0
crw-rw---- 1 root dialout 188, 0 Mar 12 18:16 /dev/ttyACM0
如果在以普通用户身份打开串行端口时遇到错误,则可以将自己添加到正确的组中.根据以上示例,我的openSUSE发行版上的组名称为dialout
.您的名称可能有所不同,因此请在以下命令中替换该组名称:
If you're getting errors opening the serial port as a regular user, you might add yourself to the correct group. Based on the above example, the group name is dialout
on my openSUSE distro. It might be different on yours, so substitute that group name in the following command:
sudo usermod -a -G dialout <USER_NAME>
这篇关于如何使Scilab在Linux(Ubuntu)中使用/dev/ttyACM0 USB端口打开串行通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!