Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Using Java communications API

Posted on 2006-05-02
32
Medium Priority
?
422 Views
Last Modified: 2010-05-19
Dear Experts,
 I am using comm.jar  with Netbeans 4.1 and jdk 1.4 I got (run one of the samples call blackbox)
No serial ports found!
could you please tell me what is wrong, or give me an example of how to use java to connect to a serial port ?

Any help will be greatly appreciated.

Thank you
Hector
0
Comment
Question by:hvelasco
  • 12
  • 8
  • 6
  • +3
32 Comments
 
LVL 92

Expert Comment

by:objects
ID: 16591024
Have you installed it as per the install instructions?
ie. placing the dll and properties files in the correct directory
0
 
LVL 14

Expert Comment

by:Tommy Braas
ID: 16593247
And of course you do have serial ports on your system?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 30

Expert Comment

by:Mayank S
ID: 16593572
You need to place comm.jar and javax.comm.properties files in your JDK\JRE\LIB\EXT, and win32comm.dll in your JDK\BIN. Might need to restart Netbeans after that.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16595388
Sorry only the JAR will go in %JAVA_HOME%\jre\lib\ext. The properties-file will go under %JAVA_HOME%\jre\lib
0
 
LVL 12

Expert Comment

by:Giant2
ID: 16595440
See this example to view about the Port on your system:
http://www.java2s.com/Code/Java/Development-Class/Chooseaportanyport.htm
...and how to listen on it like a Modem:
http://www.java2s.com/Code/Java/Network-Protocol/JModemsimplecommunicationsprogram.htm

If the first program say no port are present, soyou do not have port utilizable with javax.comm

Hope this could help you.
Bye, Giant.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16595506
You can use this to check if any serial ports are present:

Enumeration en = CommPortIdentifier.getPortIdentifiers () ;
while ( en.hasMoreElements () )
  System.out.println ( ( ( CommPortIdentifier ) en.nextElement () ).getName () ) ;
0
 

Author Comment

by:hvelasco
ID: 16598848
Dear Experts,
 Thank you for all your comments. As for your questions:
 Yes I follow the direction.
 I have active ports (in fact 2 serial ports and they work using hyperterminal or another C++ application)
 I tried Giant2 code and the dropboxes are inactive
 I tried mayankeagle snippet and does not get any name
 I looked the discussion threads given by the links from shivaspk and they show me that I did the right thing installed the files.

Any additional help will be greatly appreciated.
Thank you
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16603146
Did you place the JAR/ DLL/ properties files in the locations I asked you to? You shouldn't be facing problems after that.
0
 

Author Comment

by:hvelasco
ID: 16639577
Dear mayankeagle,
 I am sorry for a late response. Yes I did and still do not get any ports. Any additional idea will be greatly appreciate.
Thank you
0
 
LVL 12

Expert Comment

by:Giant2
ID: 16639725
>I tried Giant2 code and the dropboxes are inactive
Seems you do not have any ports.
In Windows environment, do you have check if there are any?
(My computer-Properties-Hardware-...-Ports)
Are there Communication port (COM1...)?

It seems you have only USB.

Bye, Giant.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16645048
Are you able to run any other application (like VB, C++, .NET or whatever you have) which detects Com ports?

Can you confirm if you have multiple JDKs? What is the JAVA_HOME environment-variable pointing to? Which JDK version is the Netbeans project referring to? What directory do you have the JAR in, what directory do you have the DLL in and what directory do you have the properties-file in?
0
 

Author Comment

by:hvelasco
ID: 16652930
Dear Giant2  & mayankeagle ,
  I have another applications (C++ applications and of course Hyperterminal) that use my communication ports (2).
  Here is the tree
C:\Program Files\netbeans-4.1>tree
Folder PATH listing for volume IBM_PRELO
Volume serial number is 54B9-2CAB
C:.
├───bin
├───enterprise1
│   ├───ant
│   │   ├───extra
│   │   ├───nblib
│   │   │   └───locale
│   │   └───sources
│   │       └───org
│   │           └───netbeans
│   │               └───modules
│   │                   ├───web
│   │                   │   └───project
│   │                   │       └───ant
│   │                   └───websvc
│   │                       └───core
│   │                           └───ant
│   ├───config
│   │   ├───Modules
│   │   ├───TagLibraries
│   │   │   └───JSTL11
│   │   └───WebServices
│   ├───docs
│   ├───jakarta-tomcat-5.5.7
│   │   ├───bin
│   │   ├───common
│   │   │   ├───classes
│   │   │   ├───endorsed
│   │   │   ├───i18n
│   │   │   └───lib
│   │   ├───conf
│   │   │   └───Catalina
│   │   │       └───localhost
│   │   ├───logs
│   │   ├───server
│   │   │   ├───classes
│   │   │   ├───lib
│   │   │   └───webapps
│   │   │       ├───admin
│   │   │       │   ├───connector
│   │   │       │   ├───context
│   │   │       │   ├───host
│   │   │       │   ├───images
│   │   │       │   ├───realm
│   │   │       │   ├───resources
│   │   │       │   ├───server
│   │   │       │   ├───service
│   │   │       │   ├───users
│   │   │       │   ├───valve
│   │   │       │   └───WEB-INF
│   │   │       │       └───lib
│   │   │       └───manager
│   │   │           ├───images
│   │   │           └───WEB-INF
│   │   │               └───lib
│   │   ├───shared
│   │   │   ├───classes
│   │   │   └───lib
│   │   ├───temp
│   │   ├───webapps
│   │   │   ├───balancer
│   │   │   │   ├───images
│   │   │   │   ├───META-INF
│   │   │   │   └───WEB-INF
│   │   │   │       ├───config
│   │   │   │       └───lib
│   │   │   ├───ROOT
│   │   │   │   ├───admin
│   │   │   │   └───WEB-INF
│   │   │   │       └───lib
│   │   │   ├───tomcat-docs
│   │   │   │   ├───appdev
│   │   │   │   │   ├───printer
│   │   │   │   │   └───sample
│   │   │   │   │       ├───docs
│   │   │   │   │       ├───src
│   │   │   │   │       │   └───mypackag
│   │   │   │   │       └───web
│   │   │   │   │           ├───images
│   │   │   │   │           └───WEB-INF
│   │   │   │   ├───architecture
│   │   │   │   │   ├───printer
│   │   │   │   │   ├───requestProcess
│   │   │   │   │   └───startup
│   │   │   │   ├───config
│   │   │   │   │   └───printer
│   │   │   │   ├───images
│   │   │   │   ├───printer
│   │   │   │   └───WEB-INF
│   │   │   └───webdav
│   │   │       └───WEB-INF
│   │   └───work
│   ├───modules
│   │   ├───autoload
│   │   │   ├───ext
│   │   │   │   └───locale
│   │   │   └───locale
│   │   ├───docs
│   │   │   └───locale
│   │   ├───eager
│   │   │   └───locale
│   │   ├───ext
│   │   │   └───locale
│   │   └───locale
│   └───update_tracking
├───etc
├───ide5
│   ├───ant
│   │   ├───bin
│   │   ├───etc
│   │   │   └───checkstyle
│   │   ├───lib
│   │   ├───nblib
│   │   │   └───locale
│   │   └───patches
│   ├───config
│   │   ├───ModuleAutoDeps
│   │   └───Modules
│   ├───core
│   ├───docs
│   │   └───org
│   │       └───netbeans
│   │           └───modules
│   │               └───usersguide
│   ├───mdrstorage
│   ├───modules
│   │   ├───autoload
│   │   │   ├───ext
│   │   │   │   └───locale
│   │   │   └───locale
│   │   ├───docs
│   │   │   └───locale
│   │   ├───ext
│   │   │   └───locale
│   │   ├───lib
│   │   └───locale
│   ├───sources
│   │   └───org
│   │       └───netbeans
│   │           └───lib
│   │               └───awtextra
│   └───update_tracking
├───nb4.1
│   ├───config
│   │   └───Modules
│   ├───core
│   │   └───locale
│   ├───docs
│   ├───modules
│   │   └───locale
│   └───update_tracking
├───platform5
│   ├───config
│   │   ├───ModuleAutoDeps
│   │   └───Modules
│   ├───core
│   │   └───locale
│   ├───lib
│   │   └───locale
│   ├───modules
│   │   ├───ext
│   │   └───locale
│   └───update_tracking
└───_uninst
    └───storagebuilder

for Netbeans 4.1
and the tree for jdk:
C:\j2sdk1.4.2_10>tree
Folder PATH listing for volume IBM_PRELOAD
Volume serial number is 00000030 54B9:2CAB
C:.
├───bin
├───demo
│   ├───applets
│   │   ├───Animator
│   │   │   ├───audio
│   │   │   └───images
│   │   │       ├───Beans
│   │   │       └───SimpleAnimation
│   │   ├───ArcTest
│   │   ├───BarChart
│   │   ├───Blink
│   │   ├───CardTest
│   │   ├───Clock
│   │   ├───DitherTest
│   │   ├───DrawTest
│   │   ├───Fractal
│   │   ├───GraphicsTest
│   │   ├───GraphLayout
│   │   │   └───audio
│   │   ├───ImageMap
│   │   │   ├───audio
│   │   │   └───images
│   │   ├───JumpingBox
│   │   │   └───sounds
│   │   ├───MoleculeViewer
│   │   │   └───models
│   │   ├───NervousText
│   │   ├───SimpleGraph
│   │   ├───SortDemo
│   │   ├───SpreadSheet
│   │   ├───TicTacToe
│   │   │   ├───audio
│   │   │   └───images
│   │   └───WireFrame
│   │       └───models
│   ├───jfc
│   │   ├───FileChooserDemo
│   │   │   ├───images
│   │   │   └───src
│   │   ├───Font2DTest
│   │   │   └───src
│   │   ├───Java2D
│   │   │   └───src
│   │   │       └───java2d
│   │   │           └───demos
│   │   │               ├───Arcs_Curves
│   │   │               ├───Clipping
│   │   │               ├───Colors
│   │   │               ├───Composite
│   │   │               ├───Fonts
│   │   │               ├───Images
│   │   │               ├───Lines
│   │   │               ├───Mix
│   │   │               ├───Paint
│   │   │               ├───Paths
│   │   │               └───Transforms
│   │   ├───Metalworks
│   │   │   ├───HelpFiles
│   │   │   ├───images
│   │   │   └───src
│   │   ├───Notepad
│   │   │   ├───resources
│   │   │   └───src
│   │   ├───SampleTree
│   │   │   ├───images
│   │   │   └───src
│   │   ├───Stylepad
│   │   │   ├───resources
│   │   │   └───src
│   │   ├───SwingApplet
│   │   │   └───src
│   │   ├───SwingSet2
│   │   │   └───src
│   │   └───TableExample
│   │       └───src
│   ├───jpda
│   └───plugin
│       ├───applets
│       │   ├───Animator
│       │   │   ├───audio
│       │   │   └───images
│       │   │       ├───Beans
│       │   │       └───SimpleAnimation
│       │   ├───ArcTest
│       │   ├───BarChart
│       │   ├───Blink
│       │   ├───CardTest
│       │   ├───Clock
│       │   ├───DitherTest
│       │   ├───DrawTest
│       │   ├───Fractal
│       │   ├───GraphicsTest
│       │   ├───GraphLayout
│       │   │   └───audio
│       │   ├───ImageMap
│       │   │   ├───audio
│       │   │   └───images
│       │   ├───JumpingBox
│       │   │   └───sounds
│       │   ├───MoleculeViewer
│       │   │   └───models
│       │   ├───NervousText
│       │   ├───SimpleGraph
│       │   ├───SortDemo
│       │   ├───SpreadSheet
│       │   ├───TicTacToe
│       │   │   ├───audio
│       │   │   └───images
│       │   └───WireFrame
│       │       └───models
│       └───jfc
│           ├───FileChooserDemo
│           │   ├───images
│           │   └───src
│           ├───Font2DTest
│           │   └───src
│           ├───Java2D
│           │   └───src
│           │       └───java2d
│           │           └───demos
│           │               ├───Arcs_Curves
│           │               ├───Clipping
│           │               ├───Colors
│           │               ├───Composite
│           │               ├───Fonts
│           │               ├───Images
│           │               ├───Lines
│           │               ├───Mix
│           │               ├───Paint
│           │               ├───Paths
│           │               └───Transforms
│           ├───Metalworks
│           │   ├───HelpFiles
│           │   ├───images
│           │   └───src
│           ├───Notepad
│           │   ├───resources
│           │   └───src
│           ├───SampleTree
│           │   ├───images
│           │   └───src
│           ├───Stylepad
│           │   ├───resources
│           │   └───src
│           ├───SwingApplet
│           │   └───src
│           ├───SwingSet2
│           │   └───src
│           └───TableExample
│               └───src
├───include
│   └───win32
├───jre
│   ├───bin
│   │   ├───client
│   │   └───server
│   ├───javaws
│   │   └───resources
│   └───lib
│       ├───applet
│       ├───audio
│       ├───cmm
│       ├───ext
│       ├───fonts
│       ├───i386
│       ├───im
│       ├───images
│       │   └───cursors
│       ├───security
│       └───zi
│           ├───Africa
│           ├───America
│           │   ├───Indiana
│           │   ├───Kentucky
│           │   └───North_Dakota
│           ├───Antarctica
│           ├───Asia
│           ├───Atlantic
│           ├───Australia
│           ├───Etc
│           ├───Europe
│           ├───Indian
│           └───Pacific
└───lib
As far as JAVA_HOME, I think NetBeans takes care of this, since I compiled other projects and they ran fine

Once again any additional help would be greatly appreciated.
Thank you
0
 
LVL 92

Expert Comment

by:objects
ID: 16653513
>  Yes I follow the direction.

Did you install the files in the jre you are actually running your application with and not a different one?
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16655026
>> As far as JAVA_HOME, I think NetBeans takes care of this, since I compiled other projects and they ran fine

Can you stil verify if you have multiple versions of Java installed and whether you placed the JAR/ DLL/ properties in the correct directories as per the version Netbeans is using?
0
 

Author Comment

by:hvelasco
ID: 16662690
Dear Experts,
  As fas as installation goes, I use all the default options from jdk 1.4 and Netbeans.
  As for the JAVA_HOME I did not change the path, since I let NetBeans do the path for me. I do not know how to see the path that Netbeans is using it, but if you tell me how to do it I will be more than happy to check it for you.

Once again thank you for your help.
0
 
LVL 92

Expert Comment

by:objects
ID: 16663199
so are you running it via netbeans?
can you try running it via the commasnd line using the jre that you installed it into to verify if that works.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16664322
Netbeans might not have set the JAVA_HOME environment variable. Try setting it explicitly from My Computer -> Properties -> Advanced -> Environment Variables -> add it if it does not exist (System or User environment variables). Set it to the root directory of your JDK. Try running it from the command-prompt then.
0
 

Author Comment

by:hvelasco
ID: 16720591
Dear Experts,
I am sorry for took so long to response. Well it DID NOT work either. I was wondering if I can hardcoded the value?
Please advice
Thank you
0
 
LVL 92

Expert Comment

by:objects
ID: 16722089
What exactly did not work?
Hardcode what value?
0
 

Author Comment

by:hvelasco
ID: 16722964
Dear objects
 I tried your and mayankeagle suggestions and did not work.
 Hardcode, well this method return some values that populate the drop down box, if I knew those values I can populate the drop down box manually.

Thank you
0
 
LVL 92

Expert Comment

by:objects
ID: 16722984
what command did you try to run it with?
What directory did you install javacomm in?
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16731961
You can of course try:

CommPortIdentifier id = CommPortIdentifier.getPortIdentifier ( "COM1" ) ; // hard-code port number
CommPort handle = id.open ( "My Application", 5000 ) ;

Can you post a complete answer to http:#16645048 just to make sure where you have your DLLs, properties and JAR placed. Also - try setting JAVA_HOME yourself (my computer -> properties -> advanced -> environment variables)
0
 
LVL 12

Expert Comment

by:Giant2
ID: 16732044
What is the code you use to check what port are there?
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16750927
Maybe that you installed JDK (with JRE) in a directory, and also the same JRE version in another directory, like:

C:\Program Files\j2sdk1.4.1_02 - JDK - this is what your JAVA_HOME should be set to
C:\Program Files\Java\j2sdk1.4.1_02\jre - JRE within the JDK

And you might also have another:

C:\Program Files\Java\j2re1.4.1_02 - only the JRE

Which one is the Netbeans project referring to? You need to put the DLL, properties-file and the JAR under the correct one.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16750988
>> C:\Program Files\j2sdk1.4.1_02

I meant: C:\Program Files\Java\j2sdk1.4.1_02  (the default normally)
0
 

Author Comment

by:hvelasco
ID: 16753963
Dear mayankeagle
 Your point is valid, however the files located at the jdk/lib folder are not repeated on the NetBEan folders. Also, on Netbeans there is bin folder only for the executable and a lib folder for the ant. When you installl the Netbeans bundle, it will automatically install the jdk, jre and the ide, so I do not think there should be a replication.
 Do you or any of the other experts tried with Netbeans 4.1? From scratch, download it, install it and run the sample application.

Once again thank you
0
 
LVL 92

Assisted Solution

by:objects
objects earned 400 total points
ID: 16755903
I thought you said you tried running it from the command line?
You need to ensure that the jre that you are running it with is the one you have installed javacomm in.
By the sounds you may have at least 3 jre's installed and from what you have said you have only installed javacomm  in one.
0
 
LVL 30

Accepted Solution

by:
Mayank S earned 1600 total points
ID: 16758219
Like we said before - can you check the JRE which the Netbeans project is using? Check which directory it is installed in and place the DLL, JAR, properties in its sub-folders as indicated earlier.

>> so I do not think there should be a replication

There is for the JRE, if you have:

C:\Program Files\Java\j2sdk1.4.1_02\jre as well as C:\Program Files\Java\j2re1.4.1_02.

Maybe that you have copied the JAR, etc inside the j2sdk folder (former) where as the Netbeans project is referring to the j2re folder (latter).
0
 

Author Comment

by:hvelasco
ID: 16769222
Dear Experts,
 You are great!!. Thank you so much for your patient and do not give up on me. I found the problem thanks to all your great comments. Yes I do have two JRE folders, one from the NetBeans installation and another one that came with my computer. What I also learned is that looks like all the dll files must be at

../jdx2.x/JRE/bin

and the jar files at

../jdx2.x/JRE/lib

Is this true??

Anyhow, by putting my jar and dll files on those locations I was able to see the light at the end of the tunnel. Feels good :)
Once again thank you
p.s. The readme file for these sample is not up to date and that was another factor that cause me confusion.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16769480
>> and the jar files at
>> ../jdx2.x/JRE/lib

The JAR should be in JRE/lib/ext

Glad to help.
0
 
LVL 12

Expert Comment

by:Giant2
ID: 16789211
Sorry not help.
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Don’ts and Dos are two important end products of software testing basics that a tester needs to regard. This article attempts to explain the principles of both.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month11 days, 20 hours left to enroll

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question