commands:rdsbyte
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| commands:rdsbyte [2024/06/18 21:18] – minor wording change brandon | commands:rdsbyte [2026/03/12 17:25] (current) – jon | ||
|---|---|---|---|
| Line 16: | Line 16: | ||
| <-- | <-- | ||
| - | Requests the TG-1000 and MS-2000 to respond with the '' | + | Requests the TG-1000 and MS-2000 to respond with the '' |
| + | |||
| + | |||
| + | <WRAP center round info 80%> | ||
| + | **Note:** If you don't see the serial response, it may be because the reply is in raw bytes, see the [[# | ||
| + | </ | ||
| == Status Byte Format == | == Status Byte Format == | ||
| Line 79: | Line 84: | ||
| </ | </ | ||
| + | === Python Helper Script === | ||
| - | --> Python script to query the status byte | + | {{section>:python_code# |
| - | + | ||
| - | <code python statusbyte.py> | + | |
| - | import serial | + | |
| - | from enum import Flag, auto | + | |
| - | + | ||
| - | class StatusByte(Flag): | + | |
| - | """ | + | |
| - | The Status Byte returned by the RDSBYTE (RB) command. | + | |
| - | The value parameter should be an 8-bit int, 0-255. | + | |
| - | 00000001 <- Bit 0 is 1, commanded move in progress. | + | |
| - | """ | + | |
| - | COMMANDED_MOVE = auto() | + | |
| - | AXIS_ENABLED = auto() | + | |
| - | MOTOR_ACTIVE = auto() | + | |
| - | JS_KNOB_ENABLED = auto() | + | |
| - | MOTOR_RAMPING = auto() | + | |
| - | MOTOR_RAMPING_UP = auto() | + | |
| - | AT_UPPER_LIMIT = auto() | + | |
| - | AT_LOWER_LIMIT = auto() | + | |
| - | + | ||
| - | def main() -> None: | + | |
| - | # use an empty string for MS2000 (card_address = "" | + | |
| - | card_address = " | + | |
| - | + | ||
| - | # which axes to query (for a single axis use: axes = [" | + | |
| - | # axes_byte_len is the number of bytes that need to be read for RDSBYTE | + | |
| - | axes = [" | + | |
| - | axes_str = " " | + | |
| - | axes_byte_len = len(axes) + 3 # 3 bytes for ':', | + | |
| - | + | ||
| - | with serial.Serial(" | + | |
| - | # query the controller for the status byte of each axis | + | |
| - | command = f"{card_address}RB | + | |
| - | serial_port.write(bytes(command, | + | |
| - | response = serial_port.read(axes_byte_len) | + | |
| - | + | ||
| - | # report and check for errors | + | |
| - | print(f" | + | |
| - | print(f" | + | |
| - | print(f" | + | |
| - | if b" | + | |
| - | print(" | + | |
| - | return | + | |
| - | + | ||
| - | | + | |
| - | response_bytes = [byte for byte in response] | + | |
| - | print(f" | + | |
| - | + | ||
| - | # get the status byte for each axis and skip the first byte (':' | + | |
| - | status_bytes = [response[i] for i in range(1, len(axes) + 1)] | + | |
| - | print(f" | + | |
| - | + | ||
| - | # create a dictionary that maps uppercase axis names to status bytes | + | |
| - | status_bytes_dict = {axis.upper(): | + | |
| - | print(f" | + | |
| - | + | ||
| - | # check the status of each axis | + | |
| - | for axis in axes: | + | |
| - | status_byte = status_bytes_dict.get(axis.upper()) | + | |
| - | # check a single flag | + | |
| - | is_at_upper_limit = StatusByte.AT_UPPER_LIMIT in status_byte | + | |
| - | # check multiple flags | + | |
| - | is_js_and_axis_enabled = StatusByte.JS_KNOB_ENABLED | StatusByte.AXIS_ENABLED in status_byte | + | |
| - | # check if one flag is True and the other is False | + | |
| - | is_motor_on_and_not_cmd_move = StatusByte.MOTOR_ACTIVE in status_byte and StatusByte.COMMANDED_MOVE not in status_byte | + | |
| - | print(f" | + | |
| - | print(f" | + | |
| - | print(f" | + | |
| - | print(f" | + | |
| - | print(f" | + | |
| - | + | ||
| - | if __name__ == " | + | |
| - | main() | + | |
| - | + | ||
| - | </ | + | |
| - | + | ||
| - | <-- | + | |
| {{tag> | {{tag> | ||
Address: 29391 W Enid Rd. Eugene, OR 97402, USA | Phone: +1 (541) 461-8181
commands/rdsbyte.1718759925.txt.gz · Last modified: by brandon
