Sending and receiving data from serial port

Hi,

I'm working with serial ports.

Which are the methods to send and receive data to/from a serial port?

I tried using:

>byte[] data_in = {23, 54, 68};//ex: data to send

>thePort.getOutputStream().write(data_in);

to sending , and:

>System.out.println(thePort.getInputStream().read());

>System.out.println(thePort.getInputStream().read());

>System.out.println(thePort.getInputStream().read());

to receive and visualize the three data in the array.

How can I do to know how long is the input stream and, for example, make a for cycle to visualize it?

[638 byte] By [IronBargiaa] at [2007-11-26 19:55:49]
# 1

> How can I do to know how long is the input stream and, for example,

> make a for cycle to visualize it?

You can't automagically 'know' how many bytes can be read from that

stream. There either has to be some protocol, e.g. the first byte(s)

are the length of the entire message, or you can set a read timeout:

if a timeout exception is thrown there certainly aren't any more bytes

available from the input stream.

kind regards,

Jos

JosAHa at 2007-7-9 22:49:15 > top of Java-index,Java Essentials,Java Programming...
# 2
You will have a very rough time if you use package javax.comm or RXTX. Try googling for parport. It works like a miracle.
Jamwaa at 2007-7-9 22:49:16 > top of Java-index,Java Essentials,Java Programming...
# 3

> You will have a very rough time if you use package javax.comm or RXTX.

Care to elaborate? I've used javax.comm until Sun dropped support for

it; then I used rxtx; both didn't present any problems nor rough times

for me.

> Try googling for parport. It works like a miracle.

Great; parport handles the parallel port. Lots of simple devices just

have a serial RS/232 interface.

kind regards,

Jos

JosAHa at 2007-7-9 22:49:16 > top of Java-index,Java Essentials,Java Programming...