Ⅰ java 杩愯宻etSerialPortParams镞惰鍗′綇
链杩戝湪浣跨敤rxtx缂栧啓涓插彛绋嫔簭锛屾垜涔熼亣鍒拌繖涓闂棰樸备絾濂囨涔嫔勫湪浜庯纴鍦╡clipse涓阃氲繃寮曞叆RXTXcomm.jar鍖呭拰鎸囧畾鍏秐ative lib杩愯屽苟镞犻梾棰樸傚綋鎶婂伐绋媏xport涓箦ar鍖呮椂锛岀洿鎺ヨ繍琛宩ar鍖呭垯鍑虹幇浜嗙▼搴忔绘帀镄勬儏鍐碉纴钖庡畾浣嶅埌鍦ㄦ墽琛宺xtx setserialportparams镞剁▼搴忔棤娉曞线涓嬭繘琛屻傚湪command绐楀彛杩愯宩ar鍙戠幇锛岀獥鍙e嚭鐜颁简濡备笅鎻愮ず锛
WARNING: RXTX Version mismatch
Jar version = RXTX-2.2pre1
native lib Version = RXTX-2.1-7pre16
钥屽湪eclipse涓杩愯屽苟娌℃湁鍑虹幇璇ユ彁绀恒傚埯姝ュ垽鏂搴旇ユ槸RXTXcomm.jar鍖呬笌锷犺浇镄刣ll涓嶅尮閰嶃傞氲繃灏嗘g‘鐗堟湰镄刣ll瑕嗙洊铡焏ll锛屽嬬粓鍑虹幇涓婅堪闂棰桡纴涓嶆槑锏戒负浠涔堟棤娉曞姞杞芥柊镄刣ll鐗堟湰锛屽ソ镀忕郴缁熸浘缁忓姞杞借繃dll钖庡氨涓嶅啀閲嶆柊锷犺浇dll銆
𨱍冲埌阃氲繃閲嶅惎鐢佃剳锛屾槸涓嶆槸灏卞彲浠ヤ简銆备絾浠岖劧娌℃湁鏁堟灉銆伞伞
镞㈢劧绯荤粺涓嶈兘锷犺浇鎴戞兂瑕佺殑dll锛岄偅鎴戝湪绋嫔簭涓镊宸卞姞杞斤纴涓岖煡阆揿彲涓嶅彲琛屻傝瘯镌鍦ㄧ▼搴忕殑寮濮嫔姞鍏ヤ简杩欎釜绋嫔簭锛
void loadrxtxdll(){
String basePath = this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
try {
basePath = URLDecoder.decode(basePath,"utf-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
System.out.println("basePaht:"+basePath);
if(basePath.endsWith(".jar")){
basePath = basePath.substring(0,basePath.lastIndexOf("/")+1);
}
File f = new File(basePath);
basePath = f.getAbsolutePath();
System.out.println(basePath);
System.load(basePath + "\\rxtxSerial.dll");
}
涓婅堪绋嫔簭鏄锷犺浇涓庣▼搴廽ar鍖呭悓璺寰勭殑rxtxSerial.dll锛屽皢dll𨰾疯礉鍒癹ar钖岃矾寰勪笅锛岃繍琛宩ar鍖咃纴鎴愬姛浜嗭紒
鐢辨ゅ彲瑙侊纴璇ユ柟娉曟湁鏁堛备絾涓嶆槑锏界殑鏄锛屼负浣旷▼搴忎笉鑳借嚜锷ㄥ姞杞芥柊镄刣ll銆