2015-10-27 107 views

回答

1

您正在尋找的術語是波特率。 115200波特意味着串行端口能夠每秒傳輸115200位(:讀取BITS)。這是一個相當普遍的波特率,所以只要你的USB UART能跟上就不應該成爲問題。我有一個超過19200年不可靠的超級舊FTDI USB UART,但這是唯一一個讓我悲傷的人。糟糕的電纜的症狀被破壞,在響應和傳輸中缺少字符。

我不認爲你可以使用print或raw_input進行串行處理。如果可以的話,我看不到任何理由,因爲這不是他們的目的。你想要使用的是pyserial模塊:https://github.com/pyserial/pyserial

我有這個項目https://github.com/PyramidTechnologies/Python-RS-232在Raspberry Pi上運行就好了。

ser = serial.Serial(
     port=portname, 
     baudrate=115200, 
     bytesize=serial.SEVENBITS, 
     parity=serial.PARITY_EVEN, 
     stopbits=serial.STOPBITS_ONE 
    ) 

一定要設置爲任何目標設備講

然後進行讀寫,設置一些這樣的流量控制:

// msg could be a list of numbers. e.g. [4, 56, 34, 213] 
ser.write(msg) 

// Experiment with delay before reading if you are not getting 
// a response right away. 
time.sleep(0.1) 

// Keep reading from port while there is data to read 
out = '' 
while ser.inWaiting() > 0: 
    out += ser.read(1) 
    if out == '': 
     continue 

// out is now the received bytes 
// https://pythonhosted.org/pyserial/pyserial_api.html#serial.Serial.read 
實施要點