当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript pc-ble-driver-js.Adapter类代码示例

本文整理汇总了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);
  });
开发者ID:ksachdeva,项目名称:pc-ble-driver-js-examples,代码行数:9,代码来源:index.ts

示例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 ..');

            });

          });
        }
      });
开发者ID:ksachdeva,项目名称:pc-ble-driver-js-examples,代码行数:26,代码来源:index.ts

示例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);
    };
  });
开发者ID:ksachdeva,项目名称:rx-pc-ble-driver-js,代码行数:19,代码来源:index.ts

示例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);
    };
  });
开发者ID:ksachdeva,项目名称:rx-pc-ble-driver-js,代码行数:20,代码来源:index.ts

示例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 () => {
    };
  });
开发者ID:ksachdeva,项目名称:rx-pc-ble-driver-js,代码行数:13,代码来源:index.ts

示例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 () => {
    };
  });
开发者ID:ksachdeva,项目名称:rx-pc-ble-driver-js,代码行数:13,代码来源:index.ts

示例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 () => {
    };
  });
开发者ID:ksachdeva,项目名称:rx-pc-ble-driver-js,代码行数:13,代码来源:index.ts

示例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 () => {
    };
  });
开发者ID:ksachdeva,项目名称:rx-pc-ble-driver-js,代码行数:14,代码来源:index.ts


注:本文中的pc-ble-driver-js.Adapter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。