Pages: [1]   Go Down
Author Topic: Java Serial Communication libraries  (Read 509 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all, i'm using Arduino since June 2011, now i built a Java program which can communicate with it. Everithing works perfectly.
To use rxtxSerial library i MUST place it in the java folder, i placed everithing in this folder and it works.
The fact is: i have to make my program work on ANY computer without having to place libraries in the Java folder, also because with new security rules in the newest Operating Systems i need to have permissions to access the programs folder.
So is there a way to load these libraries at runtime without placing them in the Java folder? i tried with System.load() and System.loadLibrary(), the path is correct, i verified it, but it does not work, it says "No suitable RXTXSerial found in java PATH"... Any suggestions?

Thanks in advance,
Alex
Logged

0
Offline Offline
Shannon Member
****
Karma: 132
Posts: 10498
:(){:|:&};:
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

you need to load 2 file: the .jar, taht is always the same for every os, AND the native, that vary based on witch OS you are using.

if you look on the internet you'll find many overcomplicated (and obsolete) solution.

normally for library path, a .sh (linux/mac) or a .bat is created, but youcan set it inside your program:
http://blog.cedarsoft.com/2010/11/setting-java-library-path-programmatically/


for the native actually i can't find a good snippet, i'll post mine when i'll be back home
Logged

sei nuovo? non sai da dove partire? leggi qui: http://playground.arduino.cc/Italiano/Newbie

0
Offline Offline
Shannon Member
****
Karma: 132
Posts: 10498
:(){:|:&};:
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

found!
i use this code to load lwjgl native, but it is practically the same used for RXTX (old code was in the old HDD.. rip)

just be sure to change the path and file name accordantly, and call this method on the constructor of the main class that you'll use for the serial communication.

Code:
private static void loadNatives() {
Logger staticLog = LoggerFactory.getLogger("Natives Loader");
staticLog.debug("Loading natives");
try {
String osName = System.getProperty("os.name");

staticLog.info("Operating system name => {}", osName);

File path = new File("Libraries" + File.separator + "lwjgl-2.8.3" + File.separator + "native" + File.separator + osName.toLowerCase());

System.setProperty("org.lwjgl.librarypath", path.getAbsolutePath());

} catch (UnsatisfiedLinkError e) {
staticLog.error("Native code library failed to load", e);
}
staticLog.info("Loaded natives");
}

uh, and remove logger code if give you error, maybe instead use System.out.println
« Last Edit: June 18, 2012, 03:09:10 pm by lesto » Logged

sei nuovo? non sai da dove partire? leggi qui: http://playground.arduino.cc/Italiano/Newbie

Pages: [1]   Go Up
Jump to: