Controlling MUSE IR Ports with Python Code
The below Python code controls IR ports on a MUSE controller. It contains code that configures the ports, sends IR commands, and also uses one IR port as a one-way serial device.
from mojo import context
context.log.info('*** Python Script Start ***')
############ Create devices and organize them ###################
idevice = context.devices.get('idevice')
ir1 = idevice.ir[0]
ir2 = idevice.ir[1]
ir3 = idevice.ir[2]
ir4 = idevice.ir[3]
dvTP = context.devices.get('AMX-12345')
irPorts = [ir1, ir2, ir3, ir4]
#################################################################
#################### Configuring IR ports #######################
### Enable Fault Detection on all IR ports
for port in irPorts:
port.enableFaultDetection()
### Creates function to handle IR fault errors
def handle_ir_faults(event):
print(f"Received fault from {event.path['data']}: {event.arguments['data']}")
for port in irPorts:
port.fault.listen(handle_ir_faults)
### Set Port 1 on/off times to 500 milliseconds
ir1.setOnTime(500)
ir1.setOffTime(500)
### Set carrier mode on for Port 2
ir2.carrier.value = True
### Set keypadMode 1 for Pot 3
ir3.keypadMode(1)
### Set IR Port 4 for Serial mode and set communication parameters
ir4.mode.value = "SERIAL"
ir4.setCommParams("9600", 8, 1, "NONE", "232")
#################################################################
######################### IR Functions ##########################
### Pulsing an IR port via channel number
def channelPulse(event):
ir1.bufferedSendIr(1)
### Pulsing an IR port via function Name
def namePulse(event):
ir2.bufferedSendNamedIr("PLAY")
### Sending a channel input using the keypad macro
def keypadMacro(event):
ir3.keypadMacro(325)
### Sending a one-way serial string
def oneWaySerial(event):
ir4.send("POWR ON")
### Clear and send via channel
def clearSendChannel(event):
ir1.clearAndSendIr(2)
### Clear and send via name
def clearSendName(event):
ir2.clearAndSendNamedIr("STOP")
### Continuous via channel (remember to turn this off)
def onIr(event):
ir1.onIr(16)
### Continuous via name (remember to turn this off)
def onNamedIr(event):
ir1.onNamedIr(27)
### Turn off IR on the port
def offIr(event):
ir1.offIr()
### Load IR file via code
def loadIrFile(event):
ir1.loadIrFile("SamsungE750.irl")
################################################################
################ Creating Button Watch Events ##################
dvTP.port[1].button[1].watch(channelPulse)
dvTP.port[1].button[2].watch(namePulse)
dvTP.port[1].button[3].watch(keypadMacro)
dvTP.port[1].button[4].watch(oneWaySerial)
dvTP.port[1].button[5].watch(clearSendChannel)
dvTP.port[1].button[6].watch(clearSendName)
dvTP.port[1].button[7].watch(onIr)
dvTP.port[1].button[8].watch(onNamedIr)
dvTP.port[1].button[9].watch(offIr)
dvTP.port[1].button[10].watch(loadIrFile)
################################################################
# leave this as the last line in the Python script
context.run(globals())