ioctls: TIOCMSET and friends

Robert Golding robert.golding at gmail.com
Thu Jun 23 22:48:52 CST 2005


On 6/24/05, Linden <viktor86 at imap.cc> wrote:
> Hi list,
> 
> I am trying to write a program to interface (via the RS232 port) to a
> circuit that I have built. What I need is for the RTS line to go low
> before sending some data, and then return high once sending is finished.
> 
> This is an edited code segment (ioctl error checking code has been
> removed for brevity) of what I have now:
> 
>   int mcr = 0;
> 
>   ioctl(ttyS, TIOCMGET, &mcr);
>   mcr &= ~TIOCM_RTS;
>   ioctl(ttyS, TIOCMSET, &mcr);
> 
>   write_a_long_string_to_serial_port();
> 
>   ioctl(ttyS, TIOCMGET, &mcr);
>   mcr |= TIOCM_RTS;
>   ioctl(ttyS, TIOCMSET, &mcr);
> 
> The RTS line is high to start with.
> 
> Now here's the problem... If I leave out the code to turn the RTS line
> back on, it goes low and stays low, as I would expect. However, as soon
> as I put that code back in, it appears to never push the line low. I've
> tried using TIOCMBIC and TIOCMBIS but they have the same effect. The two
> operations work fine independently.
> 
> I have a couple of LEDs hooked up to TxD and RTS, to observe what is
> happening. I am sending a large chunk of data, so that there is a
> visible delay between the start and end of data transmission.
> 
> I'm using the following termios:
> 
>   #define BAUD_RATE B2400
> 
>   tios_new.c_cflag = BAUD_RATE | CS8 | CLOCAL | CREAD;
>   tios_new.c_iflag = IGNPAR;
>   tios_new.c_oflag = 0;
>   tios_new.c_lflag = 0;
> 
> I did have CRTSCTS in c_cflag for a while but removing it made no
> difference. I fiddled with the -O options to gcc to make sure it wasn't
> doing some weird optimisation. I have traced through the matching kernel
> source and from what I can gather, changes to the MCR via ioctls should
> be effected immediately.
> 
> The UART is a 16550A, according to the kernel messages. It's on an Intel
> motherboard.
> 
> Any help would be greatly appreciated. :-)
> 
> Cheers,
> Linden
> --
>   Linden May
>   viktor86 at imap.cc
> 
> --
> http://www.fastmail.fm - Does exactly what it says on the tin
> 
> --
> LinuxSA WWW: http://www.linuxsa.org.au/ IRC: #linuxsa on irc.freenode.net
> To unsubscribe or change your options:
>   http://www.netcraft.com.au/mailman/listinfo/linuxsa
> 

Hi Linden,

I'm not a coder by any stretch of the imagination, however, looking at
the sequence, it occured to me you have nothing to tell it to stay low
while 'write_a_long_string_to_serial_port();' is going on.

Perhaps a 'while' // 'end' statement of some sort for the code telling
it to go high again?


-- 
Regards,	Robert

..... Some people can tell what time it is by looking at the sun, but
I have never been able to make out the numbers.
---
Errata: Spelling mistakes are not intentional, except that I don't use
spell checkers.  It's too easy to allow the spell checker to make the
decisions and use words that are out of context for that being written
(i.e. their/there, your/you're, threw/through and even accept/except),
not to mention foreign (I'm Australian) English spelling (i.e.
colour/color, socks/sox, etc).



More information about the linuxsa mailing list