Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Problem Getting the Serial Port.

Reply
Thread Tools

Problem Getting the Serial Port.

 
 
Malik Asif Joyia
Guest
Posts: n/a
 
      06-25-2005
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

 
Reply With Quote
 
 
 
 
Tor Iver Wilhelmsen
Guest
Posts: n/a
 
      06-25-2005
"Malik Asif Joyia" <> writes:

> 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?
 
Reply With Quote
 
 
 
 
Dale King
Guest
Posts: n/a
 
      06-25-2005
Tor Iver Wilhelmsen wrote:
> "Malik Asif Joyia" <> writes:
>
>
>>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.

--
Dale King
 
Reply With Quote
 
Knute Johnson
Guest
Posts: n/a
 
      06-27-2005
Malik Asif Joyia wrote:

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


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(); }
}

--

Knute Johnson
email s/nospam/knute/
 
Reply With Quote
 
Dale King
Guest
Posts: n/a
 
      06-29-2005
Knute Johnson wrote:
> Malik Asif Joyia wrote:
>
>> 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
>>

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


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.

--
Dale King
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
fcntl, serial ports and serial signals on RS232. Max Kotasek Python 4 04-09-2010 06:32 PM
350d serial number - what serial number?!? GT Digital Photography 6 04-07-2005 07:58 PM
Test Serial to Serial Connection, Protocol Down... Scooter Cisco 5 12-16-2004 04:38 PM
Can I connect router Serial interface directly to a PC serial port? Faustino Dina Cisco 2 08-18-2004 02:30 AM
getting a serial number off an Aironet 350 access point chuck Cisco 0 02-17-2004 07:23 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57