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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? serialconnection.java

?? JAVA手機短信開發(fā)包
?? 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);
	    }
        }
    }
}

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日韩不卡手机在线v区| 国产亚洲一本大道中文在线| 一区二区三区在线观看动漫| 91性感美女视频| 亚洲成人午夜电影| 日韩精品一区二区三区swag | 欧美日韩在线直播| 亚洲国产欧美另类丝袜| 日韩一区和二区| 韩国精品久久久| 国产精品伦一区二区三级视频| 久久久久久久久久美女| 成人福利在线看| 亚洲女人的天堂| 欧美高清视频www夜色资源网| 午夜天堂影视香蕉久久| 精品久久久久久久久久久院品网| 国产乱人伦偷精品视频不卡| 亚洲欧美一区二区在线观看| 欧美精品丝袜久久久中文字幕| 久久99精品国产麻豆婷婷| 国产精品久久久久久户外露出| 一本色道久久综合狠狠躁的推荐 | 日本不卡一区二区三区| 久久久久久久电影| 色婷婷精品大视频在线蜜桃视频| 热久久久久久久| 欧美国产一区二区| 91精品国产品国语在线不卡| 成人黄色av网站在线| 日本少妇一区二区| 1024亚洲合集| 久久美女高清视频| 精品1区2区3区| 成人ar影院免费观看视频| 午夜伦欧美伦电影理论片| 久久久无码精品亚洲日韩按摩| 在线日韩av片| 国产精品亚洲综合一区在线观看| 亚洲一区在线视频| 国产日韩三级在线| 欧美精品在欧美一区二区少妇| 成熟亚洲日本毛茸茸凸凹| 日日摸夜夜添夜夜添国产精品| 亚洲国产精品精华液ab| 91精品国产综合久久久蜜臀粉嫩| 不卡的看片网站| 国产一区二区视频在线播放| 日日骚欧美日韩| 亚洲精品第1页| 欧美国产精品专区| 精品日韩在线观看| 7777精品伊人久久久大香线蕉最新版| 不卡电影一区二区三区| 国产精品一二三在| 国产伦精品一区二区三区在线观看 | 不卡的av中国片| 另类调教123区| 亚洲高清在线视频| 一二三四社区欧美黄| 国产精品高潮呻吟久久| 久久影院视频免费| 欧美成人福利视频| 91精品免费在线观看| 欧美日韩高清一区二区不卡| 91碰在线视频| 91亚洲永久精品| 91无套直看片红桃| 成人av在线观| bt7086福利一区国产| 丁香婷婷综合网| 高清久久久久久| 国产成人av福利| 在线成人av影院| 在线观看视频91| 欧美专区在线观看一区| 91行情网站电视在线观看高清版| 成人av免费观看| 91天堂素人约啪| 在线中文字幕不卡| 欧美在线色视频| 91精品国产综合久久国产大片 | 久草精品在线观看| 激情图区综合网| 国产永久精品大片wwwapp| 国产伦理精品不卡| 成人黄色软件下载| 91极品视觉盛宴| 欧美日韩激情在线| 日韩午夜在线影院| 精品国产sm最大网站免费看| 国产日产欧美一区二区视频| 国产精品美女久久久久aⅴ国产馆| 国产精品久久精品日日| 一区二区三区四区不卡在线 | av中文一区二区三区| 一本色道**综合亚洲精品蜜桃冫 | 日韩专区欧美专区| 久久99国产精品久久99| 不卡的电视剧免费网站有什么| 色婷婷亚洲综合| 日韩欧美区一区二| 中文字幕不卡的av| 亚洲第一av色| 国产剧情一区二区| 一本大道久久a久久精二百| 69久久99精品久久久久婷婷| 欧美mv日韩mv国产网站app| 日本一区二区免费在线观看视频| 亚洲视频免费观看| 日本欧美加勒比视频| 国产99精品国产| 欧美三级三级三级| 国产亚洲精品久| 亚洲123区在线观看| 粉嫩高潮美女一区二区三区| 欧美无乱码久久久免费午夜一区| 2020国产成人综合网| 一区二区三区在线观看视频| 国产一区福利在线| 欧美日韩高清一区二区| 国产精品乱人伦| 麻豆精品一区二区| 色域天天综合网| 久久久av毛片精品| 午夜久久久影院| 97精品久久久久中文字幕 | 一区二区三区日韩精品视频| 久久国产剧场电影| 色哟哟国产精品| 国产亚洲短视频| 另类小说综合欧美亚洲| 色噜噜狠狠一区二区三区果冻| 欧美精品一区二区三区久久久| 亚洲精品视频免费看| 国产成人av电影在线| 欧美一级欧美一级在线播放| 亚洲精品一卡二卡| 国产成人精品免费网站| 欧美一区二区网站| 色综合久久中文字幕综合网 | 成人黄色在线视频| 精品国产99国产精品| 日韩电影在线看| 色综合激情五月| 国产精品久久久久久久久果冻传媒| 精品一区精品二区高清| 欧美挠脚心视频网站| 亚洲精品自拍动漫在线| 国产精品99久| www亚洲一区| 蜜桃av一区二区三区| 在线电影欧美成精品| 一区二区在线观看视频在线观看| 成人综合婷婷国产精品久久蜜臀| 久久久久久电影| 国产在线不卡一卡二卡三卡四卡| 日韩欧美国产一区在线观看| 日韩精品一区第一页| 欧美日韩大陆在线| 亚洲妇熟xx妇色黄| 欧美久久久久久久久中文字幕| 亚洲综合自拍偷拍| 欧美日韩精品一区视频| 亚洲午夜私人影院| 欧美久久久久久久久久| 午夜精品久久久久久不卡8050 | 欧美精品久久久久久久多人混战 | 欧美v日韩v国产v| 玖玖九九国产精品| 精品美女在线播放| 激情丁香综合五月| 91在线观看成人| 日本韩国一区二区三区视频| 欧美天堂一区二区三区| 午夜精品一区二区三区电影天堂 | 免费成人av在线| 日韩一区二区视频| 青青草97国产精品免费观看无弹窗版| 欧美日韩一区二区三区四区| 午夜电影久久久| 欧美成人aa大片| 国产成人亚洲综合色影视| 日本一区二区三级电影在线观看| 成人污污视频在线观看| 国产精品高潮久久久久无| 色呦呦日韩精品| 免费国产亚洲视频| 国产欧美一区二区三区网站| 色综合久久综合网欧美综合网 | 91精品国产全国免费观看| 精品一区二区成人精品| 国产精品美女一区二区三区| 欧美在线色视频| 日本特黄久久久高潮| 国产清纯在线一区二区www| 91国偷自产一区二区三区观看| 日韩国产精品久久久久久亚洲| 欧美成人乱码一区二区三区| www.综合网.com|