亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? serialconnection.java

?? java串口通訊api
?? JAVA
字號:
/* @(#)SerialConnection.java	1.6 98/07/17 SMI * * Copyright (c) 1998 Sun Microsystems, Inc. All Rights Reserved. * * Sun grants you ("Licensee") a non-exclusive, royalty free, license * to use, modify and redistribute this software in source and binary * code form, provided that i) this copyright notice and license appear * on all copies of the software; and ii) Licensee does not utilize the * software in a manner which is disparaging to Sun. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY * LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THE * SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS * BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, * HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING * OUT OF THE USE OF OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * This software is not designed or intended for use in on-line control * of aircraft, air traffic, aircraft navigation or aircraft * communications; or in the design, construction, operation or * maintenance of any nuclear facility. Licensee represents and * warrants that it will not use or redistribute the Software for such * purposes. */import javax.comm.*;import java.io.*;import java.awt.TextArea;import java.awt.event.*;import java.util.TooManyListenersException;/**A class that handles the details of a serial connection. Reads from one TextArea and writes to a second TextArea. Holds the state of the connection.*/public class SerialConnection implements SerialPortEventListener, 					 CommPortOwnershipListener {    private SerialDemo parent;    private TextArea messageAreaOut;    private TextArea messageAreaIn;    private SerialParameters parameters;    private OutputStream os;    private InputStream is;    private KeyHandler keyHandler;    private CommPortIdentifier portId;    private SerialPort sPort;    private boolean open;    /**    Creates a SerialConnection object and initilizes variables passed in    as params.    @param parent A SerialDemo object.    @param parameters A SerialParameters object.    @param messageAreaOut The TextArea that messages that are to be sent out    of the serial port are entered into.    @param messageAreaIn The TextArea that messages comming into the serial    port are displayed on.    */    public SerialConnection(SerialDemo parent,			    SerialParameters parameters,			    TextArea messageAreaOut,			    TextArea messageAreaIn) {	this.parent = parent;	this.parameters = parameters;	this.messageAreaOut = messageAreaOut;	this.messageAreaIn = messageAreaIn;	open = false;   }   /**   Attempts to open a serial connection and streams using the parameters   in the SerialParameters object. If it is unsuccesfull at any step it   returns the port to a closed state, throws a    <code>SerialConnectionException</code>, and returns.   Gives a timeout of 30 seconds on the portOpen to allow other applications   to reliquish the port if have it open and no longer need it.   */   public void openConnection() throws SerialConnectionException {	// Obtain a CommPortIdentifier object for the port you want to open.	try {	    portId = 		 CommPortIdentifier.getPortIdentifier(parameters.getPortName());	} catch (NoSuchPortException e) {	    throw new SerialConnectionException(e.getMessage());	}	// Open the port represented by the CommPortIdentifier object. Give	// the open call a relatively long timeout of 30 seconds to allow	// a different application to reliquish the port if the user 	// wants to.	try {	    sPort = (SerialPort)portId.open("SerialDemo", 30000);	} catch (PortInUseException e) {	    throw new SerialConnectionException(e.getMessage());	}	// Set the parameters of the connection. If they won't set, close the	// port before throwing an exception.	try {	    setConnectionParameters();	} catch (SerialConnectionException e) {		    sPort.close();	    throw e;	}	// Open the input and output streams for the connection. If they won't	// open, close the port before throwing an exception.	try {	    os = sPort.getOutputStream();	    is = sPort.getInputStream();	} catch (IOException e) {	    sPort.close();	    throw new SerialConnectionException("Error opening i/o streams");	}	// Create a new KeyHandler to respond to key strokes in the 	// messageAreaOut. Add the KeyHandler as a keyListener to the 	// messageAreaOut.	keyHandler = new KeyHandler(os);	messageAreaOut.addKeyListener(keyHandler);	// Add this object as an event listener for the serial port.	try {	    sPort.addEventListener(this);	} catch (TooManyListenersException e) {	    sPort.close();	    throw new SerialConnectionException("too many listeners added");	}	// Set notifyOnDataAvailable to true to allow event driven input.	sPort.notifyOnDataAvailable(true);	// Set notifyOnBreakInterrup to allow event driven break handling.	sPort.notifyOnBreakInterrupt(true);	// Set receive timeout to allow breaking out of polling loop during	// input handling.	try {	    sPort.enableReceiveTimeout(30);	} catch (UnsupportedCommOperationException e) {	}	// Add ownership listener to allow ownership event handling.	portId.addPortOwnershipListener(this);	open = true;    }    /**    Sets the connection parameters to the setting in the parameters object.    If set fails return the parameters object to origional settings and    throw exception.    */    public void setConnectionParameters() throws SerialConnectionException {	// Save state of parameters before trying a set.	int oldBaudRate = sPort.getBaudRate();	int oldDatabits = sPort.getDataBits();	int oldStopbits = sPort.getStopBits();	int oldParity   = sPort.getParity();	int oldFlowControl = sPort.getFlowControlMode();	// Set connection parameters, if set fails return parameters object	// to original state.	try {	    sPort.setSerialPortParams(parameters.getBaudRate(),				      parameters.getDatabits(),				      parameters.getStopbits(),				      parameters.getParity());	} catch (UnsupportedCommOperationException e) {	    parameters.setBaudRate(oldBaudRate);	    parameters.setDatabits(oldDatabits);	    parameters.setStopbits(oldStopbits);	    parameters.setParity(oldParity);	    throw new SerialConnectionException("Unsupported parameter");	}	// Set flow control.	try {	    sPort.setFlowControlMode(parameters.getFlowControlIn() 			           | parameters.getFlowControlOut());	} catch (UnsupportedCommOperationException e) {	    throw new SerialConnectionException("Unsupported flow control");	}    }    /**    Close the port and clean up associated elements.    */    public void closeConnection() {	// If port is alread closed just return.	if (!open) {	    return;	}	// Remove the key listener.	messageAreaOut.removeKeyListener(keyHandler);	// Check to make sure sPort has reference to avoid a NPE.	if (sPort != null) {	    try {		// close the i/o streams.	    	os.close();	    	is.close();	    } catch (IOException e) {		System.err.println(e);	    }	    // Close the port.	    sPort.close();	    // Remove the ownership listener.	    portId.removePortOwnershipListener(this);	}	open = false;    }    /**    Send a one second break signal.    */    public void sendBreak() {	sPort.sendBreak(1000);    }    /**    Reports the open status of the port.    @return true if port is open, false if port is closed.    */    public boolean isOpen() {	return open;    }    /**    Handles SerialPortEvents. The two types of SerialPortEvents that this    program is registered to listen for are DATA_AVAILABLE and BI. During     DATA_AVAILABLE the port buffer is read until it is drained, when no more    data is availble and 30ms has passed the method returns. When a BI    event occurs the words BREAK RECEIVED are written to the messageAreaIn.    */    public void serialEvent(SerialPortEvent e) { 	// Create a StringBuffer and int to receive input data.	StringBuffer inputBuffer = new StringBuffer();	int newData = 0;	// Determine type of event.	switch (e.getEventType()) {	    // Read data until -1 is returned. If \r is received substitute	    // \n for correct newline handling.	    case SerialPortEvent.DATA_AVAILABLE:		    while (newData != -1) {		    	try {		    	    newData = is.read();			    if (newData == -1) {				break;			    }			    if ('\r' == (char)newData) {			   	inputBuffer.append('\n');			    } else {			    	inputBuffer.append((char)newData);			    }		    	} catch (IOException ex) {		    	    System.err.println(ex);		    	    return;		      	}   		    }		// Append received data to messageAreaIn.		messageAreaIn.append(new String(inputBuffer));		break;	    // If break event append BREAK RECEIVED message.	    case SerialPortEvent.BI:		messageAreaIn.append("\n--- BREAK RECEIVED ---\n");	}    }       /**    Handles ownership events. If a PORT_OWNERSHIP_REQUESTED event is    received a dialog box is created asking the user if they are     willing to give up the port. No action is taken on other types    of ownership events.    */    public void ownershipChange(int type) {	if (type == CommPortOwnershipListener.PORT_OWNERSHIP_REQUESTED) {	    PortRequestedDialog prd = new PortRequestedDialog(parent);	}    }    /**    A class to handle <code>KeyEvent</code>s generated by the messageAreaOut.    When a <code>KeyEvent</code> occurs the <code>char</code> that is     generated by the event is read, converted to an <code>int</code> and     writen to the <code>OutputStream</code> for the port.    */    class KeyHandler extends KeyAdapter {	OutputStream os;	/**	Creates the KeyHandler.	@param os The OutputStream for the port.	*/	public KeyHandler(OutputStream os) {	    super();	    this.os = os;	}	/**	Handles the KeyEvent.	Gets the <code>char</char> generated by the <code>KeyEvent</code>,	converts it to an <code>int</code>, writes it to the <code>	OutputStream</code> for the port.	*/        public void keyTyped(KeyEvent evt) {            char newCharacter = evt.getKeyChar();	    try {	    	os.write((int)newCharacter);	    } catch (IOException e) {		System.err.println("OutputStream write error: " + e);	    }        }    }}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
久久久久久一二三区| 91成人免费网站| 成人小视频免费观看| 3d成人动漫网站| 亚洲毛片av在线| 高清不卡在线观看| 欧美吻胸吃奶大尺度电影 | 91久久精品一区二区三区| 国产一区在线精品| 91精品1区2区| 久久综合国产精品| 美女在线视频一区| 欧美色网站导航| 专区另类欧美日韩| 成人精品视频一区| 久久久国际精品| 国产一区三区三区| 欧美大片一区二区三区| 亚洲成a人v欧美综合天堂下载| 91污在线观看| 亚洲色图欧美激情| av综合在线播放| 国产精品福利在线播放| 不卡电影一区二区三区| 国产精品免费免费| 国产精品1024| 欧美国产日韩亚洲一区| 成人激情视频网站| 成人免费在线播放视频| 色综合色狠狠天天综合色| 亚洲日本在线a| 亚洲一区二区高清| 99久久99久久久精品齐齐| 国产亚洲成av人在线观看导航| 久久99国产精品尤物| 精品国产一区二区在线观看| 精品一区二区免费看| 精品粉嫩超白一线天av| 国产激情91久久精品导航| 国产日产欧美一区| a美女胸又www黄视频久久| 亚洲精品国产精品乱码不99| 欧美写真视频网站| 美洲天堂一区二卡三卡四卡视频| 欧美一区二区精美| 久久草av在线| 国产精品色一区二区三区| 95精品视频在线| 天堂资源在线中文精品| 欧美日韩高清一区二区三区| 亚洲自拍偷拍九九九| 欧美色倩网站大全免费| 美女在线视频一区| 国产色综合久久| 欧美性猛片xxxx免费看久爱| 日本不卡视频在线观看| 久久久噜噜噜久久人人看| www.成人在线| 日韩成人午夜精品| 亚洲国产激情av| 欧美日产国产精品| 国产黑丝在线一区二区三区| 亚洲美女在线国产| 欧美一卡二卡三卡| 99久久久精品| 丰满白嫩尤物一区二区| 欧美日韩精品一区二区| 国产成人自拍网| 成人欧美一区二区三区视频网页| 欧美色图12p| 国产不卡视频一区| 亚洲成av人片在线| 欧美一区二区三区四区久久| 麻豆一区二区99久久久久| 亚洲欧洲另类国产综合| 日韩一区二区免费视频| 99久久精品国产一区二区三区| 日产国产欧美视频一区精品 | 国产成人免费视频一区| 亚洲综合网站在线观看| 国产精品伦理一区二区| 日韩一级视频免费观看在线| 一本色道久久综合亚洲aⅴ蜜桃 | 成人av在线一区二区| 蜜桃久久精品一区二区| 亚洲综合丝袜美腿| 一区在线观看视频| 久久久精品日韩欧美| 欧美一区二区高清| 欧美日韩在线不卡| 色狠狠一区二区三区香蕉| 国产成人综合在线观看| 久久99精品国产麻豆婷婷| 亚洲妇女屁股眼交7| 亚洲欧美日韩电影| 国产区在线观看成人精品| 精品久久久久久亚洲综合网 | 91福利社在线观看| 99久久精品免费精品国产| 懂色av一区二区夜夜嗨| 狠狠色综合播放一区二区| 蜜臀久久99精品久久久久宅男| 亚洲一区二区三区美女| 一区二区在线观看视频在线观看| 日韩一区二区在线看| 国产精品视频看| 久久久三级国产网站| 精品日韩在线一区| 精品久久99ma| 精品噜噜噜噜久久久久久久久试看| 欧美电影在线免费观看| 欧美夫妻性生活| 欧美一区二区三区免费在线看| 欧美福利电影网| 日韩欧美色综合网站| 欧美成人乱码一区二区三区| 欧美哺乳videos| 久久色在线视频| 国产精品久久久久影院亚瑟| 国产精品全国免费观看高清| 国产精品久久久久久久久免费桃花 | 99视频精品全部免费在线| 丁香六月久久综合狠狠色| 成人蜜臀av电影| 97久久久精品综合88久久| 色悠悠久久综合| 色吊一区二区三区| 91精品在线麻豆| 精品国产一区二区国模嫣然| 欧美激情一区二区三区在线| 亚洲色图欧美在线| 日韩精品五月天| 极品美女销魂一区二区三区免费 | 国产精品第五页| 亚洲国产毛片aaaaa无费看| 日本系列欧美系列| 国产一区二区三区免费| 99免费精品在线| 欧美精品第1页| 久久久国产午夜精品| 亚洲激情五月婷婷| 精品一区二区三区视频 | 国产成人av在线影院| 91毛片在线观看| 欧美成人在线直播| 中文字幕一区在线观看| 日本不卡不码高清免费观看| 懂色中文一区二区在线播放| 欧美色手机在线观看| 国产欧美一区二区精品性| 亚洲制服丝袜一区| 国产精品中文字幕欧美| 在线看一区二区| 久久在线观看免费| 午夜亚洲国产au精品一区二区| 国产精品一二三在| 欧美情侣在线播放| 亚洲品质自拍视频| 国产精品一区二区在线看| 欧美日韩国产色站一区二区三区| 精品国产一区二区三区久久久蜜月| 一区二区三区在线观看国产| 国产很黄免费观看久久| 7777女厕盗摄久久久| 亚洲精品你懂的| 成人一区在线观看| 久久综合九色欧美综合狠狠| 午夜伦理一区二区| 99久久精品一区二区| 国产情人综合久久777777| 美国十次了思思久久精品导航| 色婷婷亚洲精品| 亚洲欧美在线另类| 国产不卡视频在线观看| 久久综合av免费| 老司机精品视频线观看86| 欧美日韩夫妻久久| 亚洲午夜久久久久久久久久久 | 国产成人av一区二区三区在线观看| 欧美精品乱码久久久久久按摩| 亚洲欧美日韩国产中文在线| 成人小视频在线| 亚洲国产精华液网站w| 国产精品亚洲一区二区三区妖精| 日韩亚洲欧美成人一区| 日韩黄色一级片| 在线播放亚洲一区| 亚洲国产一二三| 91豆麻精品91久久久久久| 亚洲女同女同女同女同女同69| 处破女av一区二区| 久久久久国产一区二区三区四区 | 日韩欧美中文字幕精品| 午夜久久久久久电影| 欧美日韩不卡视频| 男女男精品视频| 国产精品国产成人国产三级| 成人三级在线视频| 亚洲色图在线视频| 欧美亚洲免费在线一区|