2012-03-01, 11:59
I use this python script from my linux setup to get which input is active in my TV from rs232 :
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
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