I need to get the bytes of the control character STX (02h) to append to a stream I need to send to a controller board.
How do I get the bytes of the STX control character in Java?
I need to get the bytes of the control character STX (02h) to append to a stream I need to send to a controller board.
How do I get the bytes of the STX control character in Java?
The bytes of the control character depend on the encoding the controller board uses. For ASCII:
"\u0002".getBytes(StandardCharsets.US_ASCII);
Note that if you are writing characters to an output stream, you should wrap it with a Writer which is configured with the correct encoding:
OutputStream controllerOutputStream;
Charset controllerCharset = StandardCharsets.US_ASCII; // probably ASCII
Writer controllerWriter = new OutputStreamWriter(controllerOutputStream, controllerCharset);
controllerWriter.append('\u0002'); // append a single character