react-native-bluetooth-serial icon indicating copy to clipboard operation
react-native-bluetooth-serial copied to clipboard

Write Method on this component

Open ghost opened this issue 7 years ago • 2 comments

hi i wanted to know how to run a write method on this component? how to send blue tooth data to thermal printer?

thank you in advance

ghost avatar Jan 11 '18 16:01 ghost

To write data to any component you can use the method write(), like:

// ...
import BluetoothSerial from "react-native-bluetooth-serial";

const MySerial = new BluetoothSerial();

// Then, you need to connect to the desired device, through the id.

MySerial.connect("XX:XX:XX:XX") // MAC address

MySerial.write("My message")

Don't forget to connect to the device before trying to send any message. Hope it helps.

reisdev avatar Dec 18 '18 12:12 reisdev

let encoder = new EscPosEncoder();

let result = encoder
  .initialize()
  .text("HelloWorld")
  .newline()
  .qrcode('HelloWorld')
  .encode();

const { Buffer } = require('buffer');

BluetoothSerial.write(Buffer.from(result.buffer))

chamaloriz avatar Sep 29 '19 10:09 chamaloriz