sample code of Serial communication

Hi,

I’m a new user of QNX.
If you get me a sample code of Serial communication, I’ll appreciate it.

Thanks,
JinWoo

Jin-Woo Lee <jl206@cornell.edu> wrote:

Hi,

I’m a new user of QNX.
If you get me a sample code of Serial communication, I’ll appreciate it.

How complex do you need?

At the simplest:

fd = open( “/dev/ser1”, O_RDWR );
bytes = read(fd, buf, sizeof(buf));
bytes = write(fd, buf, sizeof(buf));

Is serial communication – receive & send some bytes over a serial port.

For more detail, you get into functions like tcflow(), tcsetattr(),
tcgetattr(), fcntl(), etc.

The Terminal I/O section in Advanced Programming in the Unix Environment
by W. Richard Stevens gives a good coverage of these issues (and is a
generally good book). ISBN 0-201-56317-7

-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.

Thanks,
Is it possible to make the receiver parts as a interrupt driven way?
(meaning is that the receiver thread wakes up only when the data come into
the serial port)

Would you recommend me which functions I should use for that?

Thanks again,
JinWoo



“David Gibbs” <dagibbs@qnx.com> wrote in message
news:a6lb7q$8p9$2@nntp.qnx.com

Jin-Woo Lee <> jl206@cornell.edu> > wrote:
Hi,

I’m a new user of QNX.
If you get me a sample code of Serial communication, I’ll appreciate it.

How complex do you need?

At the simplest:

fd = open( “/dev/ser1”, O_RDWR );
bytes = read(fd, buf, sizeof(buf));
bytes = write(fd, buf, sizeof(buf));

Is serial communication – receive & send some bytes over a serial port.

For more detail, you get into functions like tcflow(), tcsetattr(),
tcgetattr(), fcntl(), etc.

The Terminal I/O section in Advanced Programming in the Unix Environment
by W. Richard Stevens gives a good coverage of these issues (and is a
generally good book). ISBN 0-201-56317-7

-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.

You can use select() or ionotify().

-seanb

Jin-Woo Lee <jl206@cornell.edu> wrote:
: Thanks,
: Is it possible to make the receiver parts as a interrupt driven way?
: (meaning is that the receiver thread wakes up only when the data come into
: the serial port)

: Would you recommend me which functions I should use for that?

: Thanks again,
: JinWoo

The read call can be made blocking or non-blocking as you like. If you have
a thread that is dedicated to reading the serial port, all it has to do is
just call read and it will sleep until some data comes available. The
problem with this method, is that you will be returning from the read EVERY
TIME there is some data available which can make for a very busy thread.
There are some fairly good ways of dealing with this though. If you look at
the documentation for devc-ser8250 (standard pc serial port) at
http://qdn.qnx.com/support/docs/neutrino/utilities/d/devc-ser8250.html,
you’ll see that you can control the size of the input buffer and how often
you want an interrupt to occur if characters are available for reading.
Very powerful yes?

cheers,

Kris


“Jin-Woo Lee” <jl206@cornell.edu> wrote in message
news:a6lif0$otq$1@inn.qnx.com

Thanks,
Is it possible to make the receiver parts as a interrupt driven way?
(meaning is that the receiver thread wakes up only when the data come into
the serial port)

Would you recommend me which functions I should use for that?

Thanks again,
JinWoo



“David Gibbs” <> dagibbs@qnx.com> > wrote in message
news:a6lb7q$8p9$> 2@nntp.qnx.com> …
Jin-Woo Lee <> jl206@cornell.edu> > wrote:
Hi,

I’m a new user of QNX.
If you get me a sample code of Serial communication, I’ll appreciate
it.

How complex do you need?

At the simplest:

fd = open( “/dev/ser1”, O_RDWR );
bytes = read(fd, buf, sizeof(buf));
bytes = write(fd, buf, sizeof(buf));

Is serial communication – receive & send some bytes over a serial port.

For more detail, you get into functions like tcflow(), tcsetattr(),
tcgetattr(), fcntl(), etc.

The Terminal I/O section in Advanced Programming in the Unix
Environment

by W. Richard Stevens gives a good coverage of these issues (and is a
generally good book). ISBN 0-201-56317-7

-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.

ok. select() is working!!!
Thanks,


“Sean Boudreau” <seanb@qnx.com> wrote in message
news:a6lj02$fnf$1@nntp.qnx.com

You can use select() or ionotify().

-seanb

Jin-Woo Lee <> jl206@cornell.edu> > wrote:
: Thanks,
: Is it possible to make the receiver parts as a interrupt driven way?
: (meaning is that the receiver thread wakes up only when the data come
into
: the serial port)

: Would you recommend me which functions I should use for that?

: Thanks again,
: JinWoo