Hi,
I am running 3 tic 825 stepper drivers using usb + python.
There are times when I’m not in my lab or I’m not connected to all the hardware but I need to write/develop code that ordinarily calls ticcmd() and gets status from yaml which I realize will not work.
For this case I just want to gracefully continue without a premature error exit.
So 2 questions:
How can I detect the presence of 1 or 2 or 3 or none tic boards with ticcmd or another function?
I know about the -list command line option but I don’t know how to use it in python.
I’m using the standard python examples from user guide: defticcmd(*args): returnsubprocess.check_output(['ticcmd'] +list(args))
The output of the --list option is not YAML; I recommend printing the result you get from it in your Python code so you can see what it is returning. For example:
There are several ways you could go about parsing it from there. For example, you could use strip() and splitlines(), then use len to get the number of objects returned, which would look something like this:
import subprocess
def ticcmd( * args):
return subprocess.check_output([ 'ticcmd' ] + list (args))
def check_tic_boards():
# Check for connected Tic controllers:
output = ticcmd('--list')
# Parse output to count the boards
boards = output.strip().splitlines()
print(boards)
return len(boards)
# Example usage:
num_boards = check_tic_boards()
print(f"Number of Tic boards detected: {num_boards}")