2013-03-20 29 views
2

我試圖打開Scilab和Arduino之間的串行通信。但是,Arduino總是被Linux Ubuntu在/dev/tty**ACM0**端口中識別。當我在Scilab編寫h=openserial(1,"9600,n,8,1)時,我知道我正在對它說,在Linux中打開一個連接到COM1/dev/tty**S0**的串行通信。如何使Scilab在Linux(Ubuntu)中使用/ dev/ttyACM0 USB端口打開串行通信

但是,例如,如果我使用h=openserial(N,"9600,n,8,1),假設N=port number,我將始終在Windows中使用COMN,在Linux中使用/dev/tty**S**(N-1)

如何通過Scilab for Linux中的/dev/tty**ACM0**端口打開串口通信?

回答

2

望着openserial.sciSerial Communication Toolbox for 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<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> 
+0

Tuxdude,我沒你sugest什麼,我得到的以下使者: - 錯誤999 TCL_EvalStr,在1號線 \t無法打開 「ACM0」:執行 沒有這樣的文件或目錄 「開放ACM0 R +」 從 中調用「設置porthandle [開ACM0 R + ]「 在函數openserial的第17行調用: h = openserial(」ACM0「,」9600,n,8,1「) – 2013-03-21 00:30:06

+0

@FabioSilva - 你確定你的串口設備節點是'/ dev/ttyACM0' ? – Tuxdude 2013-03-21 00:40:53

+0

我從arduino IDE獲取這些信息。 – 2013-03-21 00:56:55

0

只需鍵入:

h = openserial("/dev/ttyACM0", "9600, n, 8, 1"); 

和你做。

0

保持簡單,絃樂其有效選項端口,從而路易斯崗位:

「...只是類型:

h = openserial("/dev/ttyACM0", "9600, n, 8, 1"); 

和你做......」

舉個例子,你supouse其Arduino的串行端口「的/ dev/ttyACM0」類型上的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 
相關問題