Serial port determinism
        Posted  
        
            by Matt Green
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Matt Green
        
        
        
        Published on 2010-03-18T16:14:11Z
        Indexed on 
            2010/03/18
            16:31 UTC
        
        
        Read the original article
        Hit count: 438
        
serial-port
|linux
This seems like a simple question, but it is difficult to search for. I need to interface with a device over the serial port. In the event my program (or another) does not finish writing a command to the device, how do I ensure the next run of the program can successfully send a command?
Example:
- The 
fooprogram runs and begins writing "A_VERY_LONG_COMMAND" - The user terminates the program, but the program has only written, "A_VERY"
 - The user runs the program again, and the command is resent. Except, the device sees "A_VERYA_VERY_LONG_COMMAND," which isn't what we want.
 
Is there any way to make this more deterministic? Serial port programming feels very out-of-control due to issues like this.
© Stack Overflow or respective owner