0

I'm a beginner here and I'm attempting this project in which I have to send a message to a device..

I have the specs for the test message (it's all in hexadecimal), but how do I actually code it out so that my java main is sending a hexadecimal message? (since there is no data type for that, I was told to try using bytes[] but it's not working.)

I have already successfully implemented a CommPortDevice communication so I'm sure it is already connected, but the actual message itself, I'm unable to construct it.

For example, I need to send "02 60 01 00 00 84 7A BE 88 00 01 6E 6B" to the device to get a response (it will give out a beeping sound), and I'm not sure how I can construct the message in Java using bytes[]. I've seen resources using xxx * 0xFF or the operators >> and <<, for example, digit1 << 4 | digit2 or something, and I'm not sure what those are.

I would appreciate if someone point me to the right direction. Thank you.

  • 1
    I suspect your device expects binary and the hex is meant to help make that easier for you (the programmer); without knowing anything about the messages (or how your device communicates) it's hard to offer more. – Elliott Frisch Nov 18 '19 at 05:59
  • @ElliottFrisch that makes sense as well! I should send a message in binary and get a response in binary as well.. but the conversion is tough, do you have any resources on how I can convert properly? I'm planning to hard code each hexadecimal value into a String, convert it to binary, then send it. –  Nov 18 '19 at 06:03
  • 1
    Not a good plan. Decode the hex value to a byte[] and send that. [Here](https://stackoverflow.com/a/13991096/2970947). – Elliott Frisch Nov 18 '19 at 06:05
  • @ElliottFrisch thanks ill take a look! edit: decode the hex string into char array? –  Nov 18 '19 at 06:50

0 Answers0