Skip to contentSkip to conversation

Serial Port (RS-232)

DISCUSSION Jaime Garcia 5 participants 10 messages Jan 27, 2009 – Jan 29, 2009

lore
Share & tools
lore
#0 lore raw

Hi Friends,
I am pretty new to Linux programming, I want to start doing something useful, so I was thinking to start programming the serial port (RS-232) of my box, so I can read and write data from it, can someone of you give some feedback about how to start this? I will appreciate so much all your help!

Best regards,
J.G.

#1 lore raw

hi

use following link
http://www.easysw.com/~mike/serial/serial.html

Quoted 15 lines · Jaime Garcia

Hi Friends,
I am pretty new to Linux programming, I want to start doing something useful, so I was thinking to start programming the serial port (RS-232) of my box, so I can read and write data from it, can someone of you give some feedback about how to start this? I will appreciate so much all your help!

Best regards,
J.G.

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

#3 lore raw
In reply to Jaime Garcia
Quoted 7 lines

Hi Friends,
I am pretty new to Linux programming, I want to start doing something
useful, so I was thinking to start programming the serial port (RS-232) of
my box, so I can read and write data from it, can someone of you give some

A good start is reading Michael R. Sweet's guide [1] on Serial Programming for POSIX Operating Systems

[1] http://www.easysw.com/~mike/serial/serial.html

For a complete reference, I use The Linux Documentation Project (TLDP) section about Serial [2]

[2] http://tldp.org/HOWTO/Serial-HOWTO.html

--
Tiago Maluta

#2 lore raw
In reply to Jai Sharma

Thank you Jai, I think I will start from here!

Regards!

Quoted 41 lines

-----Mensaje original-----
De: [email protected] [mailto:linux-c- [email protected]] En nombre de Jai Sharma Enviado el: Martes, 27 de Enero de 2009 10:20 a.m.
Para: Jaime Garcia
CC: [email protected]
Asunto: Re: Serial Port (RS-232)

hi

use following link
http://www.easysw.com/~mike/serial/serial.html

Quoted 3 lines · Jaime Garcia

Hi Friends,
I am pretty new to Linux programming, I want to start doing something useful, so I was thinking to start programming the serial port (RS-

232) of

Quoted 1 line

my box, so I can read and write data from it, can someone of you give

some

Quoted 1 line

feedback about how to start this? I will appreciate so much all your

help!

Quoted 7 lines

Best regards,
J.G.

--
To unsubscribe from this list: send the line "unsubscribe linux-c-

programming" in

Quoted 3 lines

the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

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

#4 lore raw
In reply to Jaime Garcia
Quoted 5 lines · Jaime Garcia

Hi Friends,
I am pretty new to Linux programming, I want to start doing something useful, so I was thinking to start programming the serial port (RS-232) of my box, so I can read and write data from it, can someone of you give some feedback about how to start this?

The keyword you are looking for is ``ioctl''.

Signature · 1 line
 Michael Iatrou
#5 lore raw

Hello Michael,
Right now I opened man ioctl(2) to start looking for directions on this, I appreciate so much your tip, thanks a lot! =-)

Best regards!

Quoted 27 lines

-----Mensaje original-----
De: [email protected] [mailto:linux-c- [email protected]] En nombre de Michael Iatrou Enviado el: Martes, 27 de Enero de 2009 11:14 a.m.
Para: [email protected]
CC: Jaime Garcia
Asunto: Re: Serial Port (RS-232)

Quoted 3 lines · Jaime Garcia

Hi Friends,
I am pretty new to Linux programming, I want to start doing something useful, so I was thinking to start programming the serial port (RS-

232)

Quoted 1 line

of my box, so I can read and write data from it, can someone of you

give

Quoted 1 line

some feedback about how to start this?

The keyword you are looking for is ``ioctl''.

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

#6 lore raw
Quoted 9 lines · Jaime Garcia
Quoted 6 lines
Quoted 4 lines

I am pretty new to Linux programming, I want to start doing something useful, so I was thinking to start programming the serial port (RS-232) of my box, so I can read and write data from it, can someone of you give some feedback about how to start this?

The keyword you are looking for is ``ioctl''.

Right now I opened man ioctl(2) to start looking for directions on this, I appreciate so much your tip, thanks a lot! =-)

You probably don't need to use ioctl() unless you need to treat the serial port as a general-purpose I/O port (e.g. manually setting the control lines).

If you just want to talk to another serial device, open()ing one of the /dev/ttyS* devices and using tcsetattr/tcgetattr will normally suffice.

If you do need to use ioctl(), the ioctl(2) manpage won't help much, as ioctl() is a generic interface to device-specific functionality. The tty_ioctl(4) manpage has details related to TTY (serial) ioctl() commands.

Signature · 1 line
Glynn Clements <[email protected]>
#7 lore raw

Hi Glynn,
What I want to do is to read from another device that transmit a string of chars through serial connector, what do you recommend? I would like to know your approach for this. Thank you in advance for your help.

Best Regards!

Quoted 38 lines

-----Mensaje original-----
De: Glynn Clements [mailto:[email protected]] Enviado el: Martes, 27 de Enero de 2009 06:57 p.m.
Para: Jaime Garcia
CC: [email protected]
Asunto: RE: Serial Port (RS-232)

Quoted 1 line · Jaime Garcia
Quoted 1 line
Quoted 1 line

I am pretty new to Linux programming, I want to start doing

something

Quoted 1 line
Quoted 1 line
Quoted 1 line

useful, so I was thinking to start programming the serial port

(RS-232)

Quoted 1 line
Quoted 1 line
Quoted 1 line

of my box, so I can read and write data from it, can someone of

you give

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

some feedback about how to start this?

The keyword you are looking for is ``ioctl''.

Right now I opened man ioctl(2) to start looking for directions on this, I appreciate so much your tip, thanks a lot! =-)

You probably don't need to use ioctl() unless you need to treat the serial port as a general-purpose I/O port (e.g. manually setting the control lines).

If you just want to talk to another serial device, open()ing one of the /dev/ttyS* devices and using tcsetattr/tcgetattr will normally suffice.

If you do need to use ioctl(), the ioctl(2) manpage won't help much, as ioctl() is a generic interface to device-specific functionality. The tty_ioctl(4) manpage has details related to TTY (serial) ioctl() commands.

--
Glynn Clements <[email protected]>

#8 lore raw
Quoted 3 lines · Jaime Garcia

What I want to do is to read from another device that transmit a string of chars through serial connector, what do you recommend? I would like to know your approach for this. Thank you in advance for your help.

First, open() the device.

Then configure the line settings with e.g.:

	struct termios t;
	tcgetattr(fd, &t);
	t.c_lflag &= ~ICANON;
	tcsetattr(fd, TCSANOW, &t);

The ICANON flag controls the use of "canonical mode" (line buffering, processing of control codes, etc). For a device other than a terminal, you would normally disable this flag. Exactly how the line is configured depends upon the device; see the termios(3) manpage for a list of settings.

Finally, just read() data.

Signature · 1 line
Glynn Clements <[email protected]>
#9 lore raw

I'll give a try to this, thank you so much for the reply Glynn!

Regards!

Quoted 33 lines
Quoted 1 line · Jaime Garcia

What I want to do is to read from another device that transmit a

string of

Quoted 1 line

chars through serial connector, what do you recommend? I would like

to know

Quoted 1 line

your approach for this. Thank you in advance for your help.

First, open() the device.

Then configure the line settings with e.g.:

	struct termios t;
	tcgetattr(fd, &t);
	t.c_lflag &= ~ICANON;
	tcsetattr(fd, TCSANOW, &t);

The ICANON flag controls the use of "canonical mode" (line buffering, processing of control codes, etc). For a device other than a terminal, you would normally disable this flag. Exactly how the line is configured depends upon the device; see the termios(3) manpage for a list of settings.

Finally, just read() data.

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