Oscilloscope_example.m 2.11 KB
Newer Older
1
%% alter path to your python (3.8 is tested) distribution here
2
3
py_path = 'C:\Users\49151\AppData\Local\Programs\Python\Python37\python.exe';
broker_ip = '192.168.0.1';
4
5
6
7
8
9


%% Init components
%oscilloscope properties --> delivering mqtt string for RedPitaya Inputs
%mqtt stuff
addpath('../../lib');
10
11
12
13
14
addpath('../../lib/redpitaya'); 
myMqtt = mqtt_py_matlab(py_path);
myMqtt.connect_mqtt(broker_ip);
for delay = -1e-3:5e-5:1e-3
    op = OscilloscopeProperties(); % get an object of the OscilloscopeProperties class
15

16
17
18
    % Two options to set sample rate
    op = op.set_sample_rate_by_div(1.01e-4); % Set time per Oszilloscope-Div
    %op.SampleRate = 15.6e6; % Set samplerate in MHz
19

20
    op.TriggerDelay = delay; %Delay in samples (0 delay -> Start writing in the center of the buffer)     
21

22
    op.TriggerLevel = .2; % Trigger level in Volt
23

24
25
    test_message = op.get_mqtt_message();
    %test_message = '[OSC]\ntrigger_delay=100\ndecimation=1\ntrigger_level=0.2\ntrigger_ch=CH_1\ntrigger_src=CH_1_PE';
26

27
   
28

29
30
    % Subscription to RP1 with wildcard (#)
    %myMqtt.sub_mqtt_topics(broker_ip, "RP1/#");
31

32
33
    % Subscription without wildcard
    %myMqtt.sub_mqtt_topics(broker_ip, "RP1/CONFIGURE/RECONFIG");
34

35
    %pause(2);
36

37
38
    % Publish Redpitaya API message
    myMqtt.pub_mqtt(broker_ip, "RP1/CONFIGURE/RECONFIG", test_message);
39

40
41
42
    % Read the last published message 
    %fprintf('%s', myMqtt.get_payload_str("RP1/CONFIGURE/RECONFIG"));
    fprintf('%s', test_message);
43

44
45
    % get max length of x axis 
    x_axis = op.get_ordinate();
46

47
48
49
    myMqtt.sub_mqtt_topics(broker_ip, "RP1/raw/CH1");
    % Start oszilloscope
    myMqtt.pub_mqtt(broker_ip, "RP1/CONFIGURE/START", test_message);
50

51
    %% Signal aquisition
52

53
54
55
56
    %while(1)
        % Read input 1
        arr = myMqtt.get_payload_float("RP1/raw/CH1");
        y_mat = cell2mat(cell(arr));
57

58
59
60
61
62
        % Plot input 1
        %subplot (2,1,1)
        plot(x_axis, y_mat);
        grid on;
        drawnow;
63

64
65
66
67
        % Plot filtered input 1
        %subplot (2,1,2)
        %plot(x_axis, y_filt);
        %grid on;
68

69
    %end
70
71
    % Stop the aquisition
    myMqtt.pub_mqtt(broker_ip, "RP1/CONFIGURE/RECONFIG", "STOP");
72
end
73