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