Data loss when sending to native USB port (SerialUSB)

Interesting - I am not losing any data with that script. What happens for me is that echo blocks until ttyACM1 accepts the data. I expect that there is some mysterious stty setting which controls this.

However, it isn't really the right way to use a serial port in a script. The echo command opens the serial port, writes to it, then closes it again each time it executes. That's not what you'd do in, say, a C++ program, where you'd open the serial port once, write to it periodically, and close it at the end of the program. To do this in a shell script you'd use a fifo or a fd, for example:

exec 3<>/dev/ttyACM1
n=0
while true; do

        echo "$n" >&3
        echo $?
        sleep 1
        let "n = $n + 1"
done

This doesn't lose any data for me either, and it buffers the data on the computer rather than blocking.