Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2006

Tip: Looking for answers? Try searching our database.

CommPort integration

Thread view: 
AndreasW - 11 Nov 2006 14:45 GMT
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.
Knute Johnson - 11 Nov 2006 17:50 GMT
> Hello,
>
[quoted text clipped - 11 lines]
>
> 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);

Signature

Knute Johnson
email s/nospam/knute/

AndreasW - 11 Nov 2006 19:08 GMT
Knute Johnson schrieb:
>> Hello,
>>
[quoted text clipped - 31 lines]
>                     InputStream is = sp.getInputStream();
>                     bis = new BufferedInputStream(is);

Fine, thank you for the fast answer. I will look if it is helpful for me.
IchBin - 11 Nov 2006 19:11 GMT
> Hello,
>
[quoted text clipped - 11 lines]
>
> 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/EComActionServlet/DownloadPage:~:com.sun.sunit.sdlc.
content.DownloadPageInfo;jsessionid=4C6A445450E7A7414ADEA49AC390A61E;jsessionid=
4C6A445450E7A7414ADEA49AC390A61E


It has a lot of sample code.

Signature

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-)

Richard Wheeldon - 11 Nov 2006 21:02 GMT
> 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
Knute Johnson - 12 Nov 2006 02:53 GMT
>> 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
[quoted text clipped - 20 lines]
>
> 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.

Signature

Knute Johnson
email s/nospam/knute/

AndreasW - 12 Nov 2006 15:12 GMT
Knute Johnson schrieb:
>>> 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
[quoted text clipped - 15 lines]
>> 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

>> Regards,
>>
[quoted text clipped - 3 lines]
> 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
Knute Johnson - 13 Nov 2006 02:42 GMT
> Knute Johnson schrieb:
>>>> i've got a question about the integration of a CommPort into a Java
[quoted text clipped - 36 lines]
>
> Andreas

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

Signature

Knute Johnson
email s/nospam/knute/



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.