We help IT Professionals succeed at work.

No response while using RXTX comm APIs in Sun Solaris

sandeep1984
sandeep1984 asked
on
817 Views
Last Modified: 2013-12-27
Below mentioned program gives this output when run on WIndows XP
Stable Library
=========================================
Native lib Version = RXTX-2.1-7
Java lib Version   = RXTX-2.1-7
COM4
COM7

But when I try to run on Solaris (SPARC 64 bit) machine it is not giving any output(except that Native lib Version etc.) and still wont exit.

I am unable to find the error.


import gnu.io.*;
import java.util.*;
 
class PortTest
{
	public static void main(String args[])
	{
		try
		{
			Enumeration portList = CommPortIdentifier.getPortIdentifiers();
			while (portList.hasMoreElements()) 
			{
				CommPortIdentifier	portId = (CommPortIdentifier) portList.nextElement();
				System.out.println(portId.getName());
			}
		}
		catch(Exception exp)
		{
			exp.printStackTrace(System.out);
		}
	}
}

Open in new window

Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2016

Commented:
What happens when you change that to

System.out.printf("Port id is %s\n", portId.getName());

?
Top Expert 2008
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
This is the message I am getting in solaris when I run the above program.
ROMFTBE1(root)!!/tmp/new >java PortTest      Experimental:  JNI_OnLoad called.
Stable Library
=========================================
Native lib Version = RXTX-2.1-7
Java lib Version   = RXTX-2.1-7

Mr CEHJ, what is that %s??
And what is the difference?
CERTIFIED EXPERT
Top Expert 2016

Commented:
>>
Mr CEHJ, what is that %s??
And what is the difference?
>>

Just a formatting placeholder. I'm just making sure that *something* is being printed

Author

Commented:
I think It is not coming after
Enumeration portList = CommPortIdentifier.getPortIdentifiers();
CERTIFIED EXPERT
Top Expert 2016

Commented:
You mean it's blocking - nothing gets printed?

Author

Commented:
yes.
CERTIFIED EXPERT
Top Expert 2016

Commented:
Do you have the correct permissions on those ports?

Author

Commented:
yes I do have.
In fact I have tried with tip command.
I logged in as root
CERTIFIED EXPERT
Top Expert 2016
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
looks like an issue with the native lib to me

Author

Commented:
Native lib is built (using make fro  the source code available in RXTX web site) from that machine only.
No errors while configuring or building.
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
but then it should come out of that block or atleast throw some error right?

Author

Commented:
When I restrict the app to search only for /dev/cua/a & /dev/cua/b the application is unable to find any serial port & it is coming out of the program now.

But I am able to open /dev/cua/b through tip.
For more info I have given the full trace with the permissions.

Any suggestions please..
ROMFTBE1(deepakm)!!/tmp/new >java -Dgnu.io.rxtx.SerialPorts=/dev/cua/a:/dev/cua/b PortTest           Experimental:  JNI_OnLoad called.
Stable Library
=========================================
Native lib Version = RXTX-2.1-7
Java lib Version   = RXTX-2.1-7
ROMFTBE1(deepakm)!!/tmp/new >tip -9600 /dev/cua/b
connected
at
OK
~
[EOT]
 
ROMFTBE1(deepakm)!!/tmp/new >
ROMFTBE1(deepakm)!!/tmp/new >ls -l /dev/cua/b
lrwxrwxrwx   1 root     root          51 Aug  1  2006 /dev/cua/b -> ./../devices/pci@1e,600000/isa@7/serial@0,2e8:b,cu
ROMFTBE1(deepakm)!!/tmp/new >ls -lL /dev/cua/b
crwxrwxrwx   1 root     root      37,131073 Aug  9 13:01 /dev/cua/b
ROMFTBE1(deepakm)!!/tmp/new > 

Open in new window

CERTIFIED EXPERT
Top Expert 2016

Commented:
Two things about that:

a. your program run has clearly exited - showing the rxtx version (why is that btw?)
b. Your directory listing shows quite different timestamps - why?

Author

Commented:
Program is exited because is is unable to find any serial ports..
CERTIFIED EXPERT
Top Expert 2016

Commented:
>>Program is exited because is is unable to find any serial ports..

Well a program/library wouldn't normally print the version number unless it was asked to

Author

Commented:
Even in windows it is printing the same, but working fine.
CERTIFIED EXPERT
Top Expert 2016

Commented:
OK - we'll consider it to be normal output then - even if it's a bit strange ;-)

Author

Commented:
When I try to execute the following program I am getting this error.

Serial Port
NullpointerException
at gnu.io.RXTXCommDriver.getCommport (RXTXCommDriver.java 800)
at gnu.io.CommPortIdentifier.open(CommPortIdentifier.java 343)
at PortTest (PortTest.java 37)
import gnu.io.*;
import java.util.*;
 
class PortTest
{
	public static void main(String args[])
	{
		try
		{
			String port = "/dev/cua/b";
			RXTXCommDriver gnuDriver = new RXTXCommDriver();
			CommPortIdentifier.addPortName(port,CommPortIdentifier.PORT_SERIAL, gnuDriver);
			CommPortIdentifier portId = CommPortIdentifier.getPortIdentifier(port);
			System.out.println();
			
			if (portId.getPortType() != CommPortIdentifier.PORT_SERIAL)
			{
				System.out.println("Not a Serial Port");
				return;
			}
			else
			{
				System.out.println("Serial Port");
			}
			
			SerialPort	serialPort = (SerialPort)portId.open("Test", 2000);
			System.out.println("Opened successfully");
			serialPort.close();
			System.out.println("Closed successfully");
		}
		catch(Exception exp)
		{
			exp.printStackTrace(System.out);
		}
	}
}

Open in new window

Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
> but then it should come out of that block or atleast throw some error right?

Thats correct, its not normal behaviour.
You probably wasting your time trying to guess what the problem is.

CERTIFIED EXPERT
Top Expert 2016

Commented:
Try ser2net

Author

Commented:
The problem is solved....
:-)

The problem was in the source code of the RXTX APIs.
It was not able to detect OS name & hence its throwing error.
I edited the source & hardcoded the OS name. that's it.

Thank you all.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.