Unsolved win/wip branch of QtConnectivity
-
Hello there.
I need to use BLE on WI~~N10 platform (not RT). I was download and built win/wip branch and install it to Qt5.10.
The problem is that i do not receive signal characteristicChanged. I test my program in 3 PC. Only in one it is work fine.
My code is here:
#include <QCoreApplication> #include <QDebug> #include <QTimer> #include <QtConcurrent/QtConcurrent> #include <QBluetoothDeviceDiscoveryAgent> #include <QLowEnergyController> QBluetoothDeviceDiscoveryAgent *agent; QLowEnergyController *device; QLowEnergyService *sps; QLowEnergyCharacteristic credits_ch; QLowEnergyDescriptor credits_dsc; QLowEnergyCharacteristic fifo_ch; QLowEnergyDescriptor fifo_dcs; const QBluetoothUuid sps_fifo_uuid = QBluetoothUuid(QString(("{2456e1b9-26e2-8f83-e744-f34f01e9d703}"))); const QBluetoothUuid sps_flow_uuid = QBluetoothUuid(QString(("{2456e1b9-26e2-8f83-e744-f34f01e9d704}"))); void device_connected() { device->discoverServices(); } void characteristicChanged(const QLowEnergyCharacteristic &info, const QByteArray &value) { qDebug() << value; fifo_ch = info; qDebug() << "handle" << info.handle() << info.name() << info.isValid() << info.properties() << info.uuid() << info.value(); sps->writeCharacteristic(fifo_ch, value, QLowEnergyService::WriteWithoutResponse); } void service_error(QLowEnergyService::ServiceError error) { qDebug() << error; } void device_error(QLowEnergyController::Error error) { qDebug() << error; } void service_descriptor_written(const QLowEnergyDescriptor &info, const QByteArray &value) { qDebug() << "Dsc written:" << info.uuid() << value; } void service_characteristic_written(const QLowEnergyCharacteristic &info, const QByteArray &value) { qDebug() << "Char written:" << info.uuid() << value; } void characteristicRead(const QLowEnergyCharacteristic &info, const QByteArray &value) { qDebug() << "Char read:" << info.uuid() << value; } void timer_triggered() { //sps->readCharacteristic(fifo_ch); sps->writeCharacteristic(fifo_ch, QByteArray("asd")); QTimer::singleShot(1000, Qt::TimerType::PreciseTimer, timer_triggered); } void service_state_changed(QLowEnergyService::ServiceState state) { qDebug() << state; if (state == QLowEnergyService::ServiceDiscovered) { // Получение характеристик credits_ch = sps->characteristic(sps_flow_uuid); fifo_ch = sps->characteristic(sps_fifo_uuid); // Получение дескрипторов характристик fifo_dcs = fifo_ch.descriptor((QBluetoothUuid::ClientCharacteristicConfiguration)); //qDebug() << "handle" << credits_ch.handle() << credits_ch.name() << credits_ch.isValid() << credits_ch.properties() << credits_ch.uuid() << credits_ch.value(); QObject::connect(sps, &QLowEnergyService::characteristicChanged, characteristicChanged); QObject::connect(sps, &QLowEnergyService::characteristicRead, characteristicRead); QObject::connect(sps, QOverload<QLowEnergyService::ServiceError>::of(&QLowEnergyService::error), service_error); QObject::connect(sps, &QLowEnergyService::descriptorWritten, service_descriptor_written); QObject::connect(sps, &QLowEnergyService::characteristicWritten, service_characteristic_written); // Запись в дескрипторы разрешения на получение уведомлений при изменении характиристик sps->writeDescriptor(fifo_dcs, QByteArray::fromHex("0100")); QTimer::singleShot(500, Qt::TimerType::PreciseTimer, timer_triggered); } } void device_service_discovery_finished() { sps = device->createServiceObject(QBluetoothUuid(QString("{2456e1b9-26e2-8f83-e744-f34f01e9d701}")), NULL); QObject::connect(sps, &QLowEnergyService::stateChanged, service_state_changed); sps->discoverDetails(); } void device_status_changed(QLowEnergyController::ControllerState s) { qDebug() << s; } int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); device = new QLowEnergyController(QBluetoothAddress("C0:D2:99:35:20:64")); QObject::connect(device, &QLowEnergyController::connected, device_connected); QObject::connect(device, &QLowEnergyController::stateChanged, device_status_changed); QObject::connect(device, &QLowEnergyController::discoveryFinished, device_service_discovery_finished); QObject::connect(device, QOverload<QLowEnergyController::Error>::of(&QLowEnergyController::error), device_error); device->connectToDevice(); return a.exec(); }
I saw sources and find strange thing, in file qlowenergycontroller_win.cpp in function writeDescriptor after register event function closeSystemDevice is called.
If I comment this closeSystemDevice characterChanged signal is emitted properly. Is it correct way?
I think that this function must be called when unregister function is invoked.Is any one has the same problem? How to solve it correct?
-
Hi and welcome to devnet,
This branch being a work in progress, I'd recommend you bring this topic to the interest mailing list. You'll find there Qt Connectivity's developers/maintainers. This forum is more user oriented.