如何让 Scilab 在 Linux (Ubuntu) 中打开与/dev/ttyACM0 USB 端口的串行通信 [英] How to make Scilab open a serial communication with /dev/ttyACM0 USB port in Linux (Ubuntu)

查看:59
本文介绍了如何让 Scilab 在 Linux (Ubuntu) 中打开与/dev/ttyACM0 USB 端口的串行通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试打开 Scilab 和 Arduino 之间的串行通信.但是,Linux Ubuntu 始终在 /dev/tty**ACM0** 端口中识别 Arduino.当我在 Scilab 中编写 h=openserial(1,"9600,n,8,1) 时,我知道我在对它说,打开一个到 COM1/dev/tty**S0** 在 Linux 中.

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=端口号,我将始终在 Windows 中具有 COMN,在 Linux 中具有 /dev/tty**S**(N-1).

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.

如何在 Scilab for Linux 中通过 /dev/tty**ACM0** 端口打开串行通信?

How do I open a serial comunication through /dev/tty**ACM0** port in Scilab for Linux?

推荐答案

查看 openserial.sci 来自 串行通信工具箱Scilab 存储库,

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.因此,在您的本地工具箱文件中,您可以尝试将 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 端口的串行通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆