I don't see anything that looks out of sorts with your code, and it is remarkably similar to my test code. Is there a consistency to the size of the bytes written per write? What about the nature of the data? Are there end-of-lines embedded in the data? If so, I guess I would try setting the serial port to raw mode:
struct termios serialPortCfg;
tcgetattr(fd, &serialPortCfg );
serialPortCfg.c_oflag &= ~OPOST;
tcsetattr( fd, TCSANOW, &serialPortCfg );
I'm not completely sure about how cooked output deals with CRs & LFs or NULLs. A reasonable speculation might be that NULLs could cause the output stream to be broken into blocks, but that shouldn't be the case here, as it looks like your data is one long string. Can you confirm that the buffer length value actually being requested to write()
is greater than the value returned as writtenBytes
Sorry for the sketchy reply; I'm at a loss for better suggestions.