前提・実現したいこと
2つのアナログ入力値をMATLABでプロットしようとしています。
発生している問題・エラーメッセージ
出力では値は両方とも得られるのにプロットは片方のアナログ入力のみが行われ、もう一方はエラーが出て描画されません。
どうしたらこのエラーを回避できるプログラムにできますか?
なぜ1つ目のアナログ入力のみ描画されるのでしょうか?
>>showOutputInput 5.3680e-04 2.4084 エラー:showOutputInput(line 37) The hardware associated with this session is reserved. If you are using it in another session use the release function to unreserve the hardware. If you are using it in an external program exit that program. Then try this operation again.
該当のソースコード
MATLAB
1%送信波と受信波をプロットするプログラム 2s = daq.createSession('ni'); 3tx = daq.createSession('ni'); 4ch1 = addAnalogInputChannel(tx,'Dev1', 'ai0', 'Voltage'); 5ch2 = addAnalogInputChannel(s,'Dev1', 'ai1', 'Voltage'); 6 7s.Rate = 8000; 8 9data1 = tx.inputSingleScan; 10data2 = s.inputSingleScan; 11 12disp(data1) 13disp(data2) 14 15%送信側プロット 16subplot(2,1,1) 17tx.DurationInSeconds = 2; 18[data1,time] = tx.startForeground; 19plot(time,data1); 20%disp(time); 21%disp(data); 22xlabel('Time (secs)'); 23ylabel('Voltage') 24 25%受信側プロット 26subplot(2,1,2) 27s.DurationInSeconds = 5; 28[data2,time] = s.startForeground; 29plot(time,data2); 30%disp(time); 31%disp(data); 32xlabel('Time (secs)'); 33ylabel('Voltage') 34
試したこと
エラーメッセージが
The hardware associated with this session is reserved.
だったので、MATLABを再起動して、実行しているコード以外に動作していないことを確認しました。
また以下のように、アナログ入力ではなくMATLABでグラフの式を定義し他場合は、2つのプロットができることは確認済みです。
t1 = (0:length(s1)-1)/Fs; t2 = (0:length(s2)-1)/Fs; subplot(2,1,1) plot(t1,s1) title('s_1') subplot(2,1,2) plot(t2,s2) title('s_2') xlabel('Time (s)')
補足情報(FW/ツールのバージョンなど)
MATLABR2017b
Data Acquisition Toolbox

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。