react-native-serialport-bluetooth
Version:
comunicacao serialport e bluetooth para android
37 lines • 1.41 kB
JavaScript
import { NativeEventEmitter, NativeModules, Platform } from 'react-native';
import Connect from './connect';
import SerialportBluetooth from './native_module';
export let Parity = /*#__PURE__*/function (Parity) {
Parity[Parity["None"] = 0] = "None";
Parity[Parity["Odd"] = 1] = "Odd";
Parity[Parity["Even"] = 2] = "Even";
Parity[Parity["Mark"] = 3] = "Mark";
Parity[Parity["Space"] = 4] = "Space";
return Parity;
}({});
const defaultManager = {
list() {
return SerialportBluetooth.list();
},
async tryRequestPermission(deviceId) {
const result = await SerialportBluetooth.tryRequestPermission(deviceId);
return result === 1;
},
hasPermission(deviceId) {
return SerialportBluetooth.hasPermission(deviceId);
},
async open(deviceId, options) {
if (Platform.OS !== 'android') throw new Error(`Not support ${Platform.OS}`);
return SerialportBluetooth.open(deviceId, options.baudRate, options.dataBits, options.stopBits, options.parity, options.readWaitMillis || 200, options.writeWaitMillis || 200).then(() => {
return Promise.resolve(new Connect(deviceId, new NativeEventEmitter(NativeModules.SerialportBluetooth)));
});
}
};
export const SerialBluetoothManager = Platform.OS === 'android' ? defaultManager : new Proxy({}, {
get() {
return () => {
throw new Error(`Not support ${Platform.OS}`);
};
}
});
//# sourceMappingURL=index.js.map