VC 蓝牙通信。。。
用VC开发的蓝牙通信:
1. 蓝牙设备搜索,并将搜索到得地址显示到Listbox中。
2. PC机和硬件设备通过蓝牙连接好后,将发送开始采集指令。
3. 点击断开按钮,PC机与硬件设备断开连接。
望CSDN的高手们帮忙看看,我的第一步已经实现,可以搜索到硬件设备的蓝牙地址。
现在就卡住在,我怎么发送指令,(即发送指令的函数,VC中有关蓝牙封装好的类)
望高手们帮忙看看。。。谢谢!
下面是C#部分代码:
现在怎么把C#这段蓝牙通信发送给硬件设备的指令并采集数据上来。 怎么转化为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代码。
...全文
相关推荐
在VC6.0上编译通过的蓝牙通信演示程序
在VC6.0上编译通过的蓝牙通信演示程序
BluetoothHCI_蓝牙VC源代码_vc蓝牙_蓝牙_bluetooth_
BluetoothHCI蓝牙编程代码,很好的源代码使用VC实现蓝牙通信!!适用于初学VC的朋友们
VC2010 蓝牙(Bluetooth)设备查找
BlueToothExc_Plus蓝牙API编程实例,用windowsAPI编写的一个蓝牙识别和串口通信的例子。可以在VS2010上编译通过
VC2010与 蓝牙(Bluetooth)通讯
BlueToothExc_Plus蓝牙API编程实例,用windowsAPI编写的一个蓝牙识别和串口通信的例子。可以在VS2010上编译通过
BluetoothdevelopmentVC.rar_VC HwCOM_c++蓝牙通信_蓝牙_蓝牙 界面_蓝牙pc
蓝牙指令VC实现其功能,蓝牙通信程序,PC界面程序


