Ionic 在离子电容器Android SDK 33中使用@capacitor-community/bluetooth-le的tharmal打印机打印

von4xj4u  于 10个月前  发布在  Ionic
关注(0)|答案(1)|浏览(234)

tharmal打印机打印使用@capacitor-community/bluetooth-le
使用此插件如何连接tharmal打印机在离子capacito为android adk 33
我尝试tharmal打印机打印使用电容器蓝牙能够连接,但也发送数据到连接的蓝牙tharmal打印机设备,但它无法打印。

cgvd09ve

cgvd09ve1#

import { BluetoothLe } from '@capacitor-community/bluetooth-le';
 async  connectToBluetoothDevice() {
    debugger
    try {
     
      await BluetoothLe.initialize();
      const isEnabled = await BluetoothLe.isEnabled();
      if (!isEnabled) {
      console.log('Bluetooth is not enabled.');
        return;
      }
      
      const devices = await BluetoothLe.requestDevice({});
      console.log('devices=>',devices)
      const printerDeviceId = devices.deviceId; 
      const bluetoothDeviceId = 'your_bluetooth_device_id'; 
      const data = new Uint8Array([0x48, 0x65, 0x6C, 0x6C, 0x6F]);
      const text = 'Hello';
      const encoder = new TextEncoder();
      const uintArray4 = encoder.encode(text);
      this.sendDataViaBluetooth(devices.deviceId,uintArray4)
      

    } catch (error) {
      console.error('Error connecting to Bluetooth device:', error);
    }
  }
  async  sendDataViaBluetooth(deviceId: string, dataToSend: any) {
    debugger
    try {
      let sendData;
      sendData = new DataView(dataToSend.buffer);
      console.log('Data sent successfully via Bluetooth.');
    } catch (error) {
      console.error('Error sending data via Bluetooth:', error);
    }
  }

字符串

相关问题