Please refer my code

Qt Code:
  1. #include "bluetoothupdater.h"
  2.  
  3. BluetoothUpdater::BluetoothUpdater()
  4. {
  5. QBluetoothDeviceDiscoveryAgent* discovery = new QBluetoothDeviceDiscoveryAgent();
  6.  
  7. connect(discovery, &QBluetoothDeviceDiscoveryAgent::deviceDiscovered, [&] (const QBluetoothDeviceInfo &device)
  8. {
  9. if(device.name() == "Targ")
  10. {
  11. qDebug() << "Found new device:" << device.name();
  12. ptrQBluetoothDeviceInfo = new QBluetoothDeviceInfo(QBluetoothAddress(device.address()), device.name(), 0);
  13. m_control = new QLowEnergyController(*ptrQBluetoothDeviceInfo);
  14. m_control->connectToDevice();
  15. m_control->discoverServices();
  16. //connect(m_control, &QLowEnergyService::stateChanged, this, &BluetoothUpdater::service serviceDiscovered, this, &BluetoothUpdater::serviceDiscovered);
  17. connect(m_control, &QLowEnergyController::serviceDiscovered, this, &BluetoothUpdater::serviceDiscovered);
  18. connect(m_control, &QLowEnergyController::discoveryFinished, this, &BluetoothUpdater::serviceScanDone);
  19. }
  20. });
  21.  
  22. //connect(discovery, &QBluetoothDeviceDiscoveryAgent::deviceDiscovered, this, &BluetoothUpdater::addDevice);
  23. discovery->setLowEnergyDiscoveryTimeout(5000);
  24. discovery->start(QBluetoothDeviceDiscoveryAgent::LowEnergyMethod);
  25. }
  26.  
  27. void BluetoothUpdater::serviceScanDone()
  28. {
  29. qDebug() << "Service scan done.";
  30.  
  31. if (m_foundHeartRateService)
  32. {
  33. qDebug() << m_foundHeartRateService;
  34. m_service = m_control->createServiceObject(QBluetoothUuid(DFUService));
  35. qDebug() << m_service;
  36. }
  37.  
  38. if (m_service)
  39. {
  40. qDebug() << "DFU Service found";
  41. m_service->discoverDetails();
  42. connect(m_service, &QLowEnergyService::stateChanged, this, &BluetoothUpdater::serviceStateChanged);
  43. connect(m_service, &QLowEnergyService::characteristicChanged, this, &BluetoothUpdater::updateValue);
  44. connect(m_service, &QLowEnergyService::descriptorWritten, this, &BluetoothUpdater::confirmedDescriptorWrite);
  45. }
  46. else
  47. {
  48. qDebug() << "DFU Service not found.";
  49. }
  50. }
  51.  
  52. void BluetoothUpdater::serviceDiscovered(const QBluetoothUuid &gatt)
  53. {
  54. if (gatt == QBluetoothUuid(DFUService))
  55. {
  56. qDebug() << "DFU service discovered.";
  57. m_foundHeartRateService = true;
  58. }
  59. }
  60.  
  61. void BluetoothUpdater::serviceStateChanged(QLowEnergyService::ServiceState state)
  62. {
  63. if(state == QLowEnergyService::ServiceDiscovered)
  64. {
  65. ControlPointChar = m_service->characteristic(QBluetoothUuid(ControlPointUUID));
  66. if(ControlPointChar.isValid())
  67. {
  68. qDebug() << "Control Point Characteristic Found";
  69. m_service->writeCharacteristic(ControlPointChar, QByteArray::fromHex("0601"), QLowEnergyService::WriteWithResponse);
  70. }
  71. else
  72. {
  73. qDebug() << "Control Point Characteristic Not Found";
  74. }
  75. ControlPointDesc = ControlPointChar.descriptor(QBluetoothUuid::ClientCharacteristicConfiguration);
  76. if (ControlPointDesc.isValid())
  77. {
  78. qDebug() << "Descriptor";
  79. m_service->writeDescriptor(ControlPointDesc, QByteArray::fromHex("0100"));
  80. }
  81. }
  82. }
  83.  
  84. void BluetoothUpdater::updateValue(const QLowEnergyCharacteristic &c, const QByteArray &value)
  85. {
  86. qDebug() << "updateValue, c.uuid:" << c.uuid();
  87. qDebug() << "updateValue, value:" << value;
  88. }
  89.  
  90. void BluetoothUpdater::confirmedDescriptorWrite(const QLowEnergyDescriptor &d, const QByteArray &value)
  91. {
  92. qDebug() << "confirmedDescriptorWrite:" << value;
  93. if (d.isValid() && d == ControlPointDesc && value == QByteArray::fromHex("0000"))
  94. {
  95. qDebug() << "Inside confirmedDescriptorWrite";
  96. m_control->disconnectFromDevice();
  97. delete m_service;
  98. m_service = nullptr;
  99. }
  100. }
To copy to clipboard, switch view to plain text mode 

This line
Qt Code:
  1. m_service->writeCharacteristic(ControlPointChar, QByteArray::fromHex("0601"), QLowEnergyService::WriteWithResponse);
To copy to clipboard, switch view to plain text mode 
does not work