Logo
Telescience Resource Kit
TReK Python  5.4.0 ART
ex_command_sequence.py

ex_command.py ex_command_sequence.py

1"""
2Example TReK Command Sequence Demonstration
3
4Binary Command Sequences are created using the TReK Command Sequence Editor.
5"""
6import time
7import trek
8
9# Number of completed command sequences we sent.
10completed_count = 0
11
12def command_callback(token, status, command, count, ret_code, command_token):
13 # Called by command API from a different thread.
14 if ret_code == 0:
15 print(f"Command #{count}, '{command}' executed with status {status}.")
16 else:
17 print(f"Error command #{count}, '{command}', code={ret_code}.")
18
19
20def stop_callback(token, status, count, ret_code):
21 # Called when a command sequence concludes.
22 if ret_code == 0:
23 print(f"Command Sequence {token}, completed.")
24 else:
25 print(f"Command Sequence {token} errored.")
26
27 completed_count = completed_count + 1
28
29
30def main() -> None:
31 """
32 Main Routine
33 """
34
35 try:
36 api = trek.CommandApi()
37
38 # Connect to a destination. The name passed into the Connect() call is
39 # the name used when configuring the destination in the TReK Command
40 # application.
41 api.connect("POIC")
42
43 # Calling this method allows the API to clean up resources that may be
44 # left over from a user program that crashed. Not checking the return
45 # value as it is safe to continue if this method fails.
46 api.cleanse()
47
48 # Once connected to the API, you can make calls to the API to see what is
49 # available for the interface. Call to see if there are any status
50 # messages. If there are, print out all of the information in each
51 # message.
52
53 # Register callbacks to be notified of the status of command sequences.
54 api.register_sequence_command_callback(command_callback)
55 api.register_sequence_stop_callback(stop_callback)
56
57 # Absolute path to the binary file created by the sequence editor.
58 sequences_sent = sequences_sent + 1
59 api.start_sequence('SequenceBinaryFile')
60
61 # It is okay to start a sequences and exit without monitoring for callbacks.
62 # Execution of the sequence happens within the commanding systems.
63
64 # However, if you want to recieve the callbacks, you must keep your Python
65 # script running until the sequence completes.
66
67 # In this example, we are waiting for the stop_callback to be called for each
68 # started sequence.
69 while completed_count < sequences_sent:
70 time.sleep(1)
71
72 #
73 # It is always best to call Disconnect when you are finished with the
74 # API. There are system resources that can be freed when you no
75 # longer need the API.
76 #
77 api.disconnect()
78
79 except trek.TrekError as err:
80 # Locate friendly message why it failed.
81 print(err.find_error_code())
82 print(err)
83
84
85if __name__ == "__main__":
86 main()
Provides access to command features of TReK.
Definition: trek.py:850
The TReK C++ was designed to return error codes.
Definition: trek.py:15453