[NTLUG:Discuss] serial communications

Paul Ingendorf pauldy at wantek.net
Tue Nov 9 08:44:46 CST 2004


It can be made non blocking in java by spawning a send thread and receive
thread and creating the appropriate event listener to handle an event thrown
by the receive thread to handle incoming data. You can get javax.comm from
java.sun.com it has an example of a simpleReader/Writer in it.  With that
you can eliminate the need for the c code and I'm sure by eliminating the
need to multiple disciplines in what your doing it will be a little easier
to get to where you want with it.

-----Original Message-----
From: discuss-bounces at ntlug.org [mailto:discuss-bounces at ntlug.org]On
Behalf Of Stephen Davidson
Sent: Monday, November 08, 2004 9:16 PM
To: NTLUG Discussion List
Subject: Re: [NTLUG:Discuss] serial communications


Hi.

This Java Guy is not going to be much help with the non-blocking stuff.
Usually (at least in Java Land), there is a method to call _before_
doing the read to see if any bytes are available for reading.  The stuff
I wrote was multi-threaded and blocking, which meant a "listener" therad
was spun off to do the listening, and would "wake-up" whenever data was
received.  In the case of the devices in question, one always knew when
a message was coming in.

 From the sounds of it, somebody may have implemented the Java
SerialComm package, or something simliar?  For using non-blocking IO,
your code may do the trick.

Regards,
Steve

james osburn wrote:

> an how would a call to select or poll figure into this?
>
> what i have inherited is a slot machine that was written a combination
> of java and c and serial port monitor process written in c.
>
> the serial port monitor reads from the serial port and has an open
> message queue.
>
> i am originally a visuall c++ programmer and i have some exposure
> to linux and unix in college.  so getting my mind around how to use
> the serial port has been frustrating but ....
> i like your analogy about block versus non blocking.
>
> so if you use non block io ... how would then know when values are
> available?
>
> something like this:
>
> while(1)
> {
>      int ret = read(serial_fd,buff,size);
>      if(ret > 0 )
>      {
>      do something with the received bytes
>      }
> }
>
> what about using the function select?
>
> thanks again to the group
> jim

--
Java/J2EE Developer/Integrator
Stephen Davidson and Associates, Inc.
Past Chair, Dallas/FortWorth J2EE Sig
214-724-7741



_______________________________________________
https://ntlug.org/mailman/listinfo/discuss




More information about the Discuss mailing list