資源簡(jiǎn)介
rxtx可以跨系統(tǒng),可以在32和64位jdk上通過(guò)com通訊

代碼片段和文件信息
package?com.serial;
import?gnu.io.*;
import?java.io.*;
import?java.util.*;
import?org.apache.commons.logging.Log;
import?org.apache.commons.logging.LogFactory;
/**
?*?作用:?串口讀寫數(shù)據(jù)(底層)
?*?①串口文件位置放置:?rxtxSerial.dll?放在%java_home%\bin下
?*?②類使用介紹: 初始化:getInstance->setPortName->initialize
?*? 打開串口:openPort
?* 讀寫數(shù)據(jù):writePort->readPackData
?* 關(guān)閉串口:ClosePort
?* 枚舉全部串口名稱:getAllComPorts
?*?注意事項(xiàng):?無(wú)
?*/
public?class?Level_Final_Serial?{
/**
?*?數(shù)據(jù)包長(zhǎng)度
?*/
public?static?final?int?PACKET_LENGTH?=?500;
private?Log?log?=?LogFactory.getLog(Level_Final_Serial.class);
public?static?Level_Final_Serial?final_Level;
SerialPort?serialPort;
CommPortIdentifier?identifier;
String?PortName; //?串口名.如:COM3
OutputStream?out; //?串口輸出流
InputStream?in; //?串口輸入流
String?appname?=?“SerialBean“;? //?程序名
int?timeOut;? //?延遲時(shí)間(毫秒數(shù))
int?baudrate;? //?波特率
int?dataBits;? //?數(shù)據(jù)位
int?stopBits;? //?停止位
int?parity;? //?奇偶檢驗(yàn)
/**
?*?@describe:?獲取SerialBeanl類單例
?*?@date:2009-11-5
?*/
public?static?Level_Final_Serial?getInstance()?{
if?(final_Level?==?null)?{
final_Level?=?new?Level_Final_Serial();
}
return?final_Level;
}
/**
?*?構(gòu)造函數(shù)
?*/
public?Level_Final_Serial()?{
}
/**
?*?@describe:?設(shè)置?串口程序名
?*?@date:2010-3-2
?*/
public?void?setAppname(String?appname)?{
this.appname?=?appname;
}
/**
?*?@describe:?初始化類
?*?@param?timeOut??等待時(shí)間
?*?@param?baudrate 波特率
?*?@param?dataBits 數(shù)據(jù)位
?*?@param?stopBits 停止位
?*?@param?parity 奇偶檢驗(yàn)
?*?@date:2009-11-5
?*/
public?void?initialize(int?timeOut?int?baudrate?int?dataBits?int?stopBits?int?parity)?{
this.timeOut?=?timeOut;
this.baudrate?=?baudrate;
this.dataBits?=?dataBits;
this.stopBits?=?stopBits;
this.parity?=?parity;
}
/**
?*?@describe:?初始化串口詳細(xì)信息
?*?@return?true?:?初始化串口成功?false:?初始化串口失敗?
?*?@date:2009-11-5
?*/
public?boolean?openPort(String?portName)?{
boolean?rsBool?=?false;
this.PortName?=?portName;
try?{
//獲取串口
identifier?=?getCommPort();
if?(identifier?==?null)?{
//?null
}?else?{
if?(identifier.isCurrentlyOwned()){
log.info(PortName+?“:?串口已經(jīng)被“?+?identifier.getCurrentOwner()+?“占用...“);
}else{
//?open方法打開通訊端口
serialPort?=?(SerialPort)?identifier.open(appname?timeOut);
//?獲取端口的輸入輸出流對(duì)象?
in?=?serialPort.getInputStream();
out?=?serialPort.getOutputStream();
//?設(shè)置串口初始化參數(shù),依次是波特率,數(shù)據(jù)位,停止位和校驗(yàn)?
serialPort.setSerialPortParams(baudrate?dataBits?stopBits?parity);
serialPort.setDTR(true);
serialPort.setRTS(true);
rsBool?=?true;
}
}
}?catch?(PortInUseException?e)?{
log.info(PortName+?“:?串口已經(jīng)被“?+?identifier.getCurrentOwner()+?“占用...“);
}?catch?(Exception?e)?{
log.info(PortName+?“--初始化串口出錯(cuò):“?+?e.toString());
}
return?rsBool;
}
/**
?*?@describe:?列舉并得到需要用串口
?*?@date:2009-11-5
?*/
public
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件????????939??2014-10-23?14:25??使用rxtx通過(guò)短信貓發(fā)送短信\Java1\.classpath
?????文件????????381??2014-10-23?08:46??使用rxtx通過(guò)短信貓發(fā)送短信\Java1\.project
?????文件????????629??2014-10-23?08:46??使用rxtx通過(guò)短信貓發(fā)送短信\Java1\.settings\org.eclipse.jdt.core.prefs
?????文件???????4968??2014-10-23?14:25??使用rxtx通過(guò)短信貓發(fā)送短信\Java1\bin\com\serial\Level_Final_Serial.class
?????文件???????3500??2014-10-23?14:25??使用rxtx通過(guò)短信貓發(fā)送短信\Java1\bin\com\serial\Serial_For_Smslib.class
?????文件???????3793??2014-10-23?14:25??使用rxtx通過(guò)短信貓發(fā)送短信\Java1\bin\com\serial\SmsSendJob.class
?????文件???????1051??2014-10-23?14:25??使用rxtx通過(guò)短信貓發(fā)送短信\Java1\bin\com\serial\SmsService$CallNotification.class
?????文件???????1378??2014-10-23?14:25??使用rxtx通過(guò)短信貓發(fā)送短信\Java1\bin\com\serial\SmsService$GatewayStatusNotification.class
?????文件???????1889??2014-10-23?14:25??使用rxtx通過(guò)短信貓發(fā)送短信\Java1\bin\com\serial\SmsService$InboundNotification.class
?????文件???????1177??2014-10-23?14:25??使用rxtx通過(guò)短信貓發(fā)送短信\Java1\bin\com\serial\SmsService$OrphanedMessageNotification.class
?????文件???????1139??2014-10-23?14:25??使用rxtx通過(guò)短信貓發(fā)送短信\Java1\bin\com\serial\SmsService$OutboundNotification.class
?????文件???????5666??2014-10-23?14:25??使用rxtx通過(guò)短信貓發(fā)送短信\Java1\bin\com\serial\SmsService.class
?????文件???????5108??2014-10-23?08:46??使用rxtx通過(guò)短信貓發(fā)送短信\Java1\src\com\serial\Level_Final_Serial.java
?????文件???????4446??2014-10-23?09:05??使用rxtx通過(guò)短信貓發(fā)送短信\Java1\src\com\serial\Serial_For_Smslib.java
?????文件???????4761??2014-10-23?15:49??使用rxtx通過(guò)短信貓發(fā)送短信\Java1\src\com\serial\SmsSendJob.java
?????文件???????4768??2014-10-23?09:59??使用rxtx通過(guò)短信貓發(fā)送短信\Java1\src\com\serial\SmsSendJob.java.bak
?????文件???????7812??2014-10-23?08:46??使用rxtx通過(guò)短信貓發(fā)送短信\Java1\src\com\serial\SmsService.java
?????文件??????60841??2014-10-23?08:43??使用rxtx通過(guò)短信貓發(fā)送短信\lib\commons-logging-1.1.1.jar
?????文件?????197316??2014-10-23?08:43??使用rxtx通過(guò)短信貓發(fā)送短信\lib\commons-net-2.0.jar
?????文件??????11246??2014-10-23?08:43??使用rxtx通過(guò)短信貓發(fā)送短信\lib\log4j-over-slf4j-1.5.10.jar
?????文件??????59464??2014-10-23?08:43??使用rxtx通過(guò)短信貓發(fā)送短信\lib\RXTXcomm.jar
?????文件??????23659??2014-10-23?08:43??使用rxtx通過(guò)短信貓發(fā)送短信\lib\slf4j-api-1.5.10.jar
?????文件???????8830??2014-10-23?08:43??使用rxtx通過(guò)短信貓發(fā)送短信\lib\slf4j-jdk14-1.5.10.jar
?????文件?????263196??2014-10-23?08:43??使用rxtx通過(guò)短信貓發(fā)送短信\lib\smslib-3.4.5.jar
?????文件?????223519??2014-10-23?14:10??使用rxtx通過(guò)短信貓發(fā)送短信\RXTX_lib_32_64.zip
?????文件?????????68??2014-10-23?15:48??使用rxtx通過(guò)短信貓發(fā)送短信\說(shuō)明.txt
?????目錄??????????0??2014-10-23?15:45??使用rxtx通過(guò)短信貓發(fā)送短信\Java1\bin\com\serial
?????目錄??????????0??2014-10-23?15:49??使用rxtx通過(guò)短信貓發(fā)送短信\Java1\src\com\serial
?????目錄??????????0??2014-10-23?15:45??使用rxtx通過(guò)短信貓發(fā)送短信\Java1\bin\com
?????目錄??????????0??2014-10-23?15:45??使用rxtx通過(guò)短信貓發(fā)送短信\Java1\src\com
............此處省略9個(gè)文件信息
評(píng)論
共有 條評(píng)論