Sending rs232 commands to Samsung tv
#16
(2014-02-06, 21:38)doug Wrote:
Code:
import time, serial
ser = serial.Serial(port='/dev/ttyUSB0', baudrate=38400, timeout=1)
ser.write("\x08\x22\x00\x00\x00\x02\xd6")
time.sleep(0.25)
result=ser.read(ser.inWaiting())
print result
ser.close()

This will send a command, wait 1/4 second and print the result. My pioneer responds in less than 0.05 seconds; you can decrease the delay later but I set it higher to have a better chance of the response getting received.

Alright, I figured out that when I moved things around I had broken my serial cable so there was no connection. I found the power toggle command by guessing. If x02\xd6 is off and x01\xd5 was on then I thought x00\xd4 might toggle and I was right! lol. Now I dont have a keyboard.xml file anywhere in my userdata folder. I am running xbmc 12.2 in xbmcbuntu. I have a keymaps folder that only has one noBS.xml which just has one edit to remove the backslash function. How do I get this python script to run when I press the power button and NOT put the computer to sleep or shutdown or anything? Also, Could I run it when xbmc becomes idle and again when its unidle?
Reply
#17
My keyboard.xml:
Code:
<keymap>
  <global>
    <remote>
      <Power>RunScript(/home/xbmc/tvon.py)</Power>
    </remote>
  </global>
</keymap>

and my lircmap.xml:

Code:
xbmc@livingroom:~/.xbmc/userdata/keymaps$ sudo nano lircmap.xml
  GNU nano 2.2.6                                           File: lircmap.xml

  <lircmap>
       <remote device="mceusb">
               <power>KEY_POWER</power>
       </remote>
  </lircmap>

and the output from IRW:

Code:
xbmc@livingroom:~/.xbmc/userdata/keymaps$ irw
000000037ff07be0 00 KEY_DOWN mceusb
000000037ff07be0 01 KEY_DOWN mceusb
000000037ff07bf3 00 KEY_POWER mceusb
000000037ff07bf3 01 KEY_POWER mceusb

Yet, still, all that happens is the computer shuts down. Nothing happens at the tv. It seems like its hibernating though. Because when I turn it back on everything is where I left it. I see the BIOS and it asks for my encryption passphrase but then I am in XBMC in the tvshow right where it was when it shut down.
Reply
#18
(2014-02-22, 17:24)Jpaytoncfd Wrote: My keyboard.xml:
Code:
<keymap>
  <global>
    <remote>
      <Power>RunScript(/home/xbmc/tvon.py)</Power>
    </remote>
  </global>
</keymap>

and my lircmap.xml:

Code:
xbmc@livingroom:~/.xbmc/userdata/keymaps$ sudo nano lircmap.xml
  GNU nano 2.2.6                                           File: lircmap.xml

  <lircmap>
       <remote device="mceusb">
               <power>KEY_POWER</power>
       </remote>
  </lircmap>

and the output from IRW:

Code:
xbmc@livingroom:~/.xbmc/userdata/keymaps$ irw
000000037ff07be0 00 KEY_DOWN mceusb
000000037ff07be0 01 KEY_DOWN mceusb
000000037ff07bf3 00 KEY_POWER mceusb
000000037ff07bf3 01 KEY_POWER mceusb

Yet, still, all that happens is the computer shuts down. Nothing happens at the tv. It seems like its hibernating though. Because when I turn it back on everything is where I left it. I see the BIOS and it asks for my encryption passphrase but then I am in XBMC in the tvshow right where it was when it shut down.

Just curious as why you dont want to use irexec as was recommended? Its very simple and its purpose is to do exactly what you are trying to do.
Reply
#19
I'm not sure if keyboard.xml and lircmap.xml are case sensitive or not, but you have "Power" in one and "power" in the other.

Post a debug log http://wiki.xbmc.org/index.php?title=Log_file with the power button being pressed so we can see what is logged.
Reply
#20
I have been using this for months and it works but sometimes I have to run the command several times to get a reaction. and the print just makes a little weird box. same if the tv responds or not. Should the print be different?

Code:
import time, serial
ser = serial.Serial(port='/dev/ttyUSB0', baudrate=9600, timeout=1)
ser.write("\x08\x22\x00\x00\x00\x00\xd4")
time.sleep(0.50)
result=ser.read(ser.inWaiting())
print result
ser.close()
Reply
#21
I changed the script a little. Now theres no little box but no return ether. But there is a blank line.

also, I have to execute the command quickly repeatedly to turn the tv off. It turns on with one command. sometimes two.

Code:
import time, serial
ser = serial.Serial(port='/dev/ttyUSB0', baudrate=9600, timeout=1)
ser.write("\x08\x22\x00\x00\x00\x00\xd4")
time.sleep(0.02)
result=ser.read()
print result
ser.close()
Reply

Logout Mark Read Team Forum Stats Members Help
Sending rs232 commands to Samsung tv0