sample code of Serial communication

bridged with qdn.public.qnxrtp.applications
Post Reply
Jin-Woo Lee

sample code of Serial communication

Post by Jin-Woo Lee » Mon Mar 11, 2002 11:45 pm

Hi,

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

Thanks,
JinWoo

David Gibbs

Re: sample code of Serial communication

Post by David Gibbs » Tue Mar 12, 2002 4:43 pm

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.

Jin-Woo Lee

Re: sample code of Serial communication

Post by Jin-Woo Lee » Tue Mar 12, 2002 6:54 pm

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.

Sean Boudreau

Re: sample code of Serial communication

Post by Sean Boudreau » Tue Mar 12, 2002 6:56 pm

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

Kris Warkentin

Re: sample code of Serial communication

Post by Kris Warkentin » Tue Mar 12, 2002 7:18 pm

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/neutrin ... r8250.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.

Jin-Woo Lee

Re: sample code of Serial communication

Post by Jin-Woo Lee » Thu Mar 14, 2002 3:43 pm

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

Post Reply

Return to “qdn.public.qnxrtp.applications”