0

esp8266 和 cp2102 不工作!为什么?

import serial

sp="/dev/ttyUSB0"

port = serial.Serial(sp)

while True:
    port.write("AT+RST")
    rcv = port.read(10)
    print rcv

我按了“AT+RST”[Enter],后面没有“READY”。

4

2 回答 2

1

确保在命令末尾包含 CRLF (\r\n) 字符。在我弄清楚之前,我浪费了一天的时间。我得到了命令的本地回显,但由于我从未发送过 \r\n 我不会再获得任何数据。以下是使用 pyserial 在 Python 中作为基本终端对我有用的方法:

import serial
import time

ser = serial.Serial('/dev/tty.usbserial-A8004xaO', 115200, timeout=2.5)
while True:
    cmd = raw_input("> ");
    ser.write(cmd + "\r\n")
    ret = ser.read(len(cmd)) # eat echo
    time.sleep( 0.2 )
    while ( ser.inWaiting() ):
        ret = ser.readline().rstrip()
        print ret

于 2014-11-08T19:34:28.020 回答
0

打开串行端口时,您没有设置波特率。默认值可能不适合 ESP8266。

于 2014-10-02T15:55:21.243 回答