Data written to /dev/ttyHSL1 can later only be read if it is between bracktets i.e. [*data*]. All data outside of the brackets is ignored as if it does not exist

I have a callback function that is called every 50ms to see if there is some data written to the serial port /dev/ttyHSL1.
If this is true then a second function is called to read the data from the serial port and store it into a variable.
For testing purposes I am now writing data to it from the terminal, e.g.:
echo "[12345]" > /dev/ttyHSL1

Whenever I write data to this port that include the brackets (‘[’, ‘]’) everything works correctly

  1. ioctl() indicates there is a number of received bytes > 0 and
  2. when I read from /dev/ttyHSL1 I can access the data

When I do not include the brackets, for example:
echo "1234" > /dev/ttyHSL1
then ioctl() always indicates there is no data coming from the serial port

More things I noticed:

  1. When I write data outside of the brackets it is also not read when I call open()
    echo "1234[5678]" > /dev/ttyHSL1
    open() onyl returns “[5678]”
  2. When the data is read from /dev/ttyHSL1 by calling open() there is also always a carriage return that I did not include myself

Where is this behavior coming from? There is no other logic between calling ioctl() and open().
I don’t understand why ioctl() would return 0 bytes if the data I write to /dev/ttyHSL1 does not contain brackets.

You can try this application