I do not think that you can output TTL using the actual serial port, since these are RS-232 and not TTL logic levels. If you use a serial port, you will need a converter, for example. If you are using the FTDI driver / USB cable, which already outputs TTL logic levels, and the code looks good to me, which means that the error is probably at the end of the device.
source share