DO_PUSH in MUSE Programming
Frequently Asked Questions
Brand:
- AMX
Models:
- MUSE
- Programming
- Python
Question:
Does DO_PUSH exist in MUSE programming?
Answer:
In Netlinx programming you could emulate a button push by utilizing the DO_PUSH keyword. There is not a direct replacement for that command, but you can emulate a button push by passing an object to the callback function with the appropriate arguments. Here is an example of this in Python:
from mojo import context
context.log.info('Sample Python program')
#This class creates an object that emulates a button object, the only requirement is the value for PUSH/RELEASE, everything else can be used or ignored since they are given initial values
class doPush:
def __init__(self,value,source=None,id=None,path=None,device=None,newValue=None,oldValue=None,normalized=None):
self.value = value
self.source = source
self.id = id
self.path = path
self.device = device
self.newValue = newValue
self.oldValue = oldValue
self.normalized = normalized
#Creates the objects for the controller (idevice), touch panel (dvTP), and CE-REL8 (dvREL8)
dvTP = context.devices.get("AMX-12345")
idevice = context.devices.get("idevice")
#Creates simple variables that access the first relay port on both the idevice and CE-REL8
dvRelay1 = idevice.relay[0]
#This function processes button events for Port 1 Button 1 on the touch panel
#The value of the relay is tied to the state of the button, while the button is pressed the relay will engage, when the button is released it will disengage
def Relay1(event):
context.log.info(f"Dictionary = {event.__dict__}")
dvRelay1.state.value = event.value
#Creates a watch for Port 1, Button 1
dvTP.port[1].button[1].watch(Relay1)
#Callback function for doPush trigger
def DO_PUSH(event):
if(event.value):
#This line calls the callback function used for Relay1, you pass it the doPush object, passing doPush True emulates someone pushing button 1 on the touch panel
Relay1(doPush(True))
else:
#If you need other attributes added besides value, this line shows how you can pass those values into your object
Relay1(doPush(False,source="Code"))
#Creates a watch for a button, just needed some kind of trigger to call the doPush
dvTP.port[1].button[2].watch(DO_PUSH)
# leave this as the last line in the Python script
context.run(globals())