Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to send Hex Values via Bluetooth #71

Open
vladinko0 opened this issue Feb 16, 2018 · 4 comments
Open

How to send Hex Values via Bluetooth #71

vladinko0 opened this issue Feb 16, 2018 · 4 comments

Comments

@vladinko0
Copy link

In the BluetoothSerialExample I see:

 write (message) {
    BluetoothSerial.write(message)
    .then((res) => {
      Toast.showShortBottom('Successfuly wrote to device')
      this.setState({ connected: true })
    })
    .catch((err) => Toast.showShortBottom(err.message))
  }

But I need to send the Enquiry ENQ (0x05). And if I store into the "message" value 0x05, slave device gives me no response, because it probably wants hex value 0x05, not string value.

In the ..\react-native-bluetooth-serial-master\index.js I see:

BluetoothSerial.write = (data) => {
  if (typeof data === 'string') {
    data = new Buffer(data)
  }
  return BluetoothSerial.writeToDevice(data.toString('base64'))
}  

Should I replace data.toString('base64') with data('base64') to pass hex value, or should I in ..\node_modules\react-native-bluetooth-serial\android\src\main\java\com\rusel\RCTBluetoothSerial\RCTBluetoothSerialModule.java:

 public void writeToDevice(String message, Promise promise) {
        if (D) Log.d(TAG, "Write " + message);
        byte[] data = Base64.decode(message, Base64.DEFAULT);
        mBluetoothService.write(data);
        promise.resolve(true);
    }

replace String message with Int message in order to send hex value 0x05?

Please help me. I feel so lost.

@mahdieh-dev
Copy link

I also need to pass hex value with this package. Can anyone help please?

@PiotrDabek
Copy link

Have you managed to solve this problem? I'm facing similar one right now. Any help would be appreciated

@JackTam1993
Copy link

Here is my solution:

let buf = new Buffer("AA22EC00000000000102AA5500023C4E000001007000000000002300000000000000D0", "hex");
BluetoothSerial.write(buf)

Hope that still helpful.

@chamaloriz
Copy link

I found how to :p spent 2 Days

basically the array wasn't showing as a uint8array but as a typedArray
Buffer.from() fixed it

let encoder = new EscPosEncoder();

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

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants