How to make Scilab open a serial communication with /dev/ttyACM0 USB port in Linux (Ubuntu)

11,139

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

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

and then call openserial as follows:

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:

$ 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:

sudo usermod -a -G dialout <USER_NAME>
Share:
11,139
Fabio Silva
Author by

Fabio Silva

Updated on June 04, 2022

Comments

  • Fabio Silva
    Fabio Silva almost 2 years

    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.

    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.

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