US English (US)
JP Japanese
CN Chinese
KR Korean

Contact Us

If you still have questions or prefer to get help directly from an agent, please submit a request.
We’ll get back to you as soon as possible.

Please fill out the contact form below and we will reply as soon as possible.

  • Knowledge Base Home
  • Contact Us
Japanese
US English (US)
JP Japanese
CN Chinese
KR Korean
  • Home
  • MATLAB API

API ストリーミングと stream_to_file | MATLAB

Written by Nadia Hauser

Updated at April 9th, 2025

Contact Us

If you still have questions or prefer to get help directly from an agent, please submit a request.
We’ll get back to you as soon as possible.

Please fill out the contact form below and we will reply as soon as possible.

  • Moku:Lab
    Moku:Lab に関するよくある質問 Moku:Labロジックアナライザ/パターンジェネレータ Moku:Lab時間および周波数アナライザー Moku:Labスペクトラムアナライザー Moku:Lab PID コントローラ Moku:Labオシロスコープ Moku:Lab位相計 Moku:Labレーザーロックボックス Moku:Labデジタルフィルターボックス Moku:Lab任意波形ジェネレータ Moku:Lab波形ジェネレーター Moku:Lab周波数応答アナライザー Moku:Lab FIR フィルター ビルダー Moku:Labロックインアンプ Moku:Labデータロガー
  • Moku:Go
    Moku:Goに関するよくある質問 Moku:Goロックインアンプ Moku:Goロジックアナライザ & パターンジェネレータ Moku:Goオシロスコープ & 電圧計 Moku:Goスペクトラムアナライザー Moku:Go波形ジェネレータ Moku:Go時間・周波数アナライザー Moku:Goデジタルフィルターボックス Moku:Go FIR フィルター ビルダー Moku:Goレーザーロックボックス Moku:Go任意波形ジェネレータ Moku:Go周波数応答アナライザー Moku:Goデータロガー Moku:Go計 Moku:Go電源 Moku:Go
  • Moku:Pro
    Moku:Proに関するよくある質問 Moku:Pro波形発生器 Moku:Proタイム&周波数アナライザ Moku:Proロジックアナライザ/パターンジェネレーター Moku:Proレレーザーロックボックス Moku:Proロックインアンプ Moku:Proスペクトラムアナライザ Moku:Proデータロガー Moku:Pro任意波形発生器 Moku:Proマルチ機器モード Moku:Pro位相計 Moku:Pro FIRフィルタービルダー Moku:Pro PIDコントローラー Moku:Proオシロスコープ Moku:Pro周波数応答アナライザ Moku:Proデジタルフィルターボックス
  • Python API
  • MATLAB API
  • 任意波形発生器
  • データロガー
  • デジタルフィルターボックス
  • FIR フィルタ ビルダー
  • 周波数応答アナライザー
  • レーザーロックボックス
  • ロックインアンプ
  • オシロスコープ
  • 位相計
  • PIDコントローラー
  • スペクトラムアナライザー
  • 時間と周波数アナライザー
  • 波形発生器
  • ロジックアナライザ/パターンジェネレーター
  • マルチ機器モード
  • Mokuクラウドコンパイル
  • Mokuに関するよくある質問
  • LabVIEW API
+ More

ストリーミングオプション

APIの詳細については、 データロガー | API リファレンス 

ストリーミングstream_to_file MATLAB のデータ ストリーミングの例

stream_to_file メソッド

これは、データをログに記録したいが、mokucli を使用して外部で変換したくない場合に便利です。このユースケースについては、 「API ログ ファイルのダウンロードと変換 | MATLAB」を参照してください。これにより、ダウンロード中にファイルが変換され、ストリーミング セッションが完了すると分析できるようになります。

% moku example: Datalogger Stream to File
% (c) 2025 Liquid Pty. Ltd.

% Connect to your Moku
i = MokuDatalogger('192.168.###.###', 'force_connect', false);

try
    % Set-up the Datalogger
    i.set_acquisition_mode('mode','Precision');
    i.set_samplerate(1e3);
    i.generate_waveform(1, 'Sine', 'amplitude',1, 'frequency',10e3);

    % Start a streaming session and stream to a file, include the file type in the
    %   file name; csv, hdf5, npy, or mat
    i.start_streaming('duration', 10);
    now = datetime('now', 'Format','yyyyMMdd_HHmmSS');
    file_name = 'DataStreamingData_' + string(now) + '.mat';
    i.stream_to_file(file_name);

    fprintf('Streaming to file: %s\n', file_name);
    status = i.get_stream_status();
    fprintf('Status: %s\n', status.status);
    % Track progress percentage of the data streaming session
    while strcmp(status.status, 'RUNNING')
        pause(0.5);
        status = i.get_stream_status();
    end

    % Wait for the file to become accessible
    pause(5);
    channels = 2;
    fprintf('%s\n', file_name);
catch ME
    i.relinquish_ownership();
    rethrow(ME);
end

% Close the connection to the Moku device
i.relinquish_ownership();

% Check for the file, then open the file and create data struct
if ~isfile(file_name)
    error('Streaming failed, no file received');
end
data = struct('time', [], 'ch1', []);
file = load(file_name);
data.time = file.moku.data(:, 1);
for i = 1:channels
    data.(['ch', num2str(i)]) = file.moku.data(:, i+1);
end

% Display the streamed data
keys = fieldnames(data);
for k = 1:numel(keys)
    key = keys{k};
    disp([key, ': ', mat2str(data.(key)(1:3)), ' ... [', num2str(data.(key)(end)), ']']);
end

% Plot the streamed data
fig = figure('Position', [100, 100, 1000, 300]);
hold on;
for i = 1:channels
    plot(data.time, data.(['ch', num2str(i)]), 'DisplayName', ['Channel ', num2str(i)]);
end
title('Streamed to File Data');
grid on;
xlabel('Time (s)');
ylabel('Voltage (V)');
legend show;
hold off;

出力例:

Streaming to file: DataStreamingData_20250117_103569.mat
Status: RUNNING
DataStreamingData_20250117_103569.mat
time: [0;0.001;0.002] ... [9.999]
ch1: [0.00191093314060709;0.0016939521851782;0.00161954084887839] ... [0.0017355]
ch2: [0.014444866169697;0.01442298048255;0.0143560728104148] ... [0.014131]
stream_to_file データのプロット MATLAB

他のファイルタイプへのストリーミングの場合:

file_name = 'DataStreamingData_' + string(now) + '.npy';
i.stream_to_file(file_name);
file_name = 'DataStreamingData_' + string(now) + '.hdf5';
i.stream_to_file(file_name);
file_name = 'DataStreamingData_' + string(now) + '.csv';
i.stream_to_file(file_name);

ストリーミング方式

この方法は、ストリーミング セッションが完了するのを待つのではなく、リアルタイムでデータを分析する場合に便利です。

% moku example: Datalogger Streaming
% (c) 2025 Liquid Pty. Ltd.
i = MokuDatalogger('192.168.###.###', 'force_connect', false);

try
    % Set-up the Datalogger
    i.set_acquisition_mode('mode','Precision');
    i.set_samplerate(100);
    i.generate_waveform(1, 'Sine', 'amplitude',1, 'frequency',10e3);

    % Stream the data for 10 seconds
    i.start_streaming('duration', 10);

    % Plot the streamed data
    fig = figure('Position', [100, 100, 1000, 300]);
    hold on;
    grid on;
    ylim([0, 0.016]);
    title('Streamed Data');
    xlabel('Time (s)');
    ylabel('Voltage (V)');
    data = i.get_stream_data();
    lh1 = plot(data.time, data.ch1, 'DisplayName', 'Channel 1');
    lh2 = plot(data.time, data.ch2, 'DisplayName', 'Channel 2');
    legend show;
    while 1
        data = i.get_stream_data();
        if ~isempty(data) & ~isempty(data.time)
            set(lh1,'XData',data.time,'YData',data.ch1);
            set(lh2,'XData',data.time,'YData',data.ch2);
            xlim([data.time(1), data.time(end)]);
            pause(0.1)
        end
    end    
catch ME
    i.relinquish_ownership();
    rethrow(ME);
end

% Close the connection to the Moku device
i.relinquish_ownership();
ストリーミングデータのプロット MATLAB

Was this article helpful?

Yes
No
Give feedback about this article

Related Articles

  • MATLAB データロガーとログファイルの保存
  • MATLAB API のドキュメントはどこにありますか?
  • MATLAB を使い始める
  • 同じ MATLAB スクリプト内で複数のMokuデバイスを制御できますか?
  • Moku:Labのデータロガーから MATLAB に .CSV ファイルをインポートするにはどうすればよいですか?

Sitemap

  • Moku:Lab
  • Instruments
  • Software
  • Company
  • Support
  • Store
  • Terms & Conditions
  • Privacy Policy

Offices

United States
+1 (619) 332-6230
12526 High Bluff Dr
Suite 150
San Diego, CA 92130

Australia
+61 2 6171 9730
243 Northbourne Avenue
Suite 2
Lyneham, ACT 2602

Australia
+61 03 7073 3594
700 Swanston Street
Suite 5E, Level 5
Carlton, VIC 3053

Follow us

Youtube LinkedIn

官方微信

Contact us
© 2025 Liquid Instruments. All rights reserved.

Knowledge Base Software powered by Helpjuice

Definition by Author

0
0
Expand