例子:冰狐脚本调用BleClient和蓝牙HID硬件通信 function main() { // 参数为蓝牙硬件中对应的service的uuid和characteristic的UUID var ble = new BleClient('xxxxx-xxxx-xxx-8fxxxcc-xxxxxxx', 'vvvvv-vvv-ssss-xxxx-fffffff'); var ret = ble.connect(); console.log('ret:', ret) if (1 == ret) { // 点击 bleClick(ble, 800, 640); sleep(3000); // 滑动 bleSwipe(ble, rsScreenWidth / 2, rsScreenHeight / 3 * 2, rsScreenWidth / 2, rsScreenHeight / 3, 1000) } } function bleClick(ble, x, y) { x = parseInt(x * 10000 / rsScreenWidth); y = parseInt(y * 10000 / rsScreenHeight); var cmd = `c${x},${y}`}; console.log('cmd:' + cmd) var ret = ble.send(cmd) console.log('send ret:', ret) } function bleSwipe(ble, x1, y1, x2, y2, duration) { x1 = parseInt(x1 * 10000 / rsScreenWidth); y1 = parseInt(y1 * 10000 / rsScreenHeight); x2 = parseInt(x2 * 10000 / rsScreenWidth); y2 = parseInt(y2 * 10000 / rsScreenHeight); var cmd = `m${x1},${y1},${x2},${y2},${duration}`; console.log('cmd:' + cmd) var ret = ble.send(cmd) console.log('send ret:', ret) }
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
serviceUUID | string | 必填 | 服务的uuid |
characteristicUUID | string | 必填 | characteristic的UUID |
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
timeout | integer | 选填 | 超时时间,单位毫秒,默认值3000 |
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
data | string | 必填 | 数据 |
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
timeout | integer | 选填 | 超时时间,单位毫秒,默认值10000 |