0

在过去的 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")

在 robotsC 中我回来了 f~fžþžøž 在 Python 中我回来了

4

1 回答 1

0

原来HC-05模块没有正确配置:(

于 2016-08-06T15:18:05.063 回答