python 3.x-PySerial和VEX EDR Cortex之间的串行通信



在过去的24小时里,我一直在努力解决这个问题,我正试图让PySerial使用UART/HC-05通过蓝牙与VEX Cortex进行通信。我想这将非常类似于与Arduino交流。

设备连接在一起,数据流动,但它的垃圾

在RobotC中:(正如你所看到的,没有明显的编码,我相信它只是以字节的形式进行(

#include "BNSlib_HC05.h"
task main()
{
    setBaudRate(UART1, baudRate19200);
    bnsATGetBaudrate(UART1)
    char stringBuffer[100];;
    while(1==1)
    {
        bnsSerialRead(UART1, stringBuffer, 100, 100);
        writeDebugStreamLine(stringBuffer);
        delay(500);
        bnsSerialSend(UART1, (char*)&"simon");
    }
}

在python PySerial 中

import serial
import time
import struct
ser = serial.Serial(port='COM8', baudrate=19200)
print("connected to: " + ser.portstr)
message = "Simon"
while True:
    ser.write(message.encode()) # I guess this is encoding via utf8?
    #for b in bytearray("simon was here","UTF-8"):
        #ser.write(b)
    print("sent")
    time.sleep (100.0 / 1000.0);
    result = ser.read(25) # tried readline, just hangs
    print(">> " + result.decode('cp1252')) # tried utf8, ascii
ser.close()
print("close")

在机器人C中,我得到了f~fžþžøž在Python中,我将返回ý

HC-05模块配置不正确:(

最新更新