首页| 论坛| 消息

标题:关于BLE开发的问题
作者:nikonice
日期:2018-02-23 08:47
内容:

关于Qt 开发BLE的资料很少,目前有个问题,已经连上蓝牙设备,但是连接服务总没反应。求解!
connect(discoveryAgent, SIGNAL(deviceDiscovered(QBluetoothDeviceInfo)), this, SLOT(onFindBLEMachine(QBluetoothDeviceInfo)));
连接设备后出发槽函数:
void CBLEService::onFindBLEMachine(const QBluetoothDeviceInfo &info){
m_controller = new QLowEnergyController(m_bleDevInfo,this);
connect(m_controller, SIGNAL(connected()), this, SLOT(onBLEConnected()));
& ..


#1 [xiaolanchong 05-22 21:29]
楼主,我的为什么连蓝牙设备都找不到,代码看来看去都没问题
#include "Bluetooth.h"
#include "ui_Bluetooth.h"
static const QLatin1String serviceUuid("00001101-0000-1000-8000-00805F9B34FB");
Bluetooth::Bluetooth(QWidget *parent) :
QWidget(parent), localDevice(new QBluetoothLocalDevice),
ui(new Ui::Bluetooth)
{
ui->setupUi(this);
// localDevice = new QBluetoothLocalDevice();
discoveryAgent = new QBluetoothDeviceDiscoveryAgent();
/* 判断蓝牙是否开启,若开启则不可被选中 扫描周围蓝牙设备 */
if( localDevice->hostMode() == QBluetoothLocalDevice::HostPoweredOff)
{
ui->pushButton_openBluetooth->setEnabled(true);
ui->pushButton_upDate->setEnabled(false);
}
else
{
ui->pushButton_openBluetooth->setEnabled(false);
discoveryAgent->start();
}
/* 给socket分配内存,限定套接字协议 */
socket = new QBluetoothSocket(QBluetoothServiceInfo::RfcommProtocol);
/* 发现设备时会触发deviceDiscovered信号,转到槽显示设备 */
connect(discoveryAgent, SIGNAL(deviceDiscovered(QBluetoothDeviceInfo)),
this, SLOT(addBlueToothDevicesToList(QBluetoothDeviceInfo)));
connect(discoveryAgent, SIGNAL(finished()), this, SLOT(upDateFinish()));
/* 点击显示的蓝牙转到连接槽 */
connect(ui->listWidget_displayBluetoothDevice, SIGNAL(itemClicked(QListWidgetItem*)),
..
#2 [nikonice 05-28 08:26]
discoveryAgent = new QBluetoothDeviceDiscoveryAgent(this);
connect(discoveryAgent, SIGNAL(deviceDiscovered(const QBluetoothDeviceInfo&)),
this, SLOT(addDevice(const QBluetoothDeviceInfo&)));
connect(discoveryAgent, SIGNAL(error(QBluetoothDeviceDiscoveryAgent::Error)),
this, SLOT(onDeviceScanError(QBluetoothDeviceDiscoveryAgent::Error)));
connect(discoveryAgent, SIGNAL(finished()), this, SLOT(onScanFinished()));
可以试试,我的没问题的
#3 [大千世界mcq 10-09 11:06]
Qt for Android BLE连接上蓝牙后,会去搜寻service,根据搜索到的Service uuid,选择你需要的创建service。然后根据你的发送和接收uuid,确定写和读特征,才能完成正常的蓝牙通信。

回复 发表
主题 版块