Esempio n. 1
0
            # Fetch the measured average frequency
            fetch_result = scope_service.FetchMeasurementStats(
                niscope_types.FetchMeasurementStatsRequest(
                    vi=vi,
                    channel_list=channels,
                    timeout=1,
                    scalar_meas_function=niscope_types.ScalarMeasurement.
                    SCALAR_MEASUREMENT_NISCOPE_VAL_AVERAGE_FREQUENCY))
            CheckForError(vi, fetch_result.status)
            print("Average Frequency: " +
                  str("%.2f" % round(fetch_result.result[0], 2)) + " Hz")
            print("")

            time.sleep(0.1)
    except KeyboardInterrupt:
        pass

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:
        error_message = "The operation is not implemented or is not supported/enabled in this service"
    print(f"{error_message}")

finally:
    if ('vi' in vars() and vi.id != 0):
        # close the session.
        CheckForError(vi, (scope_service.Close(
            niscope_types.CloseRequest(vi=vi))).status)
Esempio n. 2
0
    # 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.
except grpc.RpcError as e:
    error_message = e.details()
    print(error_message)
Esempio n. 3
0
            plt.subplots_adjust(wspace=0.5)
            plt.pause(0.001)
            time.sleep(0.1)
    except KeyboardInterrupt:
        pass

    for i in range(len(sessions)):
        sample_rate_result = scope_service.SampleRate(
            niscope_types.SampleRateRequest(vi=session))
        record_length_result = scope_service.ActualRecordLength(
            niscope_types.ActualRecordLengthRequest(vi=session))
        print(resources[i])
        print("Actual Sample Rate = %f" % sample_rate_result.sample_rate)
        print("Actual Record Length = %f\n" %
              record_length_result.record_length)

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:
        error_message = "The operation is not implemented or is not supported/enabled in this service"
    print(f"{error_message}")

finally:
    if ('vi' in vars() and vi.id != 0):
        # close the sessions.
        for session in sessions:
            close_request_result = scope_service.Close(
                niscope_types.CloseRequest(vi=session))
            CheckForError(scope_service, session, close_request_result.status)
Esempio n. 4
0
                                      num_samples=10000))
        CheckStatus(scope_service, vi, read_result)
        values = read_result.waveform[0:10]
        print(values)

        # Update the plot with the new waveform
        plt.plot(read_result.waveform[0:100])
        fig.canvas.draw()
        plt.pause(0.001)

        # Fetch the measured average frequency
        fetch_result = scope_service.FetchMeasurementStats(
            niscope_types.FetchMeasurementStatsRequest(
                vi=vi,
                channel_list=channels,
                timeout=1,
                scalar_meas_function=niscope_types.ScalarMeasurement.
                SCALAR_MEASUREMENT_NISCOPE_VAL_AVERAGE_FREQUENCY))
        CheckStatus(scope_service, vi, fetch_result)
        print("Average Frequency: " +
              str("%.2f" % round(fetch_result.result[0], 2)) + " Hz")
        print("")

        time.sleep(0.1)
except KeyboardInterrupt:
    pass

# Close
scope_service.Close(niscope_types.CloseRequest(vi=vi))
channel.close()
Esempio n. 5
0
        channel_list = channels,
        attribute_id = niscope_types.NiScopeAttributes.NISCOPE_ATTRIBUTE_MEAS_REF_LEVEL_UNITS,
        value = niscope_types.NiScopeInt32AttributeValues.NISCOPE_INT32_REF_LEVEL_UNITS_VAL_VOLTS
    ))
    CheckForError(vi, result.status)

    # Read a waveform from the scope
    read_result = scope_service.Read(niscope_types.ReadRequest(
        vi = vi,
        channel_list = channels,
        timeout = 10000,
        num_samples = 100000
    ))
    CheckForError(vi, read_result.status)
    values = read_result.waveform[0:10]
    print(values)

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:
        error_message = "The operation is not implemented or is not supported/enabled in this service"
    print(f"{error_message}")

finally:
    if('vi' in vars() and vi.id != 0):
        # close the session.
        CheckForError(vi, (scope_service.Close(niscope_types.CloseRequest(
            vi = vi
        ))).status)