react-native-bluetooth-serial
react-native-bluetooth-serial copied to clipboard
Write Method on this component
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
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.
let encoder = new EscPosEncoder();
let result = encoder
.initialize()
.text("HelloWorld")
.newline()
.qrcode('HelloWorld')
.encode();
const { Buffer } = require('buffer');
BluetoothSerial.write(Buffer.from(result.buffer))