问题
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?
回答1:
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>
回答2:
Just type:
h = openserial("/dev/ttyACM0", "9600, n, 8, 1");
and you are done.
回答3:
keep simple, STRINGS its a valid option to port, so as 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:
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
来源:https://stackoverflow.com/questions/15527818/how-to-make-scilab-open-a-serial-communication-with-dev-ttyacm0-usb-port-in-lin