Skip to contentSkip to conversation

Help:Serial / Parallel Port Control Under Linux

DISCUSSION johnny 3 participants 6 messages Oct 3, 2008 – Oct 8, 2008 TTY layer and serial drivers

lore
Share & tools
lore

johnny

author
#0 lore raw

Hi,

Right Now I need to write a simple C code to control the serial / parallel port under linux working like this:
Detect there is an input signal / voltage change and send some output signal / voltage accordingly, eg: if DSR is detected to be high, I want to set RTS to be high as well; if RI is detected to be high, I want DTR set to be low etc.

I have read the Serial-How to and Serial programming-How to, however I am still not so clear regarding to this simple programming.

Could anyone direct me some useful references / codes regarding to this project?

Thanks & Best Regards,

Johnny Xing

--
To unsubscribe from this list: send the line "unsubscribe linux-serial" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#1 lore raw
Quoted 10 lines · johnny

Right Now I need to write a simple C code to control the serial / parallel port under linux working like this: Detect there is an input signal / voltage change and send some output signal / voltage accordingly, eg: if DSR is detected to be high, I want to set RTS to be high as well; if RI is detected to be high, I want DTR set to be low etc.

I have read the Serial-How to and Serial programming-How to, however I am still not so clear regarding to this simple programming.

Ignore the serial programming howto. It's out-of-date, incomplete, unmaintained and just plain wrong in many areas. I needs to be gotten rid of, but that doesn't seem to be possible.

A far better source of information is the Serial Programming Guide for Posix Operating Systems:

http://www.easysw.com/~mike/serial/serial.html

Specifically, the information about modem control and status lines is in chapter 5.1:

http://www.easysw.com/~mike/serial/serial.html#5_1

Signature · 3 lines
Grant Edwards                   grante             Yow! Inside, I'm already
                                  at               SOBBING!
                               visi.com            
author
#2 lore raw

Hi, Grant,

I have written a simple program based on the POXIS programming guide, however, it seems that ioctl() function doesn't have a command of 'TIOCMGET'and 'TIOCMSET'.

I am currently using Centos system.

Do you know any other function which could control the serial port pin status?

Error:

serialIO.c:195: error: `TIOCMGET' undeclared (first use in this function) serialIO.c:195: error: (Each undeclared identifier is reported only once serialIO.c:195: error: for each function it appears in.) serialIO.c:207: error: TIOCM_CD' undeclared (first use in this function) serialIO.c:208: error: TIOCM_CTS' undeclared (first use in this function) serialIO.c:209: error: TIOCM_DSR' undeclared (first use in this function) serialIO.c:210: error: TIOCM_RI' undeclared (first use in this function) serialIO.c:212: error: TIOCM_DTR' undeclared (first use in this function) serialIO.c:215: error: TIOCM_RTS' undeclared (first use in this function) serialIO.c:223: error: `TIOCMSET' undeclared (first use in this function)

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Grant Edwards
Sent: 2008年10月3日 22:27
To: [email protected]
Subject: Re: Help:Serial / Parallel Port Control Under Linux

Quoted 10 lines · johnny

Right Now I need to write a simple C code to control the serial / parallel port under linux working like this: Detect there is an input signal / voltage change and send some output signal / voltage accordingly, eg: if DSR is detected to be high, I want to set RTS to be high as well; if RI is detected to be high, I want DTR set to be low etc.

I have read the Serial-How to and Serial programming-How to, however I am still not so clear regarding to this simple programming.

Ignore the serial programming howto. It's out-of-date, incomplete, unmaintained and just plain wrong in many areas. I needs to be gotten rid of, but that doesn't seem to be possible.

A far better source of information is the Serial Programming Guide for Posix Operating Systems:

http://www.easysw.com/~mike/serial/serial.html

Specifically, the information about modem control and status lines is in chapter 5.1:

http://www.easysw.com/~mike/serial/serial.html#5_1

Signature · 8 lines
Grant Edwards                   grante             Yow! Inside, I'm already
                                  at               SOBBING!
                               visi.com            

--
To unsubscribe from this list: send the line "unsubscribe linux-serial" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#3 lore raw
Quoted 1 line · johnny

serialIO.c:195: error: `TIOCMGET' undeclared (first use in this function)

Did you include termios.h? (See man ioctl_list)

Regards,
Andy

author
#4 lore raw

I realized that I need to #include iotcl.h as well in order to use TIOCMGET constant.

If I want to run this small program continuously and detect the changes of the input pins all the time, can I simply use an infinite loop to do that? Does it anything wrong to the serial port?

Thanks & Best Regards,

Johnny Xing
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Andreas Stricker
Sent: 2008年10月6日 17:13
To: [email protected]
Subject: Re: Help:Serial / Parallel Port Control Under Linux

Quoted 1 line · johnny

serialIO.c:195: error: `TIOCMGET' undeclared (first use in this function)

Did you include termios.h? (See man ioctl_list)

Regards,
Andy
--
To unsubscribe from this list: send the line "unsubscribe linux-serial" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#5 lore raw
Quoted 3 lines · johnny

If I want to run this small program continuously and detect the changes of the input pins all the time, can I simply use an infinite loop to do that?

Yes. Though you may want to sleep a little between polls to allow other things to run. Unfortunately, there are no "block until modem status change" semantics in the Unix tty driver (one of a number of useful things that the Unix tty driver is missing).

Quoted 1 line

Does it anything wrong to the serial port?

No.

Signature · 1 line
Grant