I'm working on creating a emulator in Java, the emulator is to mimic Captron button which connects to a serial port: /dev/ttyS0, another micro-service is listening to this port and detect any byte array that writes to the port, for example, when the button is pressed, there will be a byte array: [04 20 00 27 02 00 00 00 06 04 01 F9 2E 05] written to the serial port and the micro service will detect the byte array message and interpret it to something meaningful.
In order to mimic the behavior of the button, I was trying to manually echo a byte array to the serial port by: echo "[04 20 00 27 02 00 00 00 06 04 01 F9 2E 05]" >> /dev/ttyS0
But nothing is detected by the micro-service, does anyone know if it is because I can't echo a byte array to a serial port like this? What is the proper way to write a byte array to serial port?