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

von4xj4u  于 2024-01-04  发布在  Ionic
关注(0)|答案(1)|浏览(303)

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

cgvd09ve

cgvd09ve1#

  1. import { BluetoothLe } from '@capacitor-community/bluetooth-le';
  2. async connectToBluetoothDevice() {
  3. debugger
  4. try {
  5. await BluetoothLe.initialize();
  6. const isEnabled = await BluetoothLe.isEnabled();
  7. if (!isEnabled) {
  8. console.log('Bluetooth is not enabled.');
  9. return;
  10. }
  11. const devices = await BluetoothLe.requestDevice({});
  12. console.log('devices=>',devices)
  13. const printerDeviceId = devices.deviceId;
  14. const bluetoothDeviceId = 'your_bluetooth_device_id';
  15. const data = new Uint8Array([0x48, 0x65, 0x6C, 0x6C, 0x6F]);
  16. const text = 'Hello';
  17. const encoder = new TextEncoder();
  18. const uintArray4 = encoder.encode(text);
  19. this.sendDataViaBluetooth(devices.deviceId,uintArray4)
  20. } catch (error) {
  21. console.error('Error connecting to Bluetooth device:', error);
  22. }
  23. }
  24. async sendDataViaBluetooth(deviceId: string, dataToSend: any) {
  25. debugger
  26. try {
  27. let sendData;
  28. sendData = new DataView(dataToSend.buffer);
  29. console.log('Data sent successfully via Bluetooth.');
  30. } catch (error) {
  31. console.error('Error sending data via Bluetooth:', error);
  32. }
  33. }

字符串

展开查看全部

相关问题