【发布时间】:2016-05-04 13:31:28
【问题描述】:
我想编写一个通过低功耗蓝牙每 10 毫秒接收一次数据的程序。
我有很多事情要做,但我总是有一个问题,找不到源头。 这是我在 Windows 10 上用 C++Builder 10 编写的代码的基础。
> //---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#define Characteristic_UUID "{6e400003-b5a3-f393-e0a9-e50e24dcca9e}"
#define Service_UUID "{6e400001-b5a3-f393-e0a9-e50e24dcca9e}"
#pragma resource "*.dfm"
TForm1 *Form1;
TBluetoothLEDevice* device;
TBluetoothGattCharacteristicList* characteristic ;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
BluetoothLE1->DiscoverDevices(100);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BluetoothLE1EndDiscoverDevices(TObject * const Sender, TBluetoothLEDeviceList * const ADeviceList)
{
device = ADeviceList->First();
BluetoothLE1->DiscoverServices(device);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BluetoothLE1ServicesDiscovered(TObject * const Sender, TBluetoothGattServiceList * const AServiceList)
{
GUID AGuid;
CLSIDFromString(TEXT(Service_UUID), &AGuid);
TBluetoothGattService* service = BluetoothLE1->GetService(device,AGuid);
//TBluetoothGattServiceList* abcd = BluetoothLE1->GetServices(device);
CLSIDFromString(TEXT(Characteristic_UUID), &AGuid);
characteristic = BluetoothLE1->GetCharacteristics(service);
while(characteristic->First()->UUID != AGuid)
{
characteristic->Delete(0);
}
if(characteristic->First()!= NULL);
BluetoothLE1->SubscribeToCharacteristic(device,characteristic->First());
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BluetoothLE1CharacteristicRead(TObject * const Sender, TBluetoothGattCharacteristic * const ACharacteristic,
TBluetoothGattStatus AGattStatus)
{
static long i;
Label1->Caption = i;
i++;
}
//---------------------------------------------------------------------------
恰好在 86303 通知(调用 BluetoothLE1CharacteristicRead)之后,我得到了 Stack Overflow。所以肯定有问题。 一开始我用 C++ 在 Visual Studio 中使用 Windows 驱动程序函数编写程序,但同样的事情。
【问题讨论】:
-
写“堆栈溢出”以区别于 StackOverflow。该网站是另一回事:)
-
你检查过实际堆栈吗?这通常是堆栈溢出的原因。通常你有一个模式
ABCABCABCABCAB,其中一些可能不是你的函数。一个常见的原因是从回调中调用库函数,以便库再次调用您的回调... -
好吧,我注意到现在几乎整个堆栈都充满了这些 12Bytes 0x014F3200 -> .O2。 0x005FFF64 -> ._ÿd 0x00000000 -> .... 但我怎样才能知道那是什么。
标签: c++ windows bluetooth-lowenergy c++builder