简体   繁体   中英

write() with ttyS is non block

My question is this - how can you make a call write() in uCLinux 2.6.21 synchronous, ie that the call is not completed before the end of the send? Now I have the following code:

//...
fd = open (PORT, O_RDWR | O_SYNC)
//...

FIO3CLR |= 0x30000000; // RTS = 0 (enable transfer)
write (fd, "A", 1) // pass
FIO3SET |= 0x30000000; // RTS = 1 (disable transfer)

command FIO3SET |= 0x30000000; starts executed almost immediately after calling the write() , for the task it is undesirable. Thanks.

My guess is that you should be setting TTY attributes and that Linux kernel will do the RTS/CTS handling for if you set the attributes. For complete example see http://www.tldp.org/HOWTO/Serial-Programming-HOWTO/x115.html . I would guess that the part that answers your question is this:

newtio.c_cflag = BAUDRATE | CRTSCTS | CS8 | CLOCAL | CREAD; // CRTSCTS is set here
//...
tcsetattr(fd,TCSANOW,&newtio);

tcdrain() waits until all output written to the object referred to by fd has been transmitted. it solved my problem C read call blocking on serial port operation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM