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.
我正在尝试在Scilab和Arduino之间进行串行通信。然而,Arduino一直被Linux Ubuntu在/dev/tty**ACM0**端口上识别。当我在Scilab中写入h= open串行(1,“9600,n,8,1)时,我知道我说的是,在Linux中打开一个串行通信到COM1或/dev/ ttys0*。
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.
但是,例如,如果我使用h= open串行(N,“9600,N, 8,1),假设N=端口号,我将总是在Linux中有COMN,在Windows和/dev/tty** **(N-1)中。
How do I open a serial comunication through /dev/tty**ACM0**
port in Scilab for Linux?
如何在Scilab中为Linux打开一个串行通信?
3 个解决方案
#1
2
Looking at the openserial.sci
from the Serial Communication Toolbox for Scilab repo,
看openserial。sci来自于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
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:
该端口始终设置为/dev/ttyS
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
and then call openserial as follows:
然后调用openseries如下:
h=openserial("ACM0","9600,n,8,1)
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:
还要确保/dev/ttyACM0是正确的设备节点。这是ls -l的一个示例输出,您可以运行它来确认:
$ ls -l /dev/ttyACM0
crw-rw---- 1 root dialout 188, 0 Mar 12 18:16 /dev/ttyACM0
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:
如果出现错误,将串行端口作为常规用户打开,您可以将自己添加到正确的组中。基于上面的例子,我的openSUSE发行版上的组名是拨号。它可能与您的不同,因此在以下命令中替换该组名称:
sudo usermod -a -G dialout <USER_NAME>
#2
0
Just type:
类型:
h = openserial("/dev/ttyACM0", "9600, n, 8, 1");
and you are done.
和你做。
#3
0
keep simple, STRINGS its a valid option to port, so as Luis post:
保持简单,字符串是端口的有效选项,因此,Luis post:
"...Just type:
“…类型:
h = openserial("/dev/ttyACM0", "9600, n, 8, 1");
and you are done..."
和你做……”
As an example, supouse your arduino its on serial port "/dev/ttyACM0" type on Scilab:
举例来说,你的arduino在Scilab上的串行端口“/dev/ttyACM0”是一个例子:
n=300 // plot 300 data points from serial port "/dev/ttyACM0"
h=openserial("/dev/ttySACM0","9600,n,8,1")
i=1;
while i<=n
data(i) = strtod(readserial(h)); // char to number
plot(i,data(i),'b-o'); // real time plot
drawnow(); // show data
i=i+1;
end
#1
2
Looking at the openserial.sci
from the Serial Communication Toolbox for Scilab repo,
看openserial。sci来自于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
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:
该端口始终设置为/dev/ttyS
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
and then call openserial as follows:
然后调用openseries如下:
h=openserial("ACM0","9600,n,8,1)
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:
还要确保/dev/ttyACM0是正确的设备节点。这是ls -l的一个示例输出,您可以运行它来确认:
$ ls -l /dev/ttyACM0
crw-rw---- 1 root dialout 188, 0 Mar 12 18:16 /dev/ttyACM0
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:
如果出现错误,将串行端口作为常规用户打开,您可以将自己添加到正确的组中。基于上面的例子,我的openSUSE发行版上的组名是拨号。它可能与您的不同,因此在以下命令中替换该组名称:
sudo usermod -a -G dialout <USER_NAME>
#2
0
Just type:
类型:
h = openserial("/dev/ttyACM0", "9600, n, 8, 1");
and you are done.
和你做。
#3
0
keep simple, STRINGS its a valid option to port, so as Luis post:
保持简单,字符串是端口的有效选项,因此,Luis post:
"...Just type:
“…类型:
h = openserial("/dev/ttyACM0", "9600, n, 8, 1");
and you are done..."
和你做……”
As an example, supouse your arduino its on serial port "/dev/ttyACM0" type on Scilab:
举例来说,你的arduino在Scilab上的串行端口“/dev/ttyACM0”是一个例子:
n=300 // plot 300 data points from serial port "/dev/ttyACM0"
h=openserial("/dev/ttySACM0","9600,n,8,1")
i=1;
while i<=n
data(i) = strtod(readserial(h)); // char to number
plot(i,data(i),'b-o'); // real time plot
drawnow(); // show data
i=i+1;
end