예제 #1
0
def get_session_u32_array(ref, prop_id):
    value_size = _funcs.nx_get_property_size(ref, prop_id)

    ref_ctypes = _ctypedefs.nxSessionRef_t(ref)
    prop_id_ctypes = _ctypedefs.u32(prop_id)
    prop_size_ctypes = _ctypedefs.u32(value_size)
    value_ctypes = (_ctypedefs.u32 * (value_size // _ctypedefs.u32.BYTES))()
    result = _cfuncs.lib.nx_get_property(ref_ctypes, prop_id_ctypes,
                                         prop_size_ctypes, value_ctypes)
    _errors.check_for_error(result.value)
    for value in value_ctypes:
        yield value.value
예제 #2
0
def get_database_string(ref, prop_id):
    # type: (int, int) -> typing.Text
    value_size = _funcs.nxdb_get_property_size(ref, prop_id)

    ref_ctypes = _ctypedefs.nxDatabaseRef_t(ref)
    prop_id_ctypes = _ctypedefs.u32(prop_id)
    prop_size_ctypes = _ctypedefs.u32(value_size)
    value_ctypes = ctypes.create_string_buffer(value_size)
    result = _cfuncs.lib.nxdb_get_property(ref_ctypes, prop_id_ctypes,
                                           prop_size_ctypes, value_ctypes)
    _errors.check_for_error(result.value)
    return value_ctypes.value.decode("ascii")
예제 #3
0
def get_database_u8_array(ref, prop_id):
    value_size = _funcs.nx_get_property_size(ref, prop_id)

    ref_ctypes = _ctypedefs.nxDatabaseRef_t(ref)
    prop_id_ctypes = _ctypedefs.u32(prop_id)
    prop_size_ctypes = _ctypedefs.u32(value_size)
    value_ctypes = (_ctypedefs.u8 * (value_size // _ctypedefs.u8.BYTES))()
    result = _cfuncs.lib.nxdb_get_property(ref_ctypes, prop_id_ctypes,
                                           prop_size_ctypes, value_ctypes)
    _errors.check_for_error(result.value)
    for value in value_ctypes:
        yield value.value
예제 #4
0
def set_session_u32_array(ref, prop_id, value):
    # type: (int, int, typing.List[int]) -> None
    value_size = len(value) * _ctypedefs.u32.BYTES
    elements = value_size // _ctypedefs.u32.BYTES

    ref_ctypes = _ctypedefs.nxSessionRef_t(ref)
    prop_id_ctypes = _ctypedefs.u32(prop_id)
    prop_size_ctypes = _ctypedefs.u32(value_size)
    value_ctypes = (_ctypedefs.u32 * (elements))(*value)  # type: ignore
    result = _cfuncs.lib.nx_set_property(ref_ctypes, prop_id_ctypes,
                                         prop_size_ctypes, value_ctypes)
    _errors.check_for_error(result.value)
예제 #5
0
def nx_read_frame(session_ref, bytes_to_read, timeout):
    session_ref_ctypes = _ctypedefs.nxSessionRef_t(session_ref)
    buffer_ctypes = (_ctypedefs.char * bytes_to_read)()
    size_of_buffer_ctypes = _ctypedefs.u32(_ctypedefs.char.BYTES *
                                           bytes_to_read)
    number_of_bytes_returned_ctypes = _ctypedefs.u32()
    timeout_ctypes = _ctypedefs.f64(timeout)
    result = _cfuncs.lib.nx_read_frame(
        session_ref_ctypes, buffer_ctypes, size_of_buffer_ctypes,
        timeout_ctypes, ctypes.pointer(number_of_bytes_returned_ctypes))
    _errors.check_for_error(result.value)
    return buffer_ctypes.raw, number_of_bytes_returned_ctypes.value
예제 #6
0
def set_session_sub_f64(ref, sub, prop_id, value):
    # type: (int, int, int, float) -> None
    ref_ctypes = _ctypedefs.nxSessionRef_t(ref)
    sub_ctypes = _ctypedefs.u32(sub)
    prop_id_ctypes = _ctypedefs.u32(prop_id)
    prop_size_ctypes = _ctypedefs.u32(_ctypedefs.f64.BYTES)
    value_ctypes = _ctypedefs.f64(value)
    value_ctypes_ptr = ctypes.pointer(value_ctypes)
    result = _cfuncs.lib.nx_set_sub_property(ref_ctypes, sub_ctypes,
                                             prop_id_ctypes, prop_size_ctypes,
                                             value_ctypes_ptr)
    _errors.check_for_error(result.value)
예제 #7
0
def set_database_string(ref, prop_id, value):
    # type: (int, int, typing.Text) -> None
    value_bytes = value.encode("ascii")
    value_size = len(value_bytes) * _ctypedefs.char.BYTES

    ref_ctypes = _ctypedefs.nxDatabaseRef_t(ref)
    prop_id_ctypes = _ctypedefs.u32(prop_id)
    prop_size_ctypes = _ctypedefs.u32(value_size)
    value_ctypes = ctypes.create_string_buffer(value_bytes, value_size)
    result = _cfuncs.lib.nxdb_set_property(ref_ctypes, prop_id_ctypes,
                                           prop_size_ctypes, value_ctypes)
    _errors.check_for_error(result.value)
예제 #8
0
def set_session_sub_string(ref, sub, prop_id, value):
    value = value.encode("ascii")
    value_size = len(value) * _ctypedefs.char.BYTES

    ref_ctypes = _ctypedefs.nxSessionRef_t(ref)
    sub_ctypes = _ctypedefs.u32(sub)
    prop_id_ctypes = _ctypedefs.u32(prop_id)
    prop_size_ctypes = _ctypedefs.u32(value_size)
    value_ctypes = ctypes.create_string_buffer(value, value_size)
    result = _cfuncs.lib.nx_set_sub_property(ref_ctypes, sub_ctypes,
                                             prop_id_ctypes, prop_size_ctypes,
                                             value_ctypes)
    _errors.check_for_error(result.value)
예제 #9
0
def set_session_u32_array(ref, prop_id, value):
    value_size = len(value) * _ctypedefs.u32.BYTES

    ref_ctypes = _ctypedefs.nxSessionRef_t(ref)
    prop_id_ctypes = _ctypedefs.u32(prop_id)
    prop_size_ctypes = _ctypedefs.u32(value_size)
    value_ctypes = (_ctypedefs.u32 * (value_size // _ctypedefs.u32.BYTES))(*value)
    result = _cfuncs.lib.nx_set_property(
        ref_ctypes,
        prop_id_ctypes,
        prop_size_ctypes,
        value_ctypes)
    _errors.check_for_error(result.value)
예제 #10
0
def get_database_ref(ref, prop_id):
    ref_ctypes = _ctypedefs.nxDatabaseRef_t(ref)
    prop_id_ctypes = _ctypedefs.u32(prop_id)
    prop_size_ctypes = _ctypedefs.u32(_ctypedefs.nxDatabase_t.BYTES)
    value_ctypes = _ctypedefs.nxDatabaseRef_t()
    value_ctypes_ptr = ctypes.pointer(value_ctypes)
    result = _cfuncs.lib.nxdb_get_property(
        ref_ctypes,
        prop_id_ctypes,
        prop_size_ctypes,
        value_ctypes_ptr)
    _errors.check_for_error(result.value)
    return value_ctypes.value
예제 #11
0
def set_database_ref_array(ref, prop_id, value):
    value_size = len(value) * _ctypedefs.nxDatabase_t.BYTES

    ref_ctypes = _ctypedefs.nxDatabaseRef_t(ref)
    prop_id_ctypes = _ctypedefs.u32(prop_id)
    prop_size_ctypes = _ctypedefs.u32(value_size)
    value_ctypes = (_ctypedefs.nxDatabaseRef_t * (value_size // _ctypedefs.nxDatabase_t.BYTES))(*value)
    result = _cfuncs.lib.nxdb_set_property(
        ref_ctypes,
        prop_id_ctypes,
        prop_size_ctypes,
        value_ctypes)
    _errors.check_for_error(result.value)
예제 #12
0
def get_session_u32(ref, prop_id):
    ref_ctypes = _ctypedefs.nxSessionRef_t(ref)
    prop_id_ctypes = _ctypedefs.u32(prop_id)
    prop_size_ctypes = _ctypedefs.u32(_ctypedefs.u32.BYTES)
    value_ctypes = _ctypedefs.u32()
    value_ctypes_ptr = ctypes.pointer(value_ctypes)
    result = _cfuncs.lib.nx_get_property(
        ref_ctypes,
        prop_id_ctypes,
        prop_size_ctypes,
        value_ctypes_ptr)
    _errors.check_for_error(result.value)
    return value_ctypes.value
예제 #13
0
def get_session_u32_array(ref, prop_id):
    # type: (int, int) -> typing.Iterable[int]
    value_size = _funcs.nx_get_property_size(ref, prop_id)
    elements = value_size // _ctypedefs.u32.BYTES

    ref_ctypes = _ctypedefs.nxSessionRef_t(ref)
    prop_id_ctypes = _ctypedefs.u32(prop_id)
    prop_size_ctypes = _ctypedefs.u32(value_size)
    value_ctypes = (_ctypedefs.u32 * (elements))()  # type: ignore
    result = _cfuncs.lib.nx_get_property(ref_ctypes, prop_id_ctypes,
                                         prop_size_ctypes, value_ctypes)
    _errors.check_for_error(result.value)
    for value in value_ctypes:
        yield value.value
예제 #14
0
def nxdb_get_property_size(
    db_object_ref,
    property_id,
):
    db_object_ref_ctypes = _ctypedefs.nxDatabaseRef_t(db_object_ref)
    property_id_ctypes = _ctypedefs.u32(property_id)
    property_size_ctypes = _ctypedefs.u32()
    result = _cfuncs.lib.nxdb_get_property_size(
        db_object_ref_ctypes,
        property_id_ctypes,
        ctypes.pointer(property_size_ctypes),
    )
    _errors.check_for_error(result.value)
    return property_size_ctypes.value
예제 #15
0
def nx_get_property_size(
    session_ref,
    property_id,
):
    session_ref_ctypes = _ctypedefs.nxSessionRef_t(session_ref)
    property_id_ctypes = _ctypedefs.u32(property_id)
    property_size_ctypes = _ctypedefs.u32()
    result = _cfuncs.lib.nx_get_property_size(
        session_ref_ctypes,
        property_id_ctypes,
        ctypes.pointer(property_size_ctypes),
    )
    _errors.check_for_error(result.value)
    return property_size_ctypes.value
예제 #16
0
def get_session_string(ref, prop_id):
    value_size = _funcs.nx_get_property_size(ref, prop_id)

    ref_ctypes = _ctypedefs.nxSessionRef_t(ref)
    prop_id_ctypes = _ctypedefs.u32(prop_id)
    prop_size_ctypes = _ctypedefs.u32(value_size)
    value_ctypes = ctypes.create_string_buffer(value_size)
    result = _cfuncs.lib.nx_get_property(
        ref_ctypes,
        prop_id_ctypes,
        prop_size_ctypes,
        value_ctypes)
    _errors.check_for_error(result.value)
    return value_ctypes.value.decode("ascii")
예제 #17
0
def nxdb_get_database_list_sizes(
        ip_address,  # type: typing.Text
):
    # type: (...) -> typing.Tuple[int, int]
    ip_address_ctypes = ctypes.create_string_buffer(ip_address.encode('ascii'))
    size_of_alias_buffer_ctypes = _ctypedefs.u32()
    size_of_filepath_buffer_ctypes = _ctypedefs.u32()
    result = _cfuncs.lib.nxdb_get_database_list_sizes(
        ip_address_ctypes,
        size_of_alias_buffer_ctypes,
        size_of_filepath_buffer_ctypes,
    )
    _errors.check_for_error(result.value)
    return size_of_alias_buffer_ctypes.value, size_of_filepath_buffer_ctypes.value
예제 #18
0
def nx_read_signal_single_point(
    session_ref,
    num_signals,
):
    session_ref_ctypes = _ctypedefs.nxSessionRef_t(session_ref)
    value_buffer_ctypes = (_ctypedefs.f64 * num_signals)()
    size_of_value_buffer_ctypes = _ctypedefs.u32(_ctypedefs.f64.BYTES *
                                                 num_signals)
    timestamp_buffer_ctypes = (_ctypedefs.nxTimestamp_t * num_signals)()
    size_of_timestamp_buffer_ctypes = _ctypedefs.u32(
        _ctypedefs.nxTimestamp_t.BYTES * num_signals)
    result = _cfuncs.lib.nx_read_signal_single_point(
        session_ref_ctypes, value_buffer_ctypes, size_of_value_buffer_ctypes,
        timestamp_buffer_ctypes, size_of_timestamp_buffer_ctypes)
    _errors.check_for_error(result.value)
    return timestamp_buffer_ctypes, value_buffer_ctypes
예제 #19
0
def nx_create_session(
        database_name,  # type: typing.Text
        cluster_name,  # type: typing.Text
        list,  # type: typing.Text
        interface,  # type: typing.Text
        mode,  # type: _enums.CreateSessionMode
):
    # type: (...) -> int
    database_name_ctypes = ctypes.create_string_buffer(
        database_name.encode('ascii'))
    cluster_name_ctypes = ctypes.create_string_buffer(
        cluster_name.encode('ascii'))
    list_ctypes = ctypes.create_string_buffer(list.encode('ascii'))
    interface_ctypes = ctypes.create_string_buffer(interface.encode('ascii'))
    mode_ctypes = _ctypedefs.u32(mode.value)
    session_ref_ctypes = _ctypedefs.nxSessionRef_t()
    result = _cfuncs.lib.nx_create_session(
        database_name_ctypes,
        cluster_name_ctypes,
        list_ctypes,
        interface_ctypes,
        mode_ctypes,
        ctypes.pointer(session_ref_ctypes),
    )
    _errors.check_for_error(result.value)
    return session_ref_ctypes.value
예제 #20
0
def nx_write_frame(session_ref, buffer, timeout):
    session_ref_ctypes = _ctypedefs.nxSessionRef_t(session_ref)
    buffer_ctypes = (_ctypedefs.char * len(buffer))(*buffer)
    size_of_buffer_ctypes = _ctypedefs.u32(_ctypedefs.char.BYTES * len(buffer))
    timeout_ctypes = _ctypedefs.f64(timeout)
    result = _cfuncs.lib.nx_write_frame(session_ref_ctypes, buffer_ctypes,
                                        size_of_buffer_ctypes, timeout_ctypes)
    _errors.check_for_error(result.value)
예제 #21
0
def nx_read_frame(
        session_ref,  # type: int
        bytes_to_read,  # type: int
        timeout,  # type: float
):
    # type: (...) -> typing.Tuple[bytes, int]
    session_ref_ctypes = _ctypedefs.nxSessionRef_t(session_ref)
    buffer_ctypes = (_ctypedefs.byte * bytes_to_read)()  # type: ignore
    size_of_buffer_ctypes = _ctypedefs.u32(_ctypedefs.byte.BYTES *
                                           bytes_to_read)
    number_of_bytes_returned_ctypes = _ctypedefs.u32()
    timeout_ctypes = _ctypedefs.f64(timeout)
    result = _cfuncs.lib.nx_read_frame(
        session_ref_ctypes, buffer_ctypes, size_of_buffer_ctypes,
        timeout_ctypes, ctypes.pointer(number_of_bytes_returned_ctypes))
    _errors.check_for_error(result.value)
    return buffer_ctypes.raw, number_of_bytes_returned_ctypes.value
예제 #22
0
def nxdb_get_dbc_attribute_size(
    db_object_ref,
    mode,
    attribute_name,
):
    db_object_ref_ctypes = _ctypedefs.nxDatabaseRef_t(db_object_ref)
    mode_ctypes = _ctypedefs.u32(mode)
    attribute_name_ctypes = _ctypedefs.char_p(attribute_name.encode('ascii'))
    attribute_text_size_ctypes = _ctypedefs.u32()
    result = _cfuncs.lib.nxdb_get_dbc_attribute_size(
        db_object_ref_ctypes,
        mode_ctypes,
        attribute_name_ctypes,
        ctypes.pointer(attribute_text_size_ctypes),
    )
    _errors.check_for_error(result.value)
    return attribute_text_size_ctypes.value
예제 #23
0
def nx_get_sub_property_size(
    session_ref,  # type: int
    active_index,  # type: int
    property_id,  # type: int
):
    # type: (...) -> int
    session_ref_ctypes = _ctypedefs.nxSessionRef_t(session_ref)
    active_index_ctypes = _ctypedefs.u32(active_index)
    property_id_ctypes = _ctypedefs.u32(property_id)
    property_size_ctypes = _ctypedefs.u32()
    result = _cfuncs.lib.nx_get_sub_property_size(
        session_ref_ctypes,
        active_index_ctypes,
        property_id_ctypes,
        ctypes.pointer(property_size_ctypes),
    )
    _errors.check_for_error(result.value)
    return property_size_ctypes.value
 def state(self):
     # type: () -> constants.SessionInfoState
     """:any:`nixnet._enums.SessionInfoState`: Session running state."""
     state_value_ctypes = _ctypedefs.u32()
     state_size = ctypes.sizeof(state_value_ctypes)
     _funcs.nx_read_state(self._handle, constants.ReadState.SESSION_INFO,
                          state_size, ctypes.pointer(state_value_ctypes))
     state = state_value_ctypes.value
     return constants.SessionInfoState(state)
예제 #25
0
def status_to_string(status_code):
    buffer_size = 2048
    buffer_size_ctypes = _ctypedefs.u32(buffer_size)
    buffer_ctypes = ctypes.create_string_buffer(buffer_size)
    status_code_ctypes = _ctypedefs.nxStatus_t(status_code)
    _cfuncs.lib.nx_status_to_string(status_code_ctypes, buffer_size_ctypes,
                                    buffer_ctypes)
    status_string = buffer_ctypes.value.decode("ascii")
    return status_string
예제 #26
0
def nxdb_get_dbc_attribute_size(
        db_object_ref,  # type: int
        mode,  # type: _enums.GetDbcAttributeMode
        attribute_name,  # type: typing.Text
):
    # type: (...) -> int
    db_object_ref_ctypes = _ctypedefs.nxDatabaseRef_t(db_object_ref)
    mode_ctypes = _ctypedefs.u32(mode.value)
    attribute_name_ctypes = _ctypedefs.char_p(attribute_name.encode('ascii'))
    attribute_text_size_ctypes = _ctypedefs.u32()
    result = _cfuncs.lib.nxdb_get_dbc_attribute_size(
        db_object_ref_ctypes,
        mode_ctypes,
        attribute_name_ctypes,
        ctypes.pointer(attribute_text_size_ctypes),
    )
    _errors.check_for_error(result.value)
    return attribute_text_size_ctypes.value
 def can_comm(self):
     # type: () -> types.CanComm
     """:any:`nixnet.types.CanComm`: CAN Communication state"""
     state_value_ctypes = _ctypedefs.u32()
     state_size = ctypes.sizeof(state_value_ctypes)
     _funcs.nx_read_state(self._handle, constants.ReadState.CAN_COMM,
                          state_size, ctypes.pointer(state_value_ctypes))
     bitfield = state_value_ctypes.value
     return _utils.parse_can_comm_bitfield(bitfield)
예제 #28
0
def nx_read_signal_single_point(
        session_ref,  # type: int
        num_signals,  # type: int
):
    # type: (...) -> typing.Tuple[typing.List[_ctypedefs.nxTimestamp_t], typing.List[_ctypedefs.f64]]
    session_ref_ctypes = _ctypedefs.nxSessionRef_t(session_ref)
    value_buffer_ctypes = (_ctypedefs.f64 * num_signals)()  # type: ignore
    size_of_value_buffer_ctypes = _ctypedefs.u32(_ctypedefs.f64.BYTES *
                                                 num_signals)
    timestamp_buffer_ctypes = (_ctypedefs.nxTimestamp_t *
                               num_signals)()  # type: ignore
    size_of_timestamp_buffer_ctypes = _ctypedefs.u32(
        _ctypedefs.nxTimestamp_t.BYTES * num_signals)
    result = _cfuncs.lib.nx_read_signal_single_point(
        session_ref_ctypes, value_buffer_ctypes, size_of_value_buffer_ctypes,
        timestamp_buffer_ctypes, size_of_timestamp_buffer_ctypes)
    _errors.check_for_error(result.value)
    return timestamp_buffer_ctypes, value_buffer_ctypes
예제 #29
0
def nx_read_state(
        session_ref,  # type: int
        state_id,  # type: _enums.ReadState
        state_value_ctypes_ptr,  # type: typing.Any
):
    # type: (...) -> typing.Tuple[typing.Any, int]
    session_ref_ctypes = _ctypedefs.nxSessionRef_t(session_ref)
    state_id_ctypes = _ctypedefs.u32(state_id.value)
    state_size_ctypes = _ctypedefs.u32(ctypes.sizeof(state_value_ctypes_ptr))
    fault_ctypes = _ctypedefs.nxStatus_t()
    result = _cfuncs.lib.nx_read_state(
        session_ref_ctypes,
        state_id_ctypes,
        state_size_ctypes,
        state_value_ctypes_ptr,
        ctypes.pointer(fault_ctypes),
    )
    _errors.check_for_error(result.value)
    return fault_ctypes.value
예제 #30
0
def nx_wait(
    session_ref,
    condition,
    param_in,
    timeout,
):
    session_ref_ctypes = _ctypedefs.nxSessionRef_t(session_ref)
    condition_ctypes = _ctypedefs.u32(condition)
    param_in_ctypes = _ctypedefs.u32(param_in)
    timeout_ctypes = _ctypedefs.f64(timeout)
    param_out_ctypes = _ctypedefs.u32()
    result = _cfuncs.lib.nx_wait(
        session_ref_ctypes,
        condition_ctypes,
        param_in_ctypes,
        timeout_ctypes,
        ctypes.pointer(param_out_ctypes),
    )
    _errors.check_for_error(result.value)
    return param_out_ctypes.value