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 / June 2005

Tip: Looking for answers? Try searching our database.

Problem Getting the Serial Port.

Thread view: 
Malik Asif Joyia - 25 Jun 2005 07:20 GMT
Hello
I m writing the following code but it is not working can any bod tell
that what is the problem with it?
<code>
public void OpenSerialPort() throws java.io.IOException {
 try {
       Enumeration en =  CommPortIdentifier.getPortIdentifiers();
           CPI1 = CommPortIdentifier.getPortIdentifier("COM1");
          try
          {
              sm = (SerialPort) CPI1.open("UARTTesting", 3000);
          }catch(PortInUseException ee)
          {
              System.out.println(ee.getMessage());
          }

       } catch (NoSuchPortException e) {
          System.out.println(e.getMessage());
       }

   }
</code>
but when i run the code it throws exception no such port exists, My OS
is Windows 2003 Server Enterpirze Edition.

Thanks
Tor Iver Wilhelmsen - 25 Jun 2005 08:14 GMT
> I m writing the following code but it is not working can any bod tell
> that what is the problem with it?

The comm API will silently "fail" to detect any ports if it cannot
load the native component. Are you sure javacomm.dll is on the library
path?
Dale King - 25 Jun 2005 13:42 GMT
>>I m writing the following code but it is not working can any bod tell
>>that what is the problem with it?
>
> The comm API will silently "fail" to detect any ports if it cannot
> load the native component. Are you sure javacomm.dll is on the library
> path?

Actually, I believe it usually occurs because of not having that stupid
properties file as well.

I recommend against using the Java Comm Api and going with RXTX
(www.rxtx.org). It at least has had active development in the past 7 years.

Signature

 Dale King

Knute Johnson - 27 Jun 2005 03:42 GMT
> Hello
> I m writing the following code but it is not working can any bod tell
[quoted text clipped - 22 lines]
>
> Thanks

The installation is tricky and all of the parts have to be in the right
places.  Here is the little class I wrote to identify the serial ports
and also to tell me that the JavaComm API was installed correctly.  My
Windows XP installation requires the:

comm.jar file to be in the Program Files/Java/jdk1.5.0_03/jre/lib/ext
and the Program Files/Java/jre1.5.0_03/lib/ext directories.

javax.comm.properties file to be in the
Program Files/Java/jre1.5.0_03/jre/lib directory.

win32com.dll file to be in the Program Files/Java/jre1.5.0_03/bin directory.

import java.io.*;
import java.util.*;
import javax.comm.*;

public class Ports {
    public Ports() {
        CommPortIdentifier cpi = null;

        Enumeration e = CommPortIdentifier.getPortIdentifiers();

        while (e.hasMoreElements()) {
            try {
                cpi = (CommPortIdentifier) e.nextElement();
            } catch (NoSuchElementException n) {}
            System.out.println(cpi.getName());
        }
    }
    public static void main(String[] args) { new Ports(); }
}

Signature

Knute Johnson
email s/nospam/knute/

Dale King - 29 Jun 2005 07:23 GMT
>> Hello
>> I m writing the following code but it is not working can any bod tell
[quoted text clipped - 36 lines]
> win32com.dll file to be in the Program Files/Java/jre1.5.0_03/bin
> directory.

I recommend putting all 3 files in both the JDK and the JRE to make sure
it works. Depending on your setup you may end up invoking the java
runtime that is in the JDK instead of the JRE.

Signature

 Dale King



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



©2008 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.