-1

I need to know how to convert this function so that I can send hex or decimal, so that STM receives it as a frame. Ready bt terminal from the android store after sending the hex number does it correct and the plate responds, but I would like to do it in my application.

 private void sendData(String message) {
    byte[] msgBuffer = message.getBytes();
    try {
        outStream.write(msgBuffer);
        System.out.println(msgBuffer);

    } catch (IOException e) {
        String msg = "Nie udało się wysłać danych" + e.getMessage();
        errorExit("Fatal Error", msg);
    }

}

After printing those bytes in the console, it gets something like the following string, so probably why it doesn't work if it converts it to bytes?

[B@a560d15
Mike 'Pomax' Kamermans
  • 49,297
  • 16
  • 112
  • 153
Programmer
  • 41
  • 5
  • What does "I need it in the morning" have to do with your question or who should answer or when? Your need does not make your question more important than anyone else's on this site. – Hovercraft Full Of Eels Feb 21 '20 at 00:16
  • Your inability to manage time is not our responsibility. Stackoverflow is here for you _and everyone in the future with the same problem_. If you don't want to help those folks out, then SO is not where you should be asking this. So, with that said: welcome to Stackoverflow (as a poster), remember to read up on the [on-topic](/help/on-topic) policy, and make _absolutely sure_ you've read [how to ask a good question](/help/how-to-ask). As a poster on SO you have some responsibilities that you didn't have before as a casual visitor of the site. – Mike 'Pomax' Kamermans Feb 21 '20 at 00:17
  • so with this time it's my fault, but I'm only human. I didn't mean anything bad or something like "more important question" by writing about it in the morning, I just wanted to mention it – Programmer Feb 21 '20 at 00:36
  • Lesson learned. The statement implied that you're in a hurry to get an answer, that folks who answer questions should drop what they're doing and answer your question first. This is not a good thing to do on a volunteer-staffed site. – Hovercraft Full Of Eels Feb 21 '20 at 00:41
  • Now I see that... – Programmer Feb 21 '20 at 00:45
  • `[B@a560d15` That looks like a java identifier for your byte array. If you want to print or log the content of your byte array you have to do it different. But if it was a string you better print the original string. – blackapps Feb 21 '20 at 08:59
  • Further you should first show what you have as integer or in hex. – blackapps Feb 21 '20 at 09:02

1 Answers1

-1

Would you like to try:

 System.out.println(Arrays.toString(msgBuffer));

Arrays are also Object.
The array does not override toString (), so the output is:

public String toString() {
        return getClass().getName() + "@" + Integer.toHexString(hashCode());
}
yeahseol
  • 377
  • 1
  • 6
  • Isn't my answer enough? – yeahseol Feb 21 '20 at 00:23
  • System.out.println(Arrays.toString(msgBuffer)); it changed 2 to 50, I don't know very well java, so what system did it write to? Unfortunately, I do not fully understand what you wrote – Programmer Feb 21 '20 at 00:37