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中的以下行编辑为以下内容:
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