QBinary I/O
- QBinary.read_header()
Reads the header of the Quanser Binary. The header must be read before anything else.
- Raises
StreamError – On a negative return code. A suitable error message may be retrieved using get_error_message.
- Returns
A structure containing the header information.
- Return type
t_qb_header
Example
>>> from quanser.communications import QBinary, StreamError >>> qb = QBinary() >>> try: >>> qb.open_file("signals000000.qbin") >>> >>> header = qb.read_header() >>> print("Signature: {0}{1}".format(header.qb_tag[0], header.qb_tag[1])) >>> print("Version: {0}.{1}".format(header.major_version, header.minor_version)) >>> printf("Flags: {0}".format(header.flags)) ... >>> qb.close() >>> except StreamError as e: >>> print(e.get_error_message())
- QBinary.read_next_tag()
Reads the next tag from the Quanser Binary. After the reading the header, use this method to progressively read the rest of the Quanser Binary.
- Raises
StreamError – On a negative return code. A suitable error message may be retrieved using get_error_message.
- Returns
The next tag read from the Quanser Binary.
- 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): >>> # ... >>> # ... ... >>> except StreamError as e: >>> print(e.get_error_message()) >>> >>> qb.close() >>> except StreamError as e: >>> print(e.get_error_message())
- QBinary.is_signal(tag)
Indicates whether the given tag represents a signal or signal group.
- Raises
StreamError – On a negative return code. A suitable error message may be retrieved using get_error_message.
- Returns
Whether the tag represents a signal (True) or not (False).
- Return type
boolean
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): >>> # ... >>> # ... ... >>> except StreamError as e: >>> print(e.get_error_message()) >>> >>> qb.close() >>> except StreamError as e: >>> print(e.get_error_message())