CM 530微控制器和Pyserial API之间的蓝牙通信

时间:2017-05-09 10:15:01

标签: python bluetooth microcontroller pyserial

我有一台带有BT-210蓝牙模块的CM 530微控制器,我希望我的PC能够使用蓝牙和Pyserial API与CM 530进行通信。

在我的电脑(Python代码)中:

import time, sys, serial

# SERIAL INIT
defaultPort = "COM4" # change to suit your needs
ser = serial.Serial()

def initCom(port):
    ser.baudrate = 57600
    ser.port = port
    ser.timeout = 0.5
    ser.open()

def closeCom():
    ser.close() 

def sendPacket(packet):
    ser.write(packet) 
    time.sleep(0.030303030303030303) 

initCom(defaultPort)
if ser.is_open:
	print "hi"
else:
	print "bye";	
sendPacket("\xFF\x55\x10\xEF\x00\xFF") # _1 (16)
sendPacket("\xFF\x55\x20\xDF\x00\xFF") # _2 (32)
closeCom()

CM 530中的任务: https://1drv.ms/i/s!Aui23LOUVecGimYWdikg9hyGAs5i

我已经使用虚拟RC-100测试了我的CM 530代码,每当我按任意键时,收到的数据变为1,如果按下1或2,则会发出不同的声音。

但是当我尝试从python代码发送数据包时,收到的数据总是为零,但是当我检查连接是否打开时,它会打印“Hi”,这意味着连接已打开。

Mabey我正在使用的端口是错的,但我尝试了COM3和COM4,COM3打印嗨但它没有结束,COM4打印喜,但程序正常结束。 https://1drv.ms/i/s!Aui23LOUVecGimcfMf7mVNec9MK8

这是RC-100A / RC-100B的信息:(我不想使用这个RC-100,但我想和CM 530进行相同的通信,但是在我的PC上(Python代码) ) http://support.robotis.com/en/product/auxdevice/communication/rc100_manual.htm

RC-100 - (蓝牙BT-210) - CM 530< - 工作正常

我的电脑(Python代码) - (蓝牙BT-210) - CM 530< - 我想做什么

0 个答案:

没有答案