Beispiel #1
0
            attribute_id=niscope_types.NiScopeAttributes.
            NISCOPE_ATTRIBUTE_FETCH_RELATIVE_TO,
            value=niscope_types.NiScopeInt32AttributeValues.
            NISCOPE_INT32_FETCH_RELATIVE_TO_VAL_READ_POINTER))).status)

    # Fetch continuously until all samples are acquired.
    current_pos = 0
    samples_per_fetch = 100
    while current_pos < total_samples:

        # We fetch each channel at a time so we don't have to de-interleave afterwards.
        # We do not keep the wfm_info returned from fetch.
        for channel_name, waveform in zip(channel_list, waveforms):
            fetch_response = client.Fetch(
                niscope_types.FetchRequest(vi=vi,
                                           channel_list=channel_name,
                                           timeout=500000,
                                           num_samples=samples_per_fetch))
            CheckForError(vi, fetch_response.status)
            waveform[current_pos:current_pos +
                     samples_per_fetch] = fetch_response.waveform
            print(
                f'Fetching channel {channel_name}\'s waveform for indices {current_pos} to {current_pos + samples_per_fetch - 1}'
            )
        print()
        current_pos += samples_per_fetch

    # Close session to NI-SCOPE module.
    CheckForError(vi, (client.Close(niscope_types.CloseRequest(vi=vi))).status)
    channel.close()

# If NI-SCOPE API throws an exception, print the error message.
Beispiel #2
0
        niscope_types.ConfigureHorizontalTimingRequest(
            vi=vi,
            min_sample_rate=50000000,
            min_num_pts=samples,
            ref_position=50.0,
            num_records=1,
            enforce_realtime=True))).status)

    # Initiate acquisition.
    CheckForError(vi, (client.InitiateAcquisition(
        niscope_types.InitiateAcquisitionRequest(vi=vi))).status)

    # Fetch waveforms.
    fetch_response = client.Fetch(
        niscope_types.FetchRequest(vi=vi,
                                   channel_list=channels,
                                   timeout=10000,
                                   num_samples=samples))
    CheckForError(vi, fetch_response.status)
    waveforms = fetch_response.waveform

    # Print waveform results.
    for i in range(len(waveforms)):
        print(f'Waveform {i} information:')
        print(f'{waveforms[i]}\n')

# If NI-SCOPE API throws an exception, print the error message.
except grpc.RpcError as rpc_error:
    error_message = rpc_error.details()
    if rpc_error.code() == grpc.StatusCode.UNAVAILABLE:
        error_message = f"Failed to connect to server on {server_address}:{server_port}"
    elif rpc_error.code() == grpc.StatusCode.UNIMPLEMENTED:
Beispiel #3
0
    def on_close(event):
        global closed
        closed = True

    fig.canvas.mpl_connect('close_event', on_close)
    print("\nReading values in loop. CTRL+C to stop.\n")
    try:
        while not closed:
            # Clear the plot and setup the axis
            fig.clf()
            plt.axis([0, 500, -6, 6])
            # Fetch a waveform from the scope
            for i in range(len(sessions)):
                fetch_result = scope_service.Fetch(
                    niscope_types.FetchRequest(vi=sessions[i],
                                               channel_list=channels,
                                               timeout=1,
                                               num_samples=500))
                CheckForError(scope_service, session, fetch_result.status)
                plt.subplot(1, len(sessions), i + 1, label=str(i))
                # Round the array to 2 decimal places and Update the plot with the new waveform
                data = np.array(fetch_result.waveform[0:500])
                # Add labels for axes and legends
                plt.ylabel('Amplitude')
                plt.xlabel('Samples')
                plt.plot(np.round(data, 2))
                plt.title(label='$Scope{i}$'.format(i=i))
            plt.subplots_adjust(wspace=0.5)
            plt.pause(0.001)
            time.sleep(0.1)
    except KeyboardInterrupt:
        pass