Kodi Community Forum

Full Version: Need python script to reset usb before running
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have a python script that turns my samsung TV on. Some of the fine folks here helped me out and its been working great. I even wrote about it on my blog: http://knightcinema.com/2015/09/08/samsu...onnection/

After re-configuring some wiring my serial controller sometimes stops working. I found a script that restarts it and it works well, but its not in python. Im not totally sure of the language, maybe c++.

I would like to only run it if the serial communication fails. This is the error:

Code:
kodi@server:~/data/scripts$ ./tvon.py
Traceback (most recent call last):
  File "./tvon.py", line 4, in <module>
    ser = serial.Serial(port='/dev/ttyUSB0', baudrate=9600, timeout=1)
  File "/usr/lib/python2.7/dist-packages/serial/serialutil.py", line 261, in __init__
    self.open()
  File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 278, in open
    raise SerialException("could not open port %s: %s" % (self._port, msg))
serial.serialutil.SerialException: could not open port /dev/ttyUSB0: [Errno 5] Input/output error: '/dev/ttyUSB0'

I would be happy if it ran every time, it happens almost instantly.

Thanks in advanced for any help.

This is the python script. I have several but the only difference is the hex code sent.
Code:
#!/usr/bin/env python
import time, serial
ser = serial.Serial(port='/dev/ttyUSB0', baudrate=9600, timeout=1)
resp=""
loop="true"
string="030cf100"
while loop:
  if string in resp:
    print "found it"
    break
    ser.close()
  else:
    ser.write("\x08\x22\x00\x00\x00\x02\xd4")
    data = ser.read(24)
    resp=data.encode('hex')
    print resp
    time.sleep(1)
print "finished"