unity 2017.3 安卓蓝牙(三)向蓝牙设备发送(Write)消息

API插件为我们准备的API是BluetoothLEHardwareInterface.WriteCharacteristic(string name, string service, string characteristic, byte[] data, int length, bool withResponse, Action<string> action);共七个参数,分别是:设...
摘要由CSDN通过智能技术生成

API

插件为我们准备的API是BluetoothLEHardwareInterface.WriteCharacteristic(string name, string service, string characteristic, byte[] data, int length, bool withResponse, Action<string> action);

共七个参数,分别是:设备地址,服务UUID,特征UUID,准备发送的数据,数据长度,是否触发回调,回调。

特别强调,第一个参数不是设备名,而是设备地址,其次,发送的数据最好不要超过20个字节,超过20个字节需要特殊处理。

实例代码

这个函数是用来开启和关闭遥控器震动的,发送的数据根据对应设备的通讯协议来组装。回调部分我选择Show一下信息,方便观察。

    private bool shake = true;
    /// <summary>
    /// 开关震动
    /// </summary>
    public void SendShake()
    {
        if (shake)
        {
            byte[] data = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
            BluetoothLEHardwareInterface.WriteCharacteristic(bleAddress, _ServiceUUID, _WriteUUID, data, data.Length, true, (characteristicUUID) =>
            {
         
  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值