Script output is wrong

  Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
cruster Offline
Junior Member
Posts: 4
Joined: Oct 2011
Reputation: 0
Post: #1
I use this python script from my linux setup to get which input is active in my TV from rs232 :
Code:
import serial
ser = serial.Serial('/dev/ttyS0', 9600, 8, serial.PARITY_NONE, serial.STOPBITS_ONE, xonxoff=0, rtscts=0, timeout=1)
inputstatus = "xb 01 FF\r"
ser.write(inputstatus)
status = ser.readline()
print status

If I run the script from terminal output is normal, but when I call it from an xbmc script with subprocess.popen(['/usr/bin/python', '/scriptlocation/script.py']) the output is the status randomly scrambled. I have also tried subprocess.Popen(), os.system(), setting shell=True but all have the same result. I even tried writing the output into a file, the contents of which are wrong too (running it from terminal, file contents are correct). Also, I played with encodings with no effect (probably reading from ttyS0 is already scrambled before I correct the encoding). Printing simple strings works fine, so the problem is somewhere between reading status from ttyS0 and storing it to a variable.

I guess that although I set the interpreter to /usr/bin/python, xbmc uses its own and this produces the wrong output. Is there any way to override the interpreter?

Thanks
find quote
vikjon0 Offline
---
Posts: 2,429
Joined: Apr 2009
Reputation: 7
Location: Sweden
Post: #2
In eden external python is used and I guess that will take a way the difference.
find quote
cruster Offline
Junior Member
Posts: 4
Joined: Oct 2011
Reputation: 0
Post: #3
After many hours, I found where the problem was! I had the script bound to a button both in .lircrc and in xbmc's remote.xml which caused the script to be called twice and messing the input/output of the serial port. But thanks for the answer, anyway!
find quote