首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何通过蓝牙将数据从C#发送到MagicBlue发光二极管?

如何通过蓝牙将数据从C#发送到MagicBlue发光二极管?
EN

Stack Overflow用户
提问于 2018-01-11 03:05:05
回答 1查看 1.7K关注 0票数 0

我正在编写一个需要发送蓝牙包到MagicBlue发光二极管的.NET应用程序。换句话说,我想创建一个.NET应用程序,类似于它的Android应用程序:https://itunes.apple.com/us/app/led-magic-blue/id992330218?mt=8

这是一个演示:https://www.youtube.com/watch?v=5Q3aQjuiLY0

我的蓝牙适配器已经找到了灯泡并连接到它,所以它是可发现的,我也有它的MAC地址,这是我的目的所需。

我正在使用InTheHand (32Feet Bluetooth) .NET Library进行通信。灯泡需要接收字节数组,以便执行命令(更改颜色、通电/断电等)。

代码语言:javascript
复制
// I use this Write function to send an array of bytes.
private bool Write(byte[] buffer)
{
    using (var bluetoothClient = new BluetoothClient())
    {
        try
        {
            var ep = new BluetoothEndPoint(_macAddress, Guid.NewGuid());
            bluetoothClient.Connect(ep);
            var bluetoothStream = bluetoothClient.GetStream();
            if (bluetoothStream != null)
            {
                bluetoothStream.Write(buffer, 0, buffer.Length);
                bluetoothStream.Flush();
                bluetoothStream.Close();
                return true;
            }
        }
        catch (Exception ex) { } 
    }
}

当我访问bluetoothClient.Connect(ep);时,它抛出一个异常,说明"the connected party did not properly responded after a period of time..."

我怎样才能解决这个问题,把字节数组转换成灯泡呢?

EN

回答 1

Stack Overflow用户

发布于 2018-08-08 20:39:44

更改为:

代码语言:javascript
复制
var ep = new BluetoothEndPoint(_macAddress, BluetoothService.HandsFree);

它将会工作的很好!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48194425

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档