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
Wrong cast if received Byte is bigger than 127 #10
Comments
On the SPPSerive file, find ConnectedThread class and replace Run function by this: public void run() {
One more thing, You should check the UUID_SP, I am not sure I have edited it before, Btw now it look like this: |
Hello @Samyssmile
With this : and it will always give 63 if we receive byte 128 to 255. Any suggestion to solve the problem? |
@bayudwirp Have your tried using |
Hi @MacroYau , Have you any other suggestion to solve this problem? |
@bayudwirp Would you mind showing your actual code implementation? |
Of course @MacroYau .
And this script below is ActivityMain.xml
Any suggestion from you, will be appreciated. |
@bayudwirp My suggestions:
for (byte b : bytes)
System.out.println("Read: " + (int) b & 0xFF); |
Thank you very much for your suggestion @MacroYau , very appreciate for you to helping me.
the results remain as before, issued a byte value of 63 when it receives 128-255. I didn't know, how could this happen again. |
@bayudwirp Your problem looks like #9 which should have already fixed... Can you try to log the incoming bit patterns as well? |
@bayudwirp How about the sending side? Is it really transmitting 128 to 255? |
@MacroYau I didn't try about sending side. But, if i try to sending character from your example apps (Blue2Serial), such as sending characters "name" (below byte 127, if we convert every characters to ASCII) there is no problem, but if i try to send specials character (above byte 127), it always receive not only the character that i was send, but also receive another random character. |
Hi @MacroYau I've tried again about your suggestion to using
and, i tried to restore a default SPPService.java (maybe i made mistake to change something on this file) Thankyou very much, for helping me. Have a good day for you :) |
Great to hear that! :) |
Hello Guys, great work you done.
We had for last Days some trouble with this API. Its exactly Issue#9. You wrote that you fixed it but it was not fixed.
Problem: If our App recieve byte 128 (hax 80), this lib read it as -128 and wrong hex.
We all know this happen because of signed Bytes in Java.
Workaround: SPPService.java
Replace this:
mHandler.obtainMessage(BluetoothSerial.MESSAGE_READ, bytes, -1, read.getBytes()).sendToTarget();
with this
mHandler.obtainMessage(BluetoothSerial.MESSAGE_READ, bytes, -1, read.getBytes(StandardCharsets.US_ASCII)).sendToTarget();
If you do this changes, issue like #9 never happen again. In most of usecases with SPP we think US_ASCII as default is much better....
Great work keep on.
The text was updated successfully, but these errors were encountered: