VC 蓝牙通信。。。

梦境传说 梦境传说 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
用VC开发的蓝牙通信:

1. 蓝牙设备搜索,并将搜索到得地址显示到Listbox中。

2. PC机和硬件设备通过蓝牙连接好后,将发送开始采集指令。

3. 点击断开按钮,PC机与硬件设备断开连接。

望CSDN的高手们帮忙看看,我的第一步已经实现,可以搜索到硬件设备的蓝牙地址。
现在就卡住在,我怎么发送指令,(即发送指令的函数,VC中有关蓝牙封装好的类)

望高手们帮忙看看。。。谢谢!


下面是C#部分代码:
 private NetworkStream _peerStream;   //C#中NetworkStream, 用VC中哪个类代替

//数据接收函数---------------------------
private void RecvThreadProc(object state)
{
try
{
while (_peerStream.DataAvailable)
{
_peerStream.Read(new byte[1024], 0, 1024);
}

_peerStream.Write(new byte[] {0xfe, 0xb7 + 1, 0xa0}, 0, 3); //开始发送指令

SaveIndexInfoTop();

_currentState = State.Working;
UpdateStateUI();


while (_isRunning) //运行中
{
var bytes = new byte[1024];
int len = _peerStream.Read(bytes, 0, 1024); //从流中读取缓冲字节数组
if (len == 0)
throw new IOException("Link Lost");
for (int i = 0; i < len; i++)
{
_recvqueue.Enqueue(bytes[i]);
}

while (_recvqueue.Count >= 22)
{
if (_recvqueue.Dequeue() != 0xe0)
{
break;
}

byte dataCountLoLo = _recvqueue.Dequeue();
byte dataCountLoHi = _recvqueue.Dequeue();
byte dataCountHiLo = _recvqueue.Dequeue();
byte dataCountHiHi = _recvqueue.Dequeue();
var framecount =
(uint)((dataCountHiHi << 24) + (dataCountHiLo << 16) + (dataCountLoHi << 8) + dataCountLoLo);

var checksum = (byte)(dataCountLoLo + dataCountLoHi + dataCountHiLo + dataCountHiHi);

var channeltmp = new int[8];
for (int i = 0; i < 8; i++)
{
byte tmpL = _recvqueue.Dequeue();
byte tmpH = _recvqueue.Dequeue();
checksum = (byte) (checksum + tmpL + tmpH);

//Console.WriteLine("{0}",checksum);
//Console.WriteLine("{0}", tmpL);
//Console.WriteLine("{0}", tmpH);

channeltmp[i] = (tmpH << 8) + tmpL;
}
if (_recvqueue.Dequeue() != checksum)
{
break;
}

var channel = new int[6];
channel[0] = channeltmp[2];
channel[1] = channeltmp[0];
channel[2] = channeltmp[3];
channel[3] = channeltmp[1];
channel[4] = channeltmp[5];
channel[5] = channeltmp[4];

lock (_channelqueue)
{
while (framecount - _frameRecvCount - 1 > 0)
{
_channelqueue.Enqueue(null);
_frameRecvCount++;
}
_channelqueue.Enqueue(channel);
_frameRecvCount++;
_channelEvent.Set();
}

if (framecount%_samplingFreq == 0)
{
_peerStream.Write(new byte[] {0xfe, 0xb7 + 1, 0xa3}, 0, 3); //breath cmd
}
}
}
_peerStream.Write(new byte[] {0xfe, 0xb7 + 1, 0xa1}, 0, 3); //停止发送指令
_channelEvent.Set();
_calcStopEvent.WaitOne();
SaveIndexInfoBottom("User stop");
_currentState = State.Idle;
Invoke(new Action(UpdateStateUI));
}
catch (Exception ex)
{
LinkLost();
MessageBox.Show(ex.Message);
}
}



现在怎么把C#这段蓝牙通信发送给硬件设备的指令并采集数据上来。 怎么转化为VC代码。
...全文
评论 13
收藏 已收藏
分享
返回顶部
梦境传说
VC/MFC 16,551 成员 421,605 内容