Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cordova 如何使用evothing从(Contec)脉搏血氧仪读取和解析数据?_Cordova - Fatal编程技术网

Cordova 如何使用evothing从(Contec)脉搏血氧仪读取和解析数据?

Cordova 如何使用evothing从(Contec)脉搏血氧仪读取和解析数据?,cordova,Cordova,我想开发一个移动应用程序,使用evothings(或phonegap)通过蓝牙连接读取和解析Contec脉搏血氧仪的测量数据 我可以连接、发现和读取静态数据(设备名称、地址…),但无法读取测量结果。 我应该使用什么服务和特性?我应该写描述符来获得测量结果吗 发现结果是(evothings): Phonegap(可扩展插件) 我的JS代码 // JavaScript code for the BLE Discovery example app. // TODO: Add comments to

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

发现结果是(evothings):

Phonegap(可扩展插件)

我的JS代码

// 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);
//BLE发现示例应用程序的JavaScript代码。
//TODO:向函数添加注释,缩短长行。
$(文档).ready(函数()
{
});
/**BLE插件是异步加载的,因此
变量在onDeviceReady处理程序中重新定义*/
var-ble=null;
//应用程序对象。
var-app={};
//将以毫秒为间隔进行BLE设备扫描。
app.scanInterval=5000;
//跟踪扫描是否正在进行,以避免多次间隔。
app.isScanning=false;
//上次扫描事件的时间。这对我们来说很有用
//当设备不支持连续扫描时。
app.lastScanEvent=0;
//应用程序构造函数
app.initialize=函数()
{
这是bindEvents();
};
//绑定事件侦听器
//
//绑定启动时所需的任何事件。常见事件包括:
//“加载”、“deviceready”、“脱机”和“联机”。
app.bindEvents=函数()
{
文件.addEventListener('devicerady',this.ondevicerady,false);
};
//deviceready事件处理程序
//
//“此”的范围是事件。为了调用“receivedEvent”
//函数,我们必须明确调用“app.receivedEvent(…);”
app.ondevicerady=函数()
{
//插件是异步加载的,可以在这里引用。
可唤起的事物;
app.receivedEvent(“DeviceRady”);
};
app.receivedEvent=函数(id)
{
console.log('接收到的事件:'+id);
};
app.scan=函数(){
table.stopScan();
$(“#结果”).html('BLE设备正在扫描…');
表.startScan(功能(r){
//$('#result').html(''+JSON.stringify(r)+'');
$('#result').html('+r.name+'['+r.address+']'+r.rssi+'');
$('#result')。追加('Connecting…');
应用程序连接(r地址);
},函数(){
$('#result').html('BLE设备扫描失败');
});
}
app.connect=功能(地址){
table.stopScan();
//$('#result')。追加(''+地址+'');
连接(地址、功能(r){
//状态=2设备句柄=1
$('#result').html('成功连接
'+JSON.stringify(r)+''); 应用服务(r.deviceHandle); },函数(错误代码){ $('#result').html('连接失败['+errorCode+']); }); }; app.services=功能(deviceHandle){ table.readAllServiceData(设备句柄、函数(服务){ //$('#result').html(''+JSON.stringify(services)+''; 应用程序读取(deviceHandle); },函数(错误代码){ $('#result').html('读取服务失败['+errorCode+']); }); } app.read=函数(deviceHandle){ /* table.readCharacteristic(deviceHandle,15,函数(数据){ $('#result').html('['+ble.fromUtf8(数据)+']'); },函数(错误代码){ $('#result').html('读取失败['+errorCode+']); }); */ Enable.启用通知(deviceHandle,19,函数(数据){ $('#result').html('['+ble.fromUtf8(数据)+']
'+data+']; },函数(错误代码){ $('#result').html('启用通知失败['+errorCode+']); }); 表.描述符(deviceHandle,19,函数(描述符){ $('#result').html('['+描述符[0].handle+']'); Table.writeDescriptor(deviceHandle,描述符[0]。handle,新Uint8Array([1,0]),函数(){ $('#result').html('Write success'); },函数(错误代码){ $('#result').html('写入失败['+errorCode+']); }); setTimeout(函数(){ Table.readDescriptor(deviceHandle,描述符[0]。句柄,函数(数据){ $('#result').html('['+ble.fromUtf8(数据)+']
'+data+']; },函数(错误代码){ $('#result').html('读取描述符失败['+errorCode+']); }) }, 10000); },函数(错误代码){ $('#result').html('Characteristics failed['+errorCode+']); }); } $(文档).on('单击','扫描',app.scan);
在调用
ble.enableNotification
ble.descriptor
时,您不能像在
应用程序中那样硬编码
特征.句柄。这些值很可能在程序运行之间发生变化,甚至更可能在平台之间发生变化

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


为了简化BLE编程中的这个(相当常见的)任务,我们在BLE插件的基础上构建了一个名为“”的库。如果您愿意,可以使用它。

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

我现在记得,有些设备要求您将某些值写入某些特征,以便启动将导致通知的测量。例如,德克萨斯仪器公司(link)

在您的服务UUID上进行谷歌搜索表明它被称为“”,似乎起到了某种串行数据链接的作用。不幸的是,我找不到任何英文文档

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

这时我记起了
{
    "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"
}
// 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);