Here the code I have developed in Python. Beware that this code is based on previous firmware version (3.x). You may have to adapt if your unit runs v4. I have developed the very basic functions, based on that it would not be difficult to add some other functions (like volume up/down for instance). Python has been chosen because it implements the socket lib which is fairly easy to use.
This code sends the power On/Off command to XMC-1 using iTach IP2IR because I don't want to let the unit in video standby mode due to power drain (35W). So in this specific case, I use the IR in plug at the backside of the unit.
Code: Select all
#!/usr/bin/env python
import socket
import sys
power = sys.argv[1]
TCP_IPADDRESS = "192.168.21.239"
TCP_PORT = 4998
BUFFER_SIZE = 1000
if power == "OFF":
MESSAGE = 'sendir,1:1,1,38000,1,69,341,170,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,64,21,21,21,21,21,64,21,64,21,64,21,64,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,64,21,64,21,64,21,64,21,64,21,64,21,64,21,64,21,21,21,1517,341,85,21,3655\r'
elif power == "ON":
MESSAGE = 'sendir,1:1,1,38000,1,69,341,170,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,64,21,21,21,21,21,64,21,64,21,64,21,64,21,21,21,21,21,64,21,21,21,21,21,21,21,21,21,64,21,64,21,64,21,21,21,64,21,64,21,64,21,64,21,21,21,21,21,1517,341,85,21,3655\r'
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((TCP_IPADDRESS, TCP_PORT))
s.send(MESSAGE)
data = s.recv(BUFFER_SIZE)
s.close()
if not 'completeir' in data:
print 'Status', 'Erreur de transmission avec XMC-1'
print "received data:", data
This code sends to XMC-1 (and iTach but this is another story) the code to select the desired input
Code: Select all
#!/usr/bin/env python
# -*- coding: latin-1 -*-
import socket
import sys
import string
from time import sleep
import errno
import fcntl, os
#import domoticz
# Preamp codes
#iTACH IP2IR module
CD='sendir,1:2,1,36023,1,1,32,32,32,32,64,32,32,64,32,32,32,32,32,32,64,64,32,32,64,64,32,3225\r'
TUNER='sendir,1:2,1,36023,1,1,32,32,64,32,32,32,32,64,32,32,32,32,64,32,32,64,64,64,32,32,32,3600\r'
PHONO='sendir,1:2,1,36023,1,1,32,32,32,32,64,32,32,64,32,32,32,32,32,32,64,64,64,64,32,32,32,3235\r'
VIDEO='sendir,1:2,1,36023,1,1,32,32,64,32,32,32,32,64,32,32,32,32,32,32,32,32,64,64,64,64,32,3235\r'
AUX='sendir,1:2,1,36023,1,1,32,32,32,32,64,32,32,64,32,32,32,32,64,64,32,32,32,32,64,64,32,3235\r'
TAPE='sendir,1:2,1,36023,1,1,32,32,64,32,32,32,32,64,32,32,32,32,64,64,32,32,32,32,64,32,32,3267\r'
PHASEIN='sendir,1:2,1,36023,1,1,32,32,32,32,64,32,32,64,32,32,32,32,32,32,32,32,64,32,32,32,32,32,32,3267\r'
PHASEOUT='sendir,1:2,1,36023,1,1,32,32,32,32,64,32,32,64,32,32,32,32,32,32,32,32,64,64,32,32,64,3267\r'
MUTE='sendir,1:2,1,36023,1,1,32,32,32,32,64,32,32,64,32,32,32,32,64,32,32,64,32,32,64,64,32,3235\r'
VOLUME_PLUS='sendir,1:2,1,36023,1,1,32,32,64,32,32,32,32,64,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,3235\r'
VOLUME_MOINS='sendir,1:2,2,36023,1,1,32,32,64,32,32,32,32,64,32,32,32,32,32,32,32,32,32,32,32,32,64,32,32,3267\r'
XMC_POWERON='sendir,1:1,1,38000,1,69,341,170,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,64,21,21,21,21,21,64,21,64,21,64,21,64,21,21,21,21,21,64,21,21,21,21,21,21,21,21,21,64,21,64,21,64,21,21,21,64,21,64,21,64,21,64,21,21,21,21,21,1517,341,85,21,3655\r'
XMC_STANDBY='sendir,1:1,1,38000,1,69,341,170,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,64,21,21,21,21,21,64,21,64,21,64,21,64,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,64,21,64,21,64,21,64,21,64,21,64,21,64,21,64,21,21,21,1517,341,85,21,3655\r'
# end of iTach
XMC_COMMAND='<?xml version="1.0" encoding="utf-8"?><emotivaControl><commandName value="commandValue" ack="yes" /></emotivaControl>'
XMC_PING='<?xml version="1.0" encoding="utf-8"?><emotivaPing />'
SLEEPTIME=0.4
audio = sys.argv[1]
IP2IR_IPADDRESS = "192.168.21.239"
IP2IR_PORT = 4998
XMC_IPADDRESS = "192.168.21.229"
XMC_TRANSACTION_PORT_IN = 7000
XMC_TRANSACTION_PORT_RESPONSE = 7001
XMC_CONTROL_PORT = 7002
BUFFER_SIZE = 1000
#row 0 is command
#row 1 is IP address
#row 2 is port
#row 3 is protocol
if audio == 'Plex':
#Set preamp input to Vidéo and XMC input to Input 1
MESSAGE=[[XMC_POWERON,IP2IR_IPADDRESS,IP2IR_PORT,"TCP"],[XMC_COMMAND,XMC_IPADDRESS,XMC_CONTROL_PORT,"UDP"],[VIDEO,IP2IR_IPADDRESS,IP2IR_PORT,"TCP"]]
MESSAGE[1][0]=string.replace(MESSAGE[1][0],'commandName','source_1')
MESSAGE[1][0]=string.replace(MESSAGE[1][0],'commandValue','0')
elif audio == 'DVD':
#Set preamp input to Vidéo and XMC input to Input 2
MESSAGE=[[XMC_POWERON,IP2IR_IPADDRESS,IP2IR_PORT,"TCP"],[XMC_COMMAND,XMC_IPADDRESS,XMC_CONTROL_PORT,"UDP"],[VIDEO,IP2IR_IPADDRESS,IP2IR_PORT,"TCP"]]
MESSAGE[1][0]=string.replace(MESSAGE[1][0],'commandName','source_2')
MESSAGE[1][0]=string.replace(MESSAGE[1][0],'commandValue','0')
elif audio == 'jRiver':
#Set preamp input to Audio
MESSAGE=[[AUX,IP2IR_IPADDRESS,IP2IR_PORT,"TCP"]]
elif audio == 'CD':
#Set preamp input to CD
MESSAGE=[[CD,IP2IR_IPADDRESS,IP2IR_PORT,"TCP"]]
elif audio == 'Tourne disque':
#Set preamp input to Phono
MESSAGE=[[PHONO,IP2IR_IPADDRESS,IP2IR_PORT,"TCP"]]
elif audio == 'XMC_STANDBY':
MESSAGE=[[XMC_STANDBY,IP2IR_IPADDRESS,IP2IR_PORT,"TCP"]]
sTCP = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sUDP = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sUDPreceive = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sUDPreceive.bind(('',XMC_TRANSACTION_PORT_RESPONSE))
fcntl.fcntl(sUDPreceive, fcntl.F_SETFL, os.O_NONBLOCK)
#for row in MESSAGE:
# #for e in row:
# #print e
# print row
IPADDRESS_PREVIOUS=""
loop=0
for row in MESSAGE:
if row[3] == "UDP": # it is XMC by design
# send a ping and check if unit is On. If not wait until it is ready (PowerOn has been sent before)
while True:
# send a ping until a response is given
sUDP.sendto(XMC_PING, (XMC_IPADDRESS, XMC_TRANSACTION_PORT_IN))
#print ('ping sent: ', MESSAGE[0][0])
# wait some time to let the unit answer
sleep (0.01)
try:
data = sUDPreceive.recvfrom(500)
except socket.error, e:
err = e.args[0]
if err == errno.EAGAIN or err == errno.EWOULDBLOCK:
sleep(SLEEPTIME)
#print 'No data available'
loop+=1
if loop*SLEEPTIME >= 70:
#print('timeout')
exit()
continue
else:
# a "real" error occurred
print e
sys.exit(1)
#TBD implement a timeout of 20 sec in case there is a problem with the unit
else:
# unit is ready send the command now
sUDP.sendto(row[0], (row[1], row[2]))
# TBD : check if OK
break
else: # TCP protocol
if IPADDRESS_PREVIOUS != row[1]:
if IPADDRESS_PREVIOUS != "": s.close()
sTCP.connect((row[1], int(row[2])))
IPADDRESS_PREVIOUS=row[1]
#print ("TCP", row[0])
result = sTCP.send(row[0])
#print (result)
data = sTCP.recv(BUFFER_SIZE)
#print "received data:", data
sUDP.close
sUDPreceive.close
sTCP.close