Kodi Community Forum

Full Version: RS232 Samsung TV Control - Python
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have a python script to turn my tv on and off using samsungs eslink serial control.

It works but not overly reliably. Sometimes I have to run the command multiple times to get it to respond. Then the response is not exactly reliable ether. Theres suppose to be 3 bytes returned but I get 4 to 12. If it works I get the three bytes but sometimes mixed into some other data.

Code:
root@livingroom:~# python tvontest.py
ada103010001a6030cf100
root@livingroom:~# python tvontest.py
00030cf100
root@livingroom:~# nano tvontest.py
root@livingroom:~# python tvontest.py
ada103010001a6030cf100
root@livingroom:~# python tvontest.py
030cf10000
root@livingroom:~# python tvontest.py

root@livingroom:~# python tvontest.py

root@livingroom:~# python tvontest.py
030cf100
root@livingroom:~# python tvontest.py
030cf100ada103010001a6ada103010001a6ada103010001
root@livingroom:~# python tvontest.py
030cf100
root@livingroom:~# python tvontest.py
00
root@livingroom:~# python tvontest.py

root@livingroom:~# python tvontest.py
030cf100
root@livingroom:~# ^C
root@livingroom:~# python tvontest.py
ada103010001a6030cf100
root@livingroom:~# python tvontest.py
00030cf100
root@livingroom:~# python tvontest.py
ada103010001a6030cf100
root@livingroom:~# python tvontest.py
00030cf100
root@livingroom:~# python tvon.py
030cff00030cf100

Can someone tell me how I can get the command to repeate until it finds those three bytes? 030cf1 is the three bytes.
You may want to share the actual python script
(2014-09-19, 01:19)drivesoslow Wrote: [ -> ]You may want to share the actual python script

Very good point...

Turns the TV on
Code:
import time, serial
ser = serial.Serial(port='/dev/ttyUSB0', baudrate=9600, timeout=2)
ser.write("\x08\x22\x00\x00\x00\x02\xd4")
data = ser.read(24)
print data.encode('hex')
ser.close()

Turns it off
Code:
import time, serial
ser = serial.Serial(port='/dev/ttyUSB0', baudrate=9600, timeout=2)
ser.write("\x08\x22\x00\x00\x00\x01\xd5")
data = ser.read(24)
print data.encode('hex')
ser.close()

This was one attempt I made. But it did not work.
Code:
import time, serial
ser = serial.Serial(port='/dev/ttyUSB0', baudrate=9600, timeout=1)

while True:
    data = ser.read(24)
    if len(data) > 0:
        ser.close()
        print 'sucess'
        break
    sleep(0.5)
    print 'Retrying'
    ser.write("\x08\x22\x00\x00\x00\x00\xd4")
This wheel seems to have been invented previously

https://github.com/enlavin/exlink
Theres no documentation and I dont see anything in those thats going to make sure a command is received. I am also not sure how to get those to work. How would I make it only send the cmd.on hex?
(2014-09-21, 01:49)Jpaytoncfd Wrote: [ -> ]Theres no documentation and I dont see anything in those thats going to make sure a command is received. I am also not sure how to get those to work. How would I make it only send the cmd.on hex?

Well _snd_cmd waits for and analyses a response.

There is a cmd_power_on defined.

I don't have a Samsung TV, just trying to help. May I simply suggest you play with the github code.

PS your code to turn on and off seems to include xD4 and xD5 at the end of the string, the github code doesn't. is this a problem perhaps?

Also note the comments about the turning on doesn't actually work. I don't know if this is a general comment on Samsung TVs, or a problem with this code or what.
PS again I guess the d4 d5 thing is the checksum which is defined and used in the github code.