2011-11-27, 08:19
Hi i made this little howto for people searching for a way to turn on and off his LG LCD SCREEN (May work with any other brand that support commands with RS232), because i have no found any isntructions in the forums to tell how to do it:
1.- rs232 cable make / buy
i made it by myself, if you don't know how to solder maybe you can find a friend that do it for you..
2.- finding serial port number:
i issued this command on xbmc shell:
3.- test cable with linux minicom:
"insert a paperclip between pins 2 and 3 of the db9 to make a loop"
CTRL-A Z
O Configure minicom
Serial port setup
A - Serial Device ttyS0
E - Bps/Par/Bits 9600
F - Hardware Flow Control No
Save setup as dfl
exit
ctrl-a X
sudo minicom
type any character it may see on the screen if cable is working and you hit the correct serial port
4.- Test tv commands with linux minicom:
Turn off:
sent this:
ka 0 0
receive this:
a 00 OK00x
Turn on:
sent this:
ka 0 1
receive this:
a 00 OK01x
5.- Install python serial (because seems to be the preferred programming language for xbmc):
made 2 little scripts:
tv_on.py:
----------------------------------------------------------
import serial
ser = serial.Serial(0) # open first serial port
#print ser.portstr # check which port was really used
ser.write("ka 0 1\n") # string to turn off tv
#print ser.read(10) # read a '\n' terminated line
ser.close() # close port
-----------------------------------------------------------
tv_off.py:
-----------------------------------------------------
import serial
ser = serial.Serial(0) # open first serial port
#print ser.portstr # check which port was really used
ser.write("ka 0 0\n") # string to turn off tv
#print ser.read(10) # read a '\n' terminated line
ser.close() # close port
-------------------------------------------------------
Adding permision for using serial ports to xbmc user:
6.- Make init.d script (/etc/init.d/tvpower):
------------------------------------------------------------
#! /bin/sh
#
### BEGIN INIT INFO
# Provides: tvpower
# Required-Start: $all
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: tvpower
# Description: turns on and off lg lc screen
### END INIT INFO
PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"
NAME=tvpower
DESC=tvpower
set -e
case "$1" in
start)
python /home/xbmc/tv_on.py
;;
stop)
python /home/xbmc/tv_off.py
;;
restart|force-reload)
# nothing
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|force-reload}" >&2
exit 1
;;
esac
exit 0
-------------------------------------------------------------------
7.- Add the script to startup:
8.- For some reason that i cannot find yet, it doesn turn on the tv so i put it the following line on /etc/rc.local and that makes the trick for now:
/etc/rc.local:
---------------------------------------------------------------------
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
python /home/xbmc/tv_on.py
exit 0
----------------------------------------------------------------------
Hope this helps someone.
Regards, Jose
1.- rs232 cable make / buy
i made it by myself, if you don't know how to solder maybe you can find a friend that do it for you..
2.- finding serial port number:
i issued this command on xbmc shell:
Code:
dmesg | grep ttyS
[ 0.212718] serial8250: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A
[ 0.213132] 00:05: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A
"insert a paperclip between pins 2 and 3 of the db9 to make a loop"
Code:
sudo apt-get install minicom
sudo minicom
CTRL-A Z
O Configure minicom
Serial port setup
A - Serial Device ttyS0
E - Bps/Par/Bits 9600
F - Hardware Flow Control No
Save setup as dfl
exit
ctrl-a X
sudo minicom
type any character it may see on the screen if cable is working and you hit the correct serial port
4.- Test tv commands with linux minicom:
Turn off:
sent this:
ka 0 0
receive this:
a 00 OK00x
Turn on:
sent this:
ka 0 1
receive this:
a 00 OK01x
5.- Install python serial (because seems to be the preferred programming language for xbmc):
Code:
sudo apt-get install python-serial
tv_on.py:
----------------------------------------------------------
import serial
ser = serial.Serial(0) # open first serial port
#print ser.portstr # check which port was really used
ser.write("ka 0 1\n") # string to turn off tv
#print ser.read(10) # read a '\n' terminated line
ser.close() # close port
-----------------------------------------------------------
tv_off.py:
-----------------------------------------------------
import serial
ser = serial.Serial(0) # open first serial port
#print ser.portstr # check which port was really used
ser.write("ka 0 0\n") # string to turn off tv
#print ser.read(10) # read a '\n' terminated line
ser.close() # close port
-------------------------------------------------------
Adding permision for using serial ports to xbmc user:
Code:
sudo usermod -a -G dialout xbmc
------------------------------------------------------------
#! /bin/sh
#
### BEGIN INIT INFO
# Provides: tvpower
# Required-Start: $all
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: tvpower
# Description: turns on and off lg lc screen
### END INIT INFO
PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"
NAME=tvpower
DESC=tvpower
set -e
case "$1" in
start)
python /home/xbmc/tv_on.py
;;
stop)
python /home/xbmc/tv_off.py
;;
restart|force-reload)
# nothing
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|force-reload}" >&2
exit 1
;;
esac
exit 0
-------------------------------------------------------------------
7.- Add the script to startup:
Code:
sudo update-rc.d -f tvpower defaults 89 89
/etc/rc.local:
---------------------------------------------------------------------
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
python /home/xbmc/tv_on.py
exit 0
----------------------------------------------------------------------
Hope this helps someone.
Regards, Jose