CommPort integration

A

AndreasW

Hello,

i've got a question about the integration of a CommPort into a Java
programm. I need it for data transfer between the PC and a
Microcontroller. I'm a newbie in programming and so it would be very
useful to have some easy examples or an introduction for the
initialisation of the port and the read/transmit- process. I've
downloaded "commapi" from Sun Microsystems, but I mean the description
is a little bit complicated.
I hope you could help me with a useful link or a helpful example file.

Thank you very much.
AW

I don't know if it is important, but I use the JBuilder from Borland.
 
K

Knute Johnson

AndreasW said:
Hello,

i've got a question about the integration of a CommPort into a Java
programm. I need it for data transfer between the PC and a
Microcontroller. I'm a newbie in programming and so it would be very
useful to have some easy examples or an introduction for the
initialisation of the port and the read/transmit- process. I've
downloaded "commapi" from Sun Microsystems, but I mean the description
is a little bit complicated.
I hope you could help me with a useful link or a helpful example file.

Thank you very much.
AW

I don't know if it is important, but I use the JBuilder from Borland.

Here is some code taken from an application I wrote. It opens the port,
sets the parameters and obtains an InputStream. After that it is just
like any other stream I/O.

CommPortIdentifier cpi =
CommPortIdentifier.getPortIdentifier("COM1");
SerialPort sp =
(SerialPort)cpi.open("LVDCClient",2500);

// set serial port parameters
sp.setSerialPortParams(9600,SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);
sp.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);

sp.disableReceiveTimeout();
sp.disableReceiveThreshold();

InputStream is = sp.getInputStream();
bis = new BufferedInputStream(is);
 
A

AndreasW

Knute said:
Here is some code taken from an application I wrote. It opens the port,
sets the parameters and obtains an InputStream. After that it is just
like any other stream I/O.

CommPortIdentifier cpi =
CommPortIdentifier.getPortIdentifier("COM1");
SerialPort sp =
(SerialPort)cpi.open("LVDCClient",2500);

// set serial port parameters
sp.setSerialPortParams(9600,SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);
sp.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);

sp.disableReceiveTimeout();
sp.disableReceiveThreshold();

InputStream is = sp.getInputStream();
bis = new BufferedInputStream(is);
Fine, thank you for the fast answer. I will look if it is helpful for me.
 
I

IchBin

AndreasW said:
Hello,

i've got a question about the integration of a CommPort into a Java
programm. I need it for data transfer between the PC and a
Microcontroller. I'm a newbie in programming and so it would be very
useful to have some easy examples or an introduction for the
initialisation of the port and the read/transmit- process. I've
downloaded "commapi" from Sun Microsystems, but I mean the description
is a little bit complicated.
I hope you could help me with a useful link or a helpful example file.

Thank you very much.
AW

I don't know if it is important, but I use the JBuilder from Borland.

You can download the Communications API Specification 2.0:
https://sdlc4e.sun.com/ECom/EComAct...E;jsessionid=4C6A445450E7A7414ADEA49AC390A61E

It has a lot of sample code.

--
Thanks in Advance... http://ichbin.9999mb.com
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
______________________________________________________________________
'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
 
R

Richard Wheeldon

AndreasW said:
i've got a question about the integration of a CommPort into a Java
programm. I need it for data transfer between the PC and a
Microcontroller.

// Get a port identifier
CommPortIdentifier portId =
CommPortIdentifier.getPortIdentifier(portName);
// Open a port
SerialPort port =
(SerialPort)portId.open("CommPortExample Application", 30000);
// Open an input Stream
InputStream in = port.getInputStream();
// Read data

Don't be suprised in you run into problems with Sun's API. If you do,
take a look at rxtx: http://users.frii.com/jarvi/rxtx/

Also, if you ever start wanting to add TCP access to your rs232-based
comms on the microcontroller side, I can strongly recommend Digi's EM
and ME series of modules,

Regards,

Richard
 
K

Knute Johnson

Richard said:
// Get a port identifier
CommPortIdentifier portId =
CommPortIdentifier.getPortIdentifier(portName);
// Open a port
SerialPort port =
(SerialPort)portId.open("CommPortExample Application", 30000);
// Open an input Stream
InputStream in = port.getInputStream();
// Read data

Don't be suprised in you run into problems with Sun's API. If you do,
take a look at rxtx: http://users.frii.com/jarvi/rxtx/

Also, if you ever start wanting to add TCP access to your rs232-based
comms on the microcontroller side, I can strongly recommend Digi's EM
and ME series of modules,

Regards,

Richard

RXTX has at least one serious bug under Windows. I have yet to have a
problem with Sun's API. I don't really know why Sun doesn't want to
support it any more but RXTX is not the answer.
 
A

AndreasW

Knute said:
RXTX has at least one serious bug under Windows. I have yet to have a
problem with Sun's API. I don't really know why Sun doesn't want to
support it any more but RXTX is not the answer.



Thank you very much for every answer. It's a great help for me.
But there is another problem. Is it correct, that I have to call the
library "javax.comm.*;" at the beginning of my program? This is written
in the documentation of Sun's commapi?! It shall be copy into the
<jdk>\jre\lib directory. But my compiler shows the Error message:
"Package javax.comm doesn't exists". What's wrong? The other files
(win32comm.dll and comm.jar) I've put in the right directorys, too?!

Greetings,

Andreas
 
K

Knute Johnson

AndreasW said:
Thank you very much for every answer. It's a great help for me.
But there is another problem. Is it correct, that I have to call the
library "javax.comm.*;" at the beginning of my program? This is written
in the documentation of Sun's commapi?! It shall be copy into the
<jdk>\jre\lib directory. But my compiler shows the Error message:
"Package javax.comm doesn't exists". What's wrong? The other files
(win32comm.dll and comm.jar) I've put in the right directorys, too?!

Greetings,

Andreas

To compile you need to put the comm.jar file in the JDK/jre/lib/ext
directory.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top