本文整理匯總了TypeScript中pc-ble-driver-js.Adapter類的典型用法代碼示例。如果您正苦於以下問題:TypeScript Adapter類的具體用法?TypeScript Adapter怎麽用?TypeScript Adapter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Adapter類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: startReading
openAdapter$.subscribe((adapter: Adapter) => {
adapter.on('error', (err) => {
console.log('An error occurred ..');
console.error(err);
});
startReading(adapter);
});
示例2:
adapterOne.getServices(device.instanceId, (err, services) => {
if (err) {
console.error('failed to discover services');
} else {
// since we are connecitng to iPhone the discovery
// will return many services
console.log(services);
// get the desired service and then discover characterisitc on it
const desiredService = services.filter((s) => s.uuid === config.peripheralOptions.serviceUUID)[0];
console.log(desiredService);
adapterOne.getCharacteristics(desiredService.instanceId, (err, chars) => {
console.log(chars);
const desiredChar = chars.filter((c) => c.uuid === config.peripheralOptions.charUUID)[0];
adapterOne.readCharacteristicValue(desiredChar.instanceId, (err, val) => {
console.log(val);
console.log('Press c to terminate the program ..');
});
});
}
});
示例3: onDeviceDiscovered
return Observable.create((obs: Subscriber<Device>) => {
function onDeviceDiscovered(device: Device) {
obs.next(device);
}
adapter.on('deviceDiscovered', onDeviceDiscovered);
adapter.startScan(scanOptions, (error) => {
if (error) {
obs.error(new ScanError(error));
return;
}
});
return () => {
adapter.removeListener('deviceDiscovered', onDeviceDiscovered);
};
});
示例4: onDeviceConnected
return Observable.create((obs: Subscriber<Device>) => {
function onDeviceConnected(connectedDevice) {
obs.next(connectedDevice);
obs.complete();
}
adapter.on('deviceConnected', onDeviceConnected);
adapter.connect(device.address, options, (err) => {
if (err) {
obs.error(new ConnectError(err, device));
return;
}
});
return () => {
adapter.removeListener('deviceConnected', onDeviceConnected);
};
});
示例5: DisconnectError
return Observable.create((obs: Subscriber<void>) => {
adapter.disconnect(device.instanceId, (err) => {
if (err) {
obs.error(new DisconnectError(err, device));
return;
}
obs.next();
obs.complete();
});
return () => {
};
});
示例6: CharacteristicDiscoveryError
return Observable.create((obs: Subscriber<Characteristic[]>) => {
adapter.getCharacteristics(service.instanceId, (err, chars) => {
if (err) {
obs.error(new CharacteristicDiscoveryError(err, service));
return;
}
obs.next(chars);
obs.complete();
});
return () => {
};
});
示例7: ServiceDiscoveryError
return Observable.create((obs: Subscriber<Service[]>) => {
adapter.getServices(device.instanceId, (err, services) => {
if (err) {
obs.error(new ServiceDiscoveryError(err, device));
return;
}
obs.next(services);
obs.complete();
});
return () => {
};
});
示例8: ReadCharacteristicError
return Observable.create((obs: Subscriber<string>) => {
adapter.readCharacteristicValue(characteristic.instanceId, (err, value) => {
if (err) {
obs.error(new ReadCharacteristicError(err, characteristic));
return;
}
obs.next(toHexString(value));
obs.complete();
});
return () => {
};
});