First of all, I donβt know why you first set all termios fields to 0, and then later, without any changes to this 0, which precedes it, decide to set the usual rs232 flags to cflag. (instead of doing it without a direct OR, where you now set it to 0).
what you might like is - instead of setting all these flags - only the cfmakeraw () field of the termios field.
also sync (); without any parameters (NOT fsync !;), it seems to send all the pending output to ALL filedescriptors, not just block devices. also tcp sockets and rs232 ..
and also open () has the O_SYNC option (O_SYNC and O_ASYNC confuse the names, but have nothing to do with the synchronized serial line protocol, it immediately writes (), and the other generates a signal to capture when the input becomes available (sort of like irq based rs232 on dos;)
setting O_SYNC in open () may already solve your problem.
also "reading data at the other end" ... there are things called "LEDs" and "resistors" that you can simply connect to TXD and view the data;) there are also things called "rs232 breakthrough" field "or area visibility, which can make it visible - directly) - is much easier than "guessing" which side is not behaving correctly.
WARNING: NOT A TEST CODE. it compiles. but I have all my ttyUSB0 cables in another building. but I think your main problem is O_SYNC anyway. setting all termios crap to 0 is pretty much like cfmakeraw () ... also why install CREAD if you open it for writing only? (why open it only for writing, and not read in any case?), as well as writing only, you will not need to be afraid that he will become the manager of tty (O_NOCTTY;), so if you write, this is not required ..
just noticed that% i (same for% dbtw) formatter also triggers a ssize_t type mismatch warning return value write (), so it is different from (int)
#include<termios.h> #include<stdio.h> #include<unistd.h> #include<fcntl.h> void main(){ int fd; struct termios tty; fd=-1; while(fd<0){fd=open("/dev/ttyUSB0",O_WRONLY|O_NONBLOCK|O_NOCTTY|O_SYNC);sleep(1);}; cfmakeraw(&tty); tty.c_cflag=CREAD|CRTSCTS|HUPCL|CS8; cfsetospeed(&tty,B19200); cfsetispeed(&tty,B19200); tcsetattr(fd,TCSANOW,&tty); printf("Write: %i\n",(int)write(fd,"HELLO",5)); sync();//if all else fails, also try without, O_SYNC should already fix that. close(fd); };