469,358 Members | 1,539 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,358 developers. It's quick & easy.

Problem to listout the ports in javax.comm package

107 100+
hi, currently i am doing the project to send the sms from PC to Mobile and vice versa using GSM modem. I successfully done this process in Hyperterminal.

First i connect the GSM modem in COM1 port

then set the baud rate to 9600

and execute the AT commands in hyperterminal and its works fine..

But my problem is that to do the similar process in java..

javax.comm package is used to interact with the ports..

I used the below code

Expand|Select|Wrap|Line Numbers
  1.         portList = CommPortIdentifier.getPortIdentifiers();
  2.  
  3.         while (portList.hasMoreElements()) {
  4.             portId = (CommPortIdentifier) portList.nextElement();
  5.             if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
  6.                 if (portId.getName().equals("COM1")) {
  7.                 //if (portId.getName().equals("/dev/term/a")) {
  8.                     try {
  9.                         serialPort = (SerialPort)
  10.                             portId.open("SimpleWriteApp", 2000);
  11.                     } catch (PortInUseException e) {}
  12.                     try {
  13.                         outputStream = serialPort.getOutputStream();
  14.                     } catch (IOException e) {}
  15.                     try {
  16.                         serialPort.setSerialPortParams(9600,
  17.                             SerialPort.DATABITS_8,
  18.                             SerialPort.STOPBITS_1,
  19.                             SerialPort.PARITY_NONE);
  20.                     } catch (UnsupportedCommOperationException e) {}
  21.                     try {
  22.                         outputStream.write(messageString.getBytes());
  23.                     } catch (IOException e) {}
  24.                 }
  25.             }
  26.  
  27.  
But the problem is that results the port count is 0(Null).
Please i need the solution.. Its Urgent..

Thanks in Advance..
Oct 3 '08 #1
9 6222
JosAH
11,448 Expert 8TB
Note that saying "It's urgent" doesn't help you much: it may be urgent to you but
it isn't urgent to us and we won't hurry and treat you in a priviledged way because
you mentioned your urgency; you'd better had started your project a bit earlier.

w.r.t. your question: Sun's comm package only handles parallel and serial ports;
it doesn't understand, nor recognizes any usb ports.

kind regards,

Jos
Oct 3 '08 #2
rajujrk
107 100+
Note that saying "It's urgent" doesn't help you much: it may be urgent to you but
it isn't urgent to us and we won't hurry and treat you in a priviledged way because
you mentioned your urgency; you'd better had started your project a bit earlier.

w.r.t. your question: Sun's comm package only handles parallel and serial ports;
it doesn't understand, nor recognizes any usb ports.

kind regards,

Jos
But Even it didn't list out the PARALLEL and SERIAL ports

Why?
Oct 10 '08 #3
JosAH
11,448 Expert 8TB
What happens when you append a line (after line #4) like this:

Expand|Select|Wrap|Line Numbers
  1. System.out.println(portID.getName());
  2.  
Is anything printed at all?

kind regards,

Jos
Oct 10 '08 #4
rajujrk
107 100+
What happens when you append a line (after line #4) like this:

Expand|Select|Wrap|Line Numbers
  1. System.out.println(portID.getName());
  2.  
Is anything printed at all?

kind regards,

Jos

AFter the Below Statement
Expand|Select|Wrap|Line Numbers
  1. portList = CommPortIdentifier.getPortIdentifiers(); 
  2.  
the getPortIdentifiers() method return no values . So the below while says always false
Expand|Select|Wrap|Line Numbers
  1.         while (portList.hasMoreElements()) { 
  2.  
  3.          }
  4.  
What happened in the getPortIdentifiers() Method?
Oct 10 '08 #5
JosAH
11,448 Expert 8TB
What happened in the getPortIdentifiers() Method?
Did you properly install all three files? i.e. the jar in the lib/ext directory, the dll
in the bin directory and the .properties file in the lib directory.

kind regards,

Jos
Oct 10 '08 #6
rajujrk
107 100+
Did you properly install all three files? i.e. the jar in the lib/ext directory, the dll
in the bin directory and the .properties file in the lib directory.

kind regards,

Jos
ya, i installed it in lib/ext

I include the following files

1. comm.jar
2. javax.comm.properties

What is the third file?

I have another file as win32.dll
Oct 11 '08 #7
JosAH
11,448 Expert 8TB
Store that .properties file in /lib instead. So:

1) the .jar in /lib/ext
2) the .properties in /lib
3) the .dll in /bin

Also read their installation notes.

kind regards,

Jos
Oct 11 '08 #8
rajujrk
107 100+
Store that .properties file in /lib instead. So:

1) the .jar in /lib/ext
2) the .properties in /lib
3) the .dll in /bin

Also read their installation notes.

kind regards,

Jos

Ya its working fine now..

I put .properties file in lib/ext

i change its loc to lib

Now its works fine

Thank you..
Oct 11 '08 #9
hi,

I am trying to do this same task. For me it is recognizing the ports but not sending the sms. It works fine via hyperterminal. Is it possible for you to send me your code?

Thanks a lot.

regards
Bharti
Dec 8 '11 #10

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Hal Vaughan | last post: by
4 posts views Thread by jesper | last post: by
13 posts views Thread by Bob Greschke | last post: by
3 posts views Thread by Steve | last post: by
oll3i
12 posts views Thread by oll3i | last post: by
1 post views Thread by shrik | last post: by
1 post views Thread by Neverhood | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.