2

Scilabと Arduino間のシリアル通信を開こうとしています。ただし、Arduino は/dev/tty**ACM0**ポート内の Linux Ubuntu によって常に認識されます。私が Scilab で書いているとき、私は、Linux への、またはLinux でh=openserial(1,"9600,n,8,1)のシリアル通信を開くように言っていることを知っています。COM1/dev/tty**S0**

しかし、たとえば、 を使用すると、Windows と Linux で常に COMN がh=openserial(N,"9600,n,8,1)使用されます。N=port number/dev/tty**S**(N-1)

/dev/tty**ACM0**Scilab for Linux でポートを介してシリアル通信を開くにはどうすればよいですか?

4

3 に答える 3

2

Serial Communication Toolbox for Scilabopenserial.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

通常のユーザーとしてシリアル ポートを開くときにエラーが発生する場合は、自分自身を正しいグループに追加することができます。上記の例に基づくと、グループ名はdialout私の openSUSE ディストリビューションにあります。お使いのものとは異なる場合があるため、次のコマンドでそのグループ名を置き換えます。

sudo usermod -a -G dialout <USER_NAME>
于 2013-03-20T21:03:26.760 に答える
0

Luisが投稿するように、STRINGSは移植するための有効なオプションです。

"...次のように入力してください:

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

そして、あなたは終わった...」

例として、Scilab のシリアルポート "/dev/ttyACM0" タイプで arduino を仮定します:

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
于 2014-12-03T12:16:28.867 に答える