Signals

class quanser.communications.qbinary.QBinarySignal(qb, signal)

A Python wrapper for a signal in the Quanser Binary API.

get_current_dimensions()

Gets the current dimensions of the signal. For fixed-size signals, the current dimensions will always be the same as the dimensions returned by get_dimensions().

Raises

StreamError – On a negative return code. A suitable error message may be retrieved using get_error_message.

Returns

The current dimensions of the signal.

Return type

array

Example

>>> from quanser.communications import QBinary, StreamError
>>> qb = QBinary()
>>> try:
>>>    qb.open_file("signals000000.qbin")
>>>
>>>    header = qb.read_header()
>>>    try:
>>>        while True:
>>>            tag = qb.read_next_tag()
>>>            if tag == QBPredefinedTag.END:
>>>                break
>>>            elif qb.is_signal(tag):
>>>                signal = qb.get_signal(tag)
>>>                dims = signal.get_current_dimensions()
>>>                # ...
>>>            # ...
...
>>>    except StreamError as e:
>>>        print(e.get_error_message())
>>>
>>>    qb.close()
>>> except StreamError as e:
>>>    print(e.get_error_message())
get_data_type()

Gets the data type of the signal

Raises

StreamError – On a negative return code. A suitable error message may be retrieved using get_error_message.

Returns

The data type of the signal (see QBDataType enumeration).

Return type

int

Example

>>> from quanser.communications import QBinary, StreamError
>>> qb = QBinary()
>>> try:
>>>    qb.open_file("signals000000.qbin")
>>>
>>>    header = qb.read_header()
>>>    try:
>>>        while True:
>>>            tag = qb.read_next_tag()
>>>            if tag == QBPredefinedTag.END:
>>>                break
>>>            elif qb.is_signal(tag):
>>>                signal = qb.get_signal(tag)
>>>                data_type = signal.get_data_type()
>>>                # ...
>>>            # ...
...
>>>    except StreamError as e:
>>>        print(e.get_error_message())
>>>
>>>    qb.close()
>>> except StreamError as e:
>>>    print(e.get_error_message())
get_dimensions()

Gets the dimensions of the signal. For variable-size signals, it returns the maximum possible dimensions of the signal.

Raises

StreamError – On a negative return code. A suitable error message may be retrieved using get_error_message.

Returns

The dimensions of the signal.

Return type

array

Example

>>> from quanser.communications import QBinary, StreamError
>>> qb = QBinary()
>>> try:
>>>    qb.open_file("signals000000.qbin")
>>>
>>>    header = qb.read_header()
>>>    try:
>>>        while True:
>>>            tag = qb.read_next_tag()
>>>            if tag == QBPredefinedTag.END:
>>>                break
>>>            elif qb.is_signal(tag):
>>>                signal = qb.get_signal(tag)
>>>                dims = signal.get_dimensions()
>>>                # ...
>>>            # ...
...
>>>    except StreamError as e:
>>>        print(e.get_error_message())
>>>
>>>    qb.close()
>>> except StreamError as e:
>>>    print(e.get_error_message())
get_flags()

Gets the flags associated with the signal

Raises

StreamError – On a negative return code. A suitable error message may be retrieved using get_error_message.

Returns

The flags associated with the signal (see QBSignalFlag enumeration).

Return type

int

Example

>>> from quanser.communications import QBinary, StreamError
>>> qb = QBinary()
>>> try:
>>>    qb.open_file("signals000000.qbin")
>>>
>>>    header = qb.read_header()
>>>    try:
>>>        while True:
>>>            tag = qb.read_next_tag()
>>>            if tag == QBPredefinedTag.END:
>>>                break
>>>            elif qb.is_signal(tag):
>>>                signal = qb.get_signal(tag)
>>>                flags = signal.get_flags()
>>>                # ...
>>>            # ...
...
>>>    except StreamError as e:
>>>        print(e.get_error_message())
>>>
>>>    qb.close()
>>> except StreamError as e:
>>>    print(e.get_error_message())
get_gain()

Gets the gain for scaling the raw signal to its standard units. The conversion formula is scaled = gain * (raw - pre_offset) + post_offset.

Raises

StreamError – On a negative return code. A suitable error message may be retrieved using get_error_message.

Returns

The gain for the signal.

Return type

double

Example

>>> from quanser.communications import QBinary, StreamError
>>> qb = QBinary()
>>> try:
>>>    qb.open_file("signals000000.qbin")
>>>
>>>    header = qb.read_header()
>>>    try:
>>>        while True:
>>>            tag = qb.read_next_tag()
>>>            if tag == QBPredefinedTag.END:
>>>                break
>>>            elif qb.is_signal(tag):
>>>                signal = qb.get_signal(tag)
>>>                gain = signal.get_gain()
>>>                # ...
>>>            # ...
...
>>>    except StreamError as e:
>>>        print(e.get_error_message())
>>>
>>>    qb.close()
>>> except StreamError as e:
>>>    print(e.get_error_message())
get_name()

Gets the name of the signal

Raises

StreamError – On a negative return code. A suitable error message may be retrieved using get_error_message.

Returns

The name of the signal.

Return type

string

Example

>>> from quanser.communications import QBinary, StreamError
>>> qb = QBinary()
>>> try:
>>>    qb.open_file("signals000000.qbin")
>>>
>>>    header = qb.read_header()
>>>    try:
>>>        while True:
>>>            tag = qb.read_next_tag()
>>>            if tag == QBPredefinedTag.END:
>>>                break
>>>            elif qb.is_signal(tag):
>>>                signal = qb.get_signal(tag)
>>>                name = signal.get_name()
>>>                # ...
>>>            # ...
...
>>>    except StreamError as e:
>>>        print(e.get_error_message())
>>>
>>>    qb.close()
>>> except StreamError as e:
>>>    print(e.get_error_message())
get_number_of_elements()

Gets the number of elements in one sample of the signal, which is the product of the current dimensions of the signal.

Raises

StreamError – On a negative return code. A suitable error message may be retrieved using get_error_message.

Returns

The number of elements in one sample the signal.

Return type

int

Example

>>> from quanser.communications import QBinary, StreamError
>>> qb = QBinary()
>>> try:
>>>    qb.open_file("signals000000.qbin")
>>>
>>>    header = qb.read_header()
>>>    try:
>>>        while True:
>>>            tag = qb.read_next_tag()
>>>            if tag == QBPredefinedTag.END:
>>>                break
>>>            elif qb.is_signal(tag):
>>>                signal = qb.get_signal(tag)
>>>                n = signal.get_number_of_elements()
>>>                # ...
>>>            # ...
...
>>>    except StreamError as e:
>>>        print(e.get_error_message())
>>>
>>>    qb.close()
>>> except StreamError as e:
>>>    print(e.get_error_message())
get_number_of_fields()

Gets the number of fields of a signal, for signals that are structures (QBDataType.STRUCTURE).

Raises

StreamError – On a negative return code. A suitable error message may be retrieved using get_error_message.

Returns

The number of fields of the signal.

Return type

int

Example

>>> from quanser.communications import QBinary, StreamError
>>> qb = QBinary()
>>> try:
>>>    qb.open_file("signals000000.qbin")
>>>
>>>    header = qb.read_header()
>>>    try:
>>>        while True:
>>>            tag = qb.read_next_tag()
>>>            if tag == QBPredefinedTag.END:
>>>                break
>>>            elif qb.is_signal(tag):
>>>                signal = qb.get_signal(tag)
>>>                num_fields = signal.get_number_of_fields()
>>>                # ...
>>>            # ...
...
>>>    except StreamError as e:
>>>        print(e.get_error_message())
>>>
>>>    qb.close()
>>> except StreamError as e:
>>>    print(e.get_error_message())
get_period()

Gets the period of this periodic signal in timebase ticks.

Raises

StreamError – On a negative return code. A suitable error message may be retrieved using get_error_message.

Returns

The period of the periodic signal in timebase ticks.

Return type

int

Example

>>> from quanser.communications import QBinary, StreamError
>>> qb = QBinary()
>>> try:
>>>    qb.open_file("signals000000.qbin")
>>>
>>>    header = qb.read_header()
>>>    try:
>>>        while True:
>>>            tag = qb.read_next_tag()
>>>            if tag == QBPredefinedTag.END:
>>>                break
>>>            elif qb.is_signal(tag):
>>>                signal = qb.get_signal(tag)
>>>                period = signal.get_period()
>>>                # ...
>>>            # ...
...
>>>    except StreamError as e:
>>>        print(e.get_error_message())
>>>
>>>    qb.close()
>>> except StreamError as e:
>>>    print(e.get_error_message())
get_post_offset()

Gets the post-offset for converting the raw signal to its standard units. The conversion formula is scaled = gain * (raw - pre_offset) + post_offset.

Raises

StreamError – On a negative return code. A suitable error message may be retrieved using get_error_message.

Returns

The post-offset for the signal.

Return type

double

Example

>>> from quanser.communications import QBinary, StreamError
>>> qb = QBinary()
>>> try:
>>>    qb.open_file("signals000000.qbin")
>>>
>>>    header = qb.read_header()
>>>    try:
>>>        while True:
>>>            tag = qb.read_next_tag()
>>>            if tag == QBPredefinedTag.END:
>>>                break
>>>            elif qb.is_signal(tag):
>>>                signal = qb.get_signal(tag)
>>>                post_offset = signal.get_post_offset()
>>>                # ...
>>>            # ...
...
>>>    except StreamError as e:
>>>        print(e.get_error_message())
>>>
>>>    qb.close()
>>> except StreamError as e:
>>>    print(e.get_error_message())
get_pre_offset()

Gets the pre-offset for converting the raw signal to its standard units. The conversion formula is scaled = gain * (raw - pre_offset) + post_offset.

Raises

StreamError – On a negative return code. A suitable error message may be retrieved using get_error_message.

Returns

The pre-offset for the signal.

Return type

double

Example

>>> from quanser.communications import QBinary, StreamError
>>> qb = QBinary()
>>> try:
>>>    qb.open_file("signals000000.qbin")
>>>
>>>    header = qb.read_header()
>>>    try:
>>>        while True:
>>>            tag = qb.read_next_tag()
>>>            if tag == QBPredefinedTag.END:
>>>                break
>>>            elif qb.is_signal(tag):
>>>                signal = qb.get_signal(tag)
>>>                pre_offset = signal.get_pre_offset()
>>>                # ...
>>>            # ...
...
>>>    except StreamError as e:
>>>        print(e.get_error_message())
>>>
>>>    qb.close()
>>> except StreamError as e:
>>>    print(e.get_error_message())
get_sample_size()

Gets the size of one sample of the signal in bytes, which is typically the number of elements times the size of each element in bytes, but can differ when QBDataType.BIT data types are involved.

Raises

StreamError – On a negative return code. A suitable error message may be retrieved using get_error_message.

Returns

The number of bytes in one sample the signal.

Return type

int

Example

>>> from quanser.communications import QBinary, StreamError
>>> qb = QBinary()
>>> try:
>>>    qb.open_file("signals000000.qbin")
>>>
>>>    header = qb.read_header()
>>>    try:
>>>        while True:
>>>            tag = qb.read_next_tag()
>>>            if tag == QBPredefinedTag.END:
>>>                break
>>>            elif qb.is_signal(tag):
>>>                signal = qb.get_signal(tag)
>>>                sample_size = signal.get_sample_size()
>>>                # ...
>>>            # ...
...
>>>    except StreamError as e:
>>>        print(e.get_error_message())
>>>
>>>    qb.close()
>>> except StreamError as e:
>>>    print(e.get_error_message())
get_scaled_value()

Gets the current scaled value of the signal (after gain and offsets applied).

Raises

StreamError – On a negative return code. A suitable error message may be retrieved using get_error_message.

Returns

The current scaled value of the signal.

Return type

array or list

Example

>>> from quanser.communications import QBinary, StreamError
>>> qb = QBinary()
>>> try:
>>>    qb.open_file("signals000000.qbin")
>>>
>>>    header = qb.read_header()
>>>    try:
>>>        while True:
>>>            tag = qb.read_next_tag()
>>>            if tag == QBPredefinedTag.END:
>>>                break
>>>            elif qb.is_signal(tag):
>>>                signal = qb.get_signal(tag)
>>>                time = signal.get_time()
>>>                value = signal.get_scaled_value()
>>>                # ...
>>>            # ...
...
>>>    except StreamError as e:
>>>        print(e.get_error_message())
>>>
>>>    qb.close()
>>> except StreamError as e:
>>>    print(e.get_error_message())
get_signals()

Gets thet tags of the signals in this signal group.

Raises

StreamError – On a negative return code. A suitable error message may be retrieved using get_error_message.

Returns

The tags of the signals in this signal group.

Return type

array

Example

>>> from quanser.communications import QBinary, StreamError
>>> qb = QBinary()
>>> try:
>>>    qb.open_file("signals000000.qbin")
>>>
>>>    header = qb.read_header()
>>>    try:
>>>        while True:
>>>            tag = qb.read_next_tag()
>>>            if tag == QBPredefinedTag.END:
>>>                break
>>>            elif tag == MY_GROUP_TAG
>>>                group = qb.get_signal(tag)
>>>                tags = group.get_signals()
>>>                # ...
>>>            # ...
...
>>>    except StreamError as e:
>>>        print(e.get_error_message())
>>>
>>>    qb.close()
>>> except StreamError as e:
>>>    print(e.get_error_message())
get_tag()

Gets the tag associated with the signal

Raises

StreamError – On a negative return code. A suitable error message may be retrieved using get_error_message.

Returns

The tag associated with the signal.

Return type

int

get_time()

Gets the current time for the signal.

Raises

StreamError – On a negative return code. A suitable error message may be retrieved using get_error_message.

Returns

The current time for the signal.

Return type

double

Example

>>> from quanser.communications import QBinary, StreamError
>>> qb = QBinary()
>>> try:
>>>    qb.open_file("signals000000.qbin")
>>>
>>>    header = qb.read_header()
>>>    try:
>>>        while True:
>>>            tag = qb.read_next_tag()
>>>            if tag == QBPredefinedTag.END:
>>>                break
>>>            elif qb.is_signal(tag):
>>>                signal = qb.get_signal(tag)
>>>                time = signal.get_time()
>>>                # ...
>>>            # ...
...
>>>    except StreamError as e:
>>>        print(e.get_error_message())
>>>
>>>    qb.close()
>>> except StreamError as e:
>>>    print(e.get_error_message())
get_timebase_frequency()

Gets the frequency of the timebase for this timestamp signal.

Raises

StreamError – On a negative return code. A suitable error message may be retrieved using get_error_message.

Returns

The frequency of the timebase for this timestamp signal.

Return type

double

Example

>>> from quanser.communications import QBinary, StreamError
>>> qb = QBinary()
>>> try:
>>>    qb.open_file("signals000000.qbin")
>>>
>>>    header = qb.read_header()
>>>    try:
>>>        while True:
>>>            tag = qb.read_next_tag()
>>>            if tag == QBPredefinedTag.END:
>>>                break
>>>            elif qb.is_signal(tag):
>>>                signal = qb.get_signal(tag)
>>>                timestamp_tag = signal.get_timestamp()
>>>                timestamp = qb.get_signal(timestamp_tag)
>>>                frequency = qb.get_timebase_frequency(timestamp)
>>>                # ...
>>>            # ...
...
>>>    except StreamError as e:
>>>        print(e.get_error_message())
>>>
>>>    qb.close()
>>> except StreamError as e:
>>>    print(e.get_error_message())
get_timestamp()

Gets the tag for the timestamp associated with the signal.

Raises

StreamError – On a negative return code. A suitable error message may be retrieved using get_error_message.

Returns

The tag of the timestamp for the signal.

Return type

int

Example

>>> from quanser.communications import QBinary, StreamError
>>> qb = QBinary()
>>> try:
>>>    qb.open_file("signals000000.qbin")
>>>
>>>    header = qb.read_header()
>>>    try:
>>>        while True:
>>>            tag = qb.read_next_tag()
>>>            if tag == QBPredefinedTag.END:
>>>                break
>>>            elif qb.is_signal(tag):
>>>                signal = qb.get_signal(tag)
>>>                timestamp_tag = signal.get_timestamp()
>>>                # ...
>>>            # ...
...
>>>    except StreamError as e:
>>>        print(e.get_error_message())
>>>
>>>    qb.close()
>>> except StreamError as e:
>>>    print(e.get_error_message())
get_type()

Gets the type of the signal

Raises

StreamError – On a negative return code. A suitable error message may be retrieved using get_error_message.

Returns

The type of the signal (see QBSignalType enumeration).

Return type

int

Example

>>> from quanser.communications import QBinary, StreamError
>>> qb = QBinary()
>>> try:
>>>    qb.open_file("signals000000.qbin")
>>>
>>>    header = qb.read_header()
>>>    try:
>>>        while True:
>>>            tag = qb.read_next_tag()
>>>            if tag == QBPredefinedTag.END:
>>>                break
>>>            elif qb.is_signal(tag):
>>>                signal = qb.get_signal(tag)
>>>                type = signal.get_type()
>>>                # ...
>>>            # ...
...
>>>    except StreamError as e:
>>>        print(e.get_error_message())
>>>
>>>    qb.close()
>>> except StreamError as e:
>>>    print(e.get_error_message())
get_units()

Gets the standard units for the signal after applying the conversion formula.

Raises

StreamError – On a negative return code. A suitable error message may be retrieved using get_error_message.

Returns

The standard units of the signal.

Return type

string

Example

>>> from quanser.communications import QBinary, StreamError
>>> qb = QBinary()
>>> try:
>>>    qb.open_file("signals000000.qbin")
>>>
>>>    header = qb.read_header()
>>>    try:
>>>        while True:
>>>            tag = qb.read_next_tag()
>>>            if tag == QBPredefinedTag.END:
>>>                break
>>>            elif qb.is_signal(tag):
>>>                signal = qb.get_signal(tag)
>>>                units = signal.get_units()
>>>                # ...
>>>            # ...
...
>>>    except StreamError as e:
>>>        print(e.get_error_message())
>>>
>>>    qb.close()
>>> except StreamError as e:
>>>    print(e.get_error_message())
get_value()

Gets the current value of the signal.

Raises

StreamError – On a negative return code. A suitable error message may be retrieved using get_error_message.

Returns

The current value of the signal.

Return type

array or list

Example

>>> from quanser.communications import QBinary, StreamError
>>> qb = QBinary()
>>> try:
>>>    qb.open_file("signals000000.qbin")
>>>
>>>    header = qb.read_header()
>>>    try:
>>>        while True:
>>>            tag = qb.read_next_tag()
>>>            if tag == QBPredefinedTag.END:
>>>                break
>>>            elif qb.is_signal(tag):
>>>                signal = qb.get_signal(tag)
>>>                time = signal.get_time()
>>>                value = signal.get_value()
>>>                # ...
>>>            # ...
...
>>>    except StreamError as e:
>>>        print(e.get_error_message())
>>>
>>>    qb.close()
>>> except StreamError as e:
>>>    print(e.get_error_message())