我目前正在研究樹莓派項目,在那裏我從OBD2讀取數據到我的汽車中的USB檢查員。無法從樹莓派上的OBD2串行端口連接讀取數據
當我使用屏幕連接到串口一切工作正常,但是當我嘗試在python中執行它時,serial.readline()返回一個空字符串。
有誰知道我怎麼能從python的串口檢索數據?
我試過了可用的每一個選項。
import serial
ser = 0
#Function to Initialize the Serial Port
def init_serial():
global ser
ser = serial.Serial()
ser.baudrate = 38400
ser.port = '/dev/ttyUSB0'
ser.timeout = 1
ser.open() #Opens SerialPort
# print port open or closed
if ser.isOpen():
print 'Open: ' + ser.portstr
#Function Ends Here
init_serial()
temp = raw_input('Type what you want to send, hit enter:\r\n')
ser.write(temp) #Writes to the SerialPort
while 1:
bytes = ser.readline() #Read from Serial Port
print bytes #Print What is Read from Port