首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用激发从(Contec)脉冲氧饱和度计中读取和解析数据?

如何使用激发从(Contec)脉冲氧饱和度计中读取和解析数据?
EN

Stack Overflow用户
提问于 2015-08-31 10:01:56
回答 4查看 2.2K关注 0票数 2

我想开发一个移动应用程序,通过蓝牙连接读取和解析来自Contec脉冲氧表的测量数据,我可以使用evothing(或phonegap)连接、发现和读取静态数据(设备名称、地址.),但我无法读取测量结果。我应该使用什么服务和特色?我应该写描述符来得到测量结果吗?

发现的结果是:

代码语言:javascript
复制
[
    {
        "type":0,"uuid":"00001800-0000-1000-8000-00805f9b34fb",
        "handle":1,
        "characteristics":[
            {
                "permissions":0,
                "writeType":2,
                "properties":2,
                "uuid":"00002a00-0000-1000-8000-00805f9b34fb",
                "handle":4,
                "descriptors":[]
            },
            {
                "permissions":0,
                "writeType":2,
                "properties":2,
                "uuid":"00002a01-0000-1000-8000-00805f9b34fb",
                "handle":5,
                "descriptors":[]
            },
            {
                "permissions":0,
                "writeType":2,
                "properties":2,
                "uuid":"00002a04-0000-1000-8000-00805f9b34fb",
                "handle":6,
                "descriptors":[]
            }
        ]
    },

    {
        "type":0,"uuid":"0000180a-0000-1000-8000-00805f9b34fb",
        "handle":2,
        "characteristics":[
            {
                "permissions":0,
                "writeType":2,
                "properties":2,
                "uuid":"00002a29-0000-1000-8000-00805f9b34fb",
                "handle":7,
                "descriptors":[]
            },
            {
                "permissions":0,
                "writeType":2,
                "properties":2,
                "uuid":"00002a24-0000-1000-8000-00805f9b34fb",
                "handle":8,
                "descriptors":[]
            },
            {
                "permissions":0,
                "writeType":2,
                "properties":2,
                "uuid":"00002a25-0000-1000-8000-00805f9b34fb",
                "handle":9,
                "descriptors":[]
            },
            {
                "permissions":0,
                "writeType":2,
                "properties":2,
                "uuid":"00002a27-0000-1000-8000-00805f9b34fb",
                "handle":10,
                "descriptors":[]
            },
            {
                "permissions":0,
                "writeType":2,
                "properties":2,
                "uuid":"00002a26-0000-1000-8000-00805f9b34fb",
                "handle":11,
                "descriptors":[]
            },
            {
                "permissions":0,
                "writeType":2,
                "properties":2,
                "uuid":"00002a28-0000-1000-8000-00805f9b34fb",
                "handle":12,"descriptors":[]
            },
            {
                "permissions":0,
                "writeType":2,
                "properties":2,
                "uuid":"00002a23-0000-1000-8000-00805f9b34fb",
                "handle":13,
                "descriptors":[]
            },
            {
                "permissions":0,
                "writeType":2,
                "properties":2,
                "uuid":"00002a2a-0000-1000-8000-00805f9b34fb",
                "handle":14,
                "descriptors":[]
            }
        ]
    },

    {
        "type":0,
        "uuid":"49535343-fe7d-4ae5-8fa9-9fafd205e455",
        "handle":3,
        "characteristics":[
            {
                "permissions":0,
                "writeType":2,
                "properties":10,
                "uuid":"49535343-6daa-4d02-abf6-19569aca69fe",
                "handle":15,
                "descriptors":[]
            },
            {
                "permissions":0,
                "writeType":2,
                "properties":24,
                "uuid":"49535343-aca3-481c-91ec-d85e28a60318",
                "handle":16,
                "descriptors":[
                    {
                        "permissions":0,
                        "uuid":"00002902-0000-1000-8000-00805f9b34fb",
                        "handle":20
                    }
                ]
            },
            {
                "permissions":0,
                "writeType":1,
                "properties":30,
                "uuid":"49535343-1e4d-4bd9-ba61-23c647249616",
                "handle":17,
                "descriptors":[
                    {
                        "permissions":0,
                        "uuid":"00002902-0000-1000-8000-00805f9b34fb",
                        "handle":21
                    }
                ]
            },
            {
                "permissions":0,
                "writeType":1,
                "properties":12,
                "uuid":"49535343-8841-43f4-a8d4-ecbe34729bb3",
                "handle":18,
                "descriptors":[]
            },
            {
                "permissions":0,
                "writeType":2,
                "properties":24,
                "uuid":"49535343-026e-3a9b-954c-97daef17e26e",
                "handle":19,
                "descriptors":[
                    {
                        "permissions":0,
                        "uuid":"00002902-0000-1000-8000-00805f9b34fb",
                        "handle":22
                    }
                ]
            }
        ]
    }
]

Phonegap (BLE插件)

代码语言:javascript
复制
{
    "address":"8C:DE:52:80:B5:24",
    "status":"discovered",
    "services":[
        {"characteristics":
            [
                {"descriptors":[],"characteristicUuid":"2a00","properties":{"read":true}},
                {"descriptors":[],"characteristicUuid":"2a01","properties":{"read":true}},
                {"descriptors":[],"characteristicUuid":"2a04","properties":{"read":true}}
            ],
            "serviceUuid":"1800"
        },
        {"characteristics":
            [
                {"descriptors":[],"characteristicUuid":"2a29","properties":{"read":true}},
                {"descriptors":[],"characteristicUuid":"2a24","properties":{"read":true}},
                {"descriptors":[],"characteristicUuid":"2a25","properties":{"read":true}},
                {"descriptors":[],"characteristicUuid":"2a27","properties":{"read":true}},
                {"descriptors":[],"characteristicUuid":"2a26","properties":{"read":true}},
                {"descriptors":[],"characteristicUuid":"2a28","properties":{"read":true}},
                {"descriptors":[],"characteristicUuid":"2a23","properties":{"read":true}},
                {"descriptors":[],"characteristicUuid":"2a2a","properties":{"read":true}}
            ],
            "serviceUuid":"180a"
        },
        {"characteristics":
            [
                {
                    "descriptors":[],
                    "characteristicUuid":"49535343-6daa-4d02-abf6-19569aca69fe",
                    "properties":{"write":true,"read":true}
                },

                {
                    "descriptors":[{"descriptorUuid":"2902"}],
                    "characteristicUuid":"49535343-aca3-481c-91ec-d85e28a60318",
                    "properties":{"write":true,"notify":true}
                },

                {
                    "descriptors":[{"descriptorUuid":"2902"}],
                    "characteristicUuid":"49535343-1e4d-4bd9-ba61-23c647249616",
                    "properties":{"write":true,"writeWithoutResponse":true,"read":true,"notify":true}
                },

                {
                    "descriptors":[],
                    "characteristicUuid":"49535343-8841-43f4-a8d4-ecbe34729bb3",
                    "properties":{"write":true,"writeWithoutResponse":true}
                },

                {
                    "descriptors":[{"descriptorUuid":"2902"}],
                    "characteristicUuid":"49535343-026e-3a9b-954c-97daef17e26e",
                    "properties":{"write":true,"notify":true}
                }
            ],
            "serviceUuid":"49535343-fe7d-4ae5-8fa9-9fafd205e455"
        }
    ],
    "name":"SpO2081127"
}

我的JS代码

代码语言:javascript
复制
// JavaScript code for the BLE Discovery example app.

// TODO: Add comments to functions, shorten long lines.

$(document).ready( function()
{

});

/** BLE plugin, is loaded asynchronously so the
    variable is redefined in the onDeviceReady handler. */
var ble = null;

// Application object.
var app = {};

// BLE device scanning will be made with this interval in milliseconds.
app.scanInterval = 5000;

// Track whether scanning is ongoing to avoid multiple intervals.
app.isScanning = false;

// Time for last scan event. This is useful for
// when the device does not support continuous scan.
app.lastScanEvent = 0;

// Application Constructor
app.initialize = function()
{
    this.bindEvents();
};

// Bind Event Listeners
//
// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', and 'online'.
app.bindEvents = function()
{
    document.addEventListener('deviceready', this.onDeviceReady, false);
};

// deviceready Event Handler
//
// The scope of 'this' is the event. In order to call the 'receivedEvent'
// function, we must explicity call 'app.receivedEvent(...);'
app.onDeviceReady = function()
{
    // The plugin was loaded asynchronously and can here be referenced.
    ble = evothings.ble;
    app.receivedEvent('deviceready');
};

app.receivedEvent = function(id)
{
    console.log('Received Event: ' + id);
};

app.scan = function(){
    ble.stopScan();
    $('#result').html('<span class="message">BLE device is scanning...</span>');
    ble.startScan(function(r){
        //$('#result').html('<span class="success">'+JSON.stringify(r)+'</span>');
        $('#result').html('<div class="device"><span class="message">'+r.name+'</span> [<span class="address">'+r.address+'</span>] <span class="success">'+r.rssi+'</span></div>');
        $('#result').append('<span class="message">Connecting...</span>');
        app.connect(r.address);
    }, function(){
        $('#result').html('<span class="error">BLE device scanning failed.</span>');
    });
}

app.connect = function(address) {
    ble.stopScan();
    //$('#result').append('<span class="success">'+address+'</span>');
    ble.connect(address, function(r){
        // state=2  deviceHandle=1
        $('#result').html('<span class="success">Successfully connected<br>'+JSON.stringify(r)+'</span>');
        app.services(r.deviceHandle);
    }, function(errorCode){
        $('#result').html('<span class="error">Connection failed ['+errorCode+'].</span>');
    });
};

app.services = function(deviceHandle){
    ble.readAllServiceData(deviceHandle, function(services){
        //$('#result').html('<span class="success">'+JSON.stringify(services)+'</span>');
        app.read(deviceHandle);
    }, function(errorCode){
        $('#result').html('<span class="error">Read services failed ['+errorCode+'].</span>');
    });
}

app.read = function(deviceHandle){
    /*
    ble.readCharacteristic(deviceHandle, 15, function(data){ 
        $('#result').html('<span class="success">['+ble.fromUtf8(data)+']</span>');
    }, function(errorCode){
        $('#result').html('<span class="error">Read failed ['+errorCode+'].</span>');
    });
    */


    ble.enableNotification(deviceHandle, 19, function(data){
        $('#result').html('<span class="success">['+ble.fromUtf8(data)+']<br>'+data+'</span>');
    }, function(errorCode){
        $('#result').html('<span class="error">Enable notification failed ['+errorCode+'].</span>');
    });


    ble.descriptors(deviceHandle,19, function(descriptors){
        $('#result').html('<span class="success">['+descriptors[0].handle+']</span>');
        ble.writeDescriptor(deviceHandle, descriptors[0].handle, new Uint8Array([1,0]), function(){
            $('#result').html('<span class="message">Write success.</span>');
        }, function(errorCode){
            $('#result').html('<span class="error">Write failed ['+errorCode+'].</span>');
        });

        setTimeout(function(){
            ble.readDescriptor(deviceHandle, descriptors[0].handle, function(data){
                $('#result').html('<span class="success">['+ble.fromUtf8(data)+']<br>'+data+'</span>');
            }, function(errorCode){
                $('#result').html('<span class="error">Read descriptor failed ['+errorCode+'].</span>');
            })
        }, 10000);
    }, function(errorCode){
        $('#result').html('<span class="error">Characteristics failed ['+errorCode+'].</span>');
    });

}

$(document).on('click','#scan',app.scan);
EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2017-12-11 19:15:25

Contec测氧仪确实使用ISSC透明业务。也就是说,服务并不是真正的特定于氧计,它只是一个服务‘透明’暴露串行连接通过蓝牙乐。

您只需要使用两个特性: TX和RX特性:

TX: 49535343-1E4D-4BD9-BA61-23C647249616

RX: 49535343-8841-43F4-A8D4-ECBE34729B3

您需要做的是:

  1. 对TX特性打开通知
  2. 将命令写入RX特性(WriteWithResponse)
  3. 您将收到有关TX特性的数据。

例如,要打开实时数据流:

  1. 将以下9个字节写入RX特性:{0x7D、0x81、0xA1、0x80、0x80、0x80、0x80、0x80、0x80}。所有命令都是9个字节。
  2. 你将开始接收60赫兹的TX特性数据。

有关如何解析数据的更多命令和信息,请参见阿尔伯特·布劳恩( Albert )为CMS50FW设计的Github项目。该项目还包含一个PDF文件和协议的文档

票数 1
EN

Stack Overflow用户

发布于 2015-09-02 12:39:10

您不能像调用characteristic.handlesble.descriptors时在app.read函数中所做的那样,硬编码ble.enableNotification。这些值可能会在程序运行期间发生变化,甚至更有可能在不同平台之间发生变化。

相反,您必须在ble.readAllServiceData回调中迭代服务及其特性,使用所需的UUID查找特性,保存它的句柄(通常在app.member中),并在app.read中使用它。

为了简化BLE编程中的这个(相当常见的)任务,我们在BLE插件之上构建了一个名为"平顺“的库。你想用就用吧。

票数 0
EN

Stack Overflow用户

发布于 2015-09-04 10:15:19

我可以在链接的示例中发现的唯一明显错误是,您没有检查描述符的UUID (这很糟糕,因为除了"2902“描述符之外还有其他描述符),但是如果您之前发布的发现结果保持不变,那么这不应该阻止这个特定程序的工作。

我现在还记得,有些设备要求您将某些值写入特定的特性,以便启动将导致通知的度量。例如,德州仪器公司的SensorTag (链接)。

在你的服务UUID上的Google搜索表明它被称为"ISSC专有服务",并且看起来像是某种串行的数据链接。不幸的是,我找不到任何英文文件。

如果该服务用于运行心率监视器,那么我怀疑您的问题会变得更加复杂。

在这一点上,我记得我是愚蠢的,没有查询你正在使用的设备的名称。最初建造的Contec脉冲氧表似乎使用了一个相当复杂的串行协议,用于RS232或USB连接。这就解释了ISSC的串行服务。不幸的是,它对我们帮助不大,因为我们仍然不知道该服务是如何工作的。

我也无法在互联网上找到任何使用BLE的Contec设备。您有描述设备通信协议的用户手册或文档吗?

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

https://stackoverflow.com/questions/32308663

复制
相关文章

相似问题

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