I do a similar thing with my Pioneer TV and a projector I have. I first tried using bash to send the RS-232 codes, but couldn't get the hex codes to send properly. I ended up installing python-serial and use python scripts to send the codes. Here's how:
install python-serial:
Code:
sudo apt-get install python-serial
edit keyboard.xml (in your userdata folder) to add what button presses you want and the scripts they should run. Something like:
Code:
<keymap>
<global>
<keyboard>
<F9 mod="ctrl">RunScript(/home/xbmc/toggle_input.py)</F9>
<F10 mod="ctrl">RunScript(/home/xbmc/toggle_on_off.py)</F10>
etc...
and then put your RS-232 commands in python script scripts like this...
/home/xbmc/toggle_input.py:
Code:
import time, serial
ser = serial.Serial(port='/dev/ttyS0', baudrate=38400, timeout=1)
ser.write("\x02**INP\x03")
time.sleep(0.05)
result=ser.read(ser.inWaiting())
if "INPS04" in result:
ser.write("\x02**INPS05\x03")
else:
ser.write("\x02**INPS04\x03")
xbmc.executebuiltin( "PlayerControl(Stop)" )
ser.close()
this script polls the TV to determine the current input and then switches to another one.
So, to turn your TV on your script could be as simple as:
Code:
import serial
ser = serial.Serial(port='/dev/ttyS0', baudrate=38400, timeout=1)
ser.write("\x08\x22\x00\x00\x00\x02\xd6")
ser.close()