Here is my code so far. It's intended to read an output from projector's power state.
Problem I have with it is that it gives no output besides ">>"
Already tried modifing the response variable with:
- response = ser.readline()
- response = ser.read()
- response = ser.inWaiting()
What's intresting is that when I run cat /dev/ttyS5
after finished Python script. It gives me output and exits. Normally when I am using a cat /dev/ttyS5
it goes forever and needs to be terminated.
#!/usr/bin/python
import serial
import sys
import os
import time
pin_export = 'echo 2 > /sys/class/gpio/export'
pin_out = 'sleep 0.1 && echo out > /sys/class/gpio/gpio2/direction'
pin_high = 'sleep 0.1 && echo 1 > /sys/class/gpio/gpio2/value'
pin_low = 'sleep 0.1 && echo 0 > /sys/class/gpio/gpio2/value'
pin_unexport = 'echo 2 > /sys/class/gpio/unexport'
response = ''
os.system(pin_export)
os.system(pin_out)
os.system(pin_high)
ser = serial.Serial()
ser.port = '/dev/ttyS5'
ser.baudrate = 9600
ser.bytesize = serial.EIGHTBITS
ser.parity = serial.PARITY_NONE
ser.stopbits = serial.STOPBITS_ONE
ser.xonxoff = False
ser.open()
ser.write(b'\r*pow=?#\r')
y = "1"
ser.timeout=0.5
while ser.inWaiting() > 0:
response = ser.readline()
print(">>" + response)
time.sleep(1)
os.system(pin_low)
os.system(pin_unexport)
On the other hand if any of you guys have a better idea how to read an input from /dev/ttyS5
that I later can save to text file I'm open for suggestions.