Home > Net >  Is it possible to programatically hold the serial port Tx line high or low in C?
Is it possible to programatically hold the serial port Tx line high or low in C?

Time:04-27

This is the relevant part of my C program (in Linux):

while (input != ' '){
 write(serial_port, msg, sizeof(msg));
 //1. here I would like to wait at least 100 us with the Tx line high
 //2. followed by at least 8us with the Tx line low
 //3. and then repeat the message
 input = mygetch();
}

As you can see, after each send of msg through the serial port, I would like to set the Tx line high for 100 microseconds and then low for 8 microseconds and then repeat the message until the user presses the space-bar.

Do I have this kind of control on the serial port using C in Linux?

TIA for your help.

CodePudding user response:

Yes. The default state of a serial line when not sending any data is "mark" (high, for a single-ended line). To send a space (low), set the break bit. Clear the break bit to restore the idle state.

  • Related