Python - Device Definitions | MUSE
This video walks you through how to define and reference hardware devices in your Python programs running on an AMX MUSE controller. You’ll learn how to leverage the Context class to retrieve device objects, access specific ports, and organize your code using clear, meaningful variables. Along the way, we’ll cover key concepts like zero-based indexing, navigating device attributes, and identifying common issues such as “zombie” devices—plus how to fix them quickly to keep your system running smoothly.
What You’ll Learn:
• How to define and reference hardware devices in MUSE Python programs
• Using the Context class to retrieve and manage device objects
• Accessing device ports and attributes effectively
• Understanding zero-based indexing in MUSE
• Organizing code with meaningful variables for readability
• Identifying and resolving “zombie” device issues
Hello, and welcome to this video on device definitions in Python. This process is necessary when programming for any device listed on the MUSE controller’s webpage.
Before your device can be referenced or used in code, we need to define it. In MUSE that means we will use the context class to retrieve the device object and assign it to a variable in our script.
In this example, we will be utilizing the serial port on an MU-2300 using idevice. Idevice is how a MUSE controller references the control ports on an MU-1300, 2300, or 3300. These control ports include serial, relay, IO, and IR ports. The number of ports varies for each model, so reference your model’s documentation for further information.
To get the idevice object, we will set a variable named dvIdevice equal to context.devices.get(“idevice”).
*** Show code ***
dvIdevice = context.devices.get(“idevice”)
*****************
When using the GET method call, the device in quotation marks must match the device listed on the controller’s device list. This includes matching capitalization.
Now that you have the device, you can run methods or access parameters about the idevice itself, but what about accessing the individual ports? Ports are an indexed attributes or properties of the idevice object. For example, to access the first serial port on a controller you would type in dvIdevice.serial[0] .
*** Show code ***
dvIdevice.serial[0]
*****************
In this case serial is the name of the attribute, and zero is the indexed position of the first serial port. All port numbers in idevice are zero based when referenced in programming, so the first serial port is array position zero.
Since we are using Python, we can utilize a different variable to take the place of dvIdevice.serial. Say, for example, this is the serial port we use to control our display. We can create a new assignment that says dvDisplay = dvIdevice.serial[0] .
*** Show code ***
dvDisplay = dvIdevice.serial[0]
*****************
From now on in our code, any time we want to reference that control port, we can just use dvDisplay. To find the attributes, methods, or parameters associated with specific devices, please reference the device’s product documentation or Descriptor file.
The last thing we need to talk about when it comes to device definitions is zombies…yes, that’s right, zombies…
Zombies are created when a device definition is run for a device that does not exist. This may be because you have not yet created the device, the device has not been created by an extension, or just a typo in code.
When the GET method is called on a device that doesn’t exist, the controller will create an entry in the device list for the missing device. In most cases you will see a listed device that has a red square beside it in the device list. There are two ways to remove a zombie from the device list.
If the device had not yet been created in the controller, simply create the device with the same instance ID as the zombie. The controller will reconcile the two names, and you will only see the created device once the page has been refreshed. If the zombie was created by accident, change the typo in your code and upload the correct version to the controller. The next time the controller reboots, the zombie will be removed.