查看来自Serial Communication Toolbox for Scilab 存储库的openserial.sci,
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 中的以下行编辑为如下内容:
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如下:
h=openserial("ACM0","9600,n,8,1)
还要确保/dev/ttyACM0 是正确的设备节点。这是来自ls -l 的示例输出,您可以运行以确认:
$ ls -l /dev/ttyACM0
crw-rw---- 1 root dialout 188, 0 Mar 12 18:16 /dev/ttyACM0
如果您以普通用户身份打开串行端口时遇到错误,您可以将自己添加到正确的组中。根据上面的例子,在我的 openSUSE 发行版上,组名是dialout。您的可能会有所不同,因此请在以下命令中替换该组名:
sudo usermod -a -G dialout <USER_NAME>