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

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

?? serialconnection.java

?? 利用JAVA采用網絡通訊的例子,支持weblogic及websphere
?? JAVA
?? 第 1 頁 / 共 2 頁
字號:
package collector.communication;

/* @(#)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 m_InputStream disparaging to Sun.
 *
     * This software m_InputStream 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 m_InputStream 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 java.io.*;
import javax.comm.*;

import collector.common.*;

/**
 * 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, IComm {
  private SerialParameters m_SerialParameters = null;
  private OutputStream m_OutputStream = null;
  private InputStream m_InputStream = null;
  //private KeyHandler keyHandler;

  private CommPortIdentifier m_PortId = null;
  private SerialPort m_Port = null;
  private int m_PortNo = -1;

  private byte[] m_RecBuffer = null;
  private int m_RecNum = 0;

  private boolean m_Open = false;

  /**
   * Creates a SerialConnection object and initilizes variables passed in
   * as params.
   *
   * @param parent A SerialDemo object.
   * @param m_SerialParameters 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 m_SerialParameters
      /*TextArea messageAreaOut,
                           TextArea messageAreaIn*/) {
    /*	this.parent = parent;*/
    this.m_SerialParameters = m_SerialParameters;
    /*	this.messageAreaOut = messageAreaOut;
            this.messageAreaIn = messageAreaIn;
     */
    this.m_Open = false;
  }

  /**
   * Attempts to m_Open a serial connection and streams using the m_SerialParameters
   * in the SerialParameters object. If it m_InputStream 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 m_Open and no longer need it.
   */

  public int initConnection() {
    // Obtain a CommPortIdentifier object for the port you want to m_Open.
    //CollectorDefine.SystemPrintln ("  serial initConnnection start up!!!  ");
    CFunction.putHintString(1,
                            "aaa " + "端口號:" + m_SerialParameters.getPortName());

    try {
      this.m_PortId =
          CommPortIdentifier.getPortIdentifier(m_SerialParameters.getPortName());
    }
    catch (NoSuchPortException e) {
      //	    throw new ConnectionException(e.getMessage());
      CFunction.writeLog("initConnection In SerialConnection Error #1 " +
                         "port no:" + m_SerialParameters.getPortName(), e);
      return -1;
    }

    // Open the port represented by the CommPortIdentifier object. Give
    // the m_Open call a relatively long timeout of 30 seconds to allow
    // a different application to reliquish the port if the user
    // wants to.
    CFunction.putHintString(1,
                            "bbb " + "端口號:" + m_SerialParameters.getPortName());

    try {
      // wj modi at hangzhou 20040531
      //this.m_Port = (SerialPort) m_PortId.open("SerialDemo", 30000);

      // wj modi at nanjing 20040616
      //this.m_Port = (SerialPort) m_PortId.open(CFunction.getLocalHostName() + "_App", 30000);
      this.m_Port = (SerialPort) m_PortId.open(CFunction.getLocalHostName() +
                                               m_SerialParameters.getPortName() +
                                               "_App", 30000);
      // wj modi at nanjing 20040616

      // wj modi at hangzhou 20040531
    }
    catch (PortInUseException e) {
      //	    throw new ConnectionException(e.getMessage());
      CFunction.writeLog("initConnection In SerialConnection Error #2 " +
                         "port no:" + m_SerialParameters.getPortName(), e);

      // wj add
      // Close the port.
      this.m_Port.close();
      this.m_Open = false;
      //

      return -1;
    }

    // Set the m_SerialParameters of the connection. If they won't set, close the
    // port before throwing an exception.
    CFunction.putHintString(1,
                            "ddd " + "端口號:" + m_SerialParameters.getPortName());

    try {
      if (setConnectionParameters(this.m_SerialParameters) <= 0) {
        CFunction.writeLog("initConnection In SerialConnection Error #3 " +
                           "port no:" + m_SerialParameters.getPortName(), null);
        this.m_Port.close();
        this.m_Open = false;
        return -1;
      }
    }
    catch (Exception m_Exception) {
      CFunction.writeLog("initConnection In SerialConnection Error #4 " +
                         "port no:" + m_SerialParameters.getPortName(),
                         m_Exception);
      return -1;
    }

    // Open the input and output streams for the connection. If they won't
    // m_Open, close the port before throwing an exception.
    CFunction.putHintString(1,
                            "eee " + "端口號:" + m_SerialParameters.getPortName());

    try {
      this.m_OutputStream = m_Port.getOutputStream();
      CFunction.putHintString(1,
                              "fff " + "端口號:" + m_SerialParameters.getPortName());

      this.m_InputStream = m_Port.getInputStream();
    }
    catch (IOException e) {
      this.m_Port.close();
      this.m_Open = false;
      //	    throw new ConnectionException("Error opening i/o streams");
      CFunction.writeLog("initConnection In SerialConnection Error #5 " +
                         "port no:" + m_SerialParameters.getPortName(), e);
      return -1;
    }

    // Create a new KeyHandler to respond to key strokes in the
    // messageAreaOut. Add the KeyHandler as a keyListener to the
    // messageAreaOut.
    /*	keyHandler = new KeyHandler(m_OutputStream);
            messageAreaOut.addKeyListener(keyHandler);
     */
    // Add this object as an event listener for the serial port.
    /*try
                 {
          m_Port.addEventListener(this);
                 }
                 catch (TooManyListenersException e)
                 {
          m_Port.close();
          //	    throw new ConnectionException("too many listeners added");
          CFunction.putHintString(1,"端口監聽器太多 " +  "端口號:" + m_SerialParameters.getPortName());
          return -1;
                 }
     */
    // Set notifyOnDataAvailable to true to allow event driven input.
    //	m_Port.notifyOnDataAvailable(true);

    // Set notifyOnBreakInterrup to allow event driven break handling.
    //	m_Port.notifyOnBreakInterrupt(true);

    // wj del at hangzhou 20040531
    // Set receive timeout to allow breaking out of polling loop during
    // input handling.
    /*try {
      this.m_Port.enableReceiveTimeout(60);
         }
         catch (UnsupportedCommOperationException e) {
      CFunction.putHintString(1,
          "setConnectionParameters In SerialConnection Error #2 ");
      return -1;
         }
     */
    // wj del at hangzhou 20040531

    // Add ownership listener to allow ownership event handling.
    //	m_PortId.addPortOwnershipListener(this);

    m_Open = true;
    CFunction.putHintString(1,
                            "ggg " + "端口號:" + m_SerialParameters.getPortName());

    return 1;
  }

  /**
   * Sets the connection m_SerialParameters to the setting in the m_SerialParameters object.
       * If set fails return the m_SerialParameters object to origional settings and
   * throw exception.
   */
  public int setConnectionParameters(SerialParameters m_SerialParameters) {
    // Save state of m_SerialParameters before trying a set.
    //CollectorDefine.SystemPrintln ("fffffffff : " + m_SerialParameters.toString ());
    int oldBaudRate = m_Port.getBaudRate();
    int oldDatabits = m_Port.getDataBits();
    int oldStopbits = m_Port.getStopBits();
    int oldParity = m_Port.getParity();
    int oldFlowControl = m_Port.getFlowControlMode();

    //CollectorDefine.SystemPrintln ("gggggggg : " + m_SerialParameters.toString ());
    this.m_SerialParameters = m_SerialParameters;
    //CollectorDefine.SystemPrintln ("hhhhhhhhh : " + m_SerialParameters.toString ());

    // Set connection m_SerialParameters, if set fails return m_SerialParameters object
    // to original state.
    try {
      m_Port.setSerialPortParams(m_SerialParameters.getBaudRate(),
                                 m_SerialParameters.getDatabits(),
                                 m_SerialParameters.getStopbits(),
                                 m_SerialParameters.getParity());
      //CollectorDefine.SystemPrintln ("iiiiii : " + m_SerialParameters.toString ());
    }
    catch (UnsupportedCommOperationException e) {
      //CollectorDefine.SystemPrintln ("jjjjjjjjj : " + m_SerialParameters.toString ());
      this.m_SerialParameters.setBaudRate(oldBaudRate);
      this.m_SerialParameters.setDatabits(oldDatabits);
      this.m_SerialParameters.setStopbits(oldStopbits);
      this.m_SerialParameters.setParity(oldParity);
      CFunction.writeLog(
          "setConnectionParameters In SerialConnection Error #1 " + "port no:" +
          m_SerialParameters.getPortName(), e);
      return -1;
    }

    // wj del at hangzhou 20040531
    /*
         // Set flow control.
         try {
      //CollectorDefine.SystemPrintln ("kkkkkkkkkk : " + m_SerialParameters.toString ());
      m_Port.setFlowControlMode(m_SerialParameters.getFlowControlIn()
                                | m_SerialParameters.getFlowControlOut());
         }
         catch (UnsupportedCommOperationException e) {
      //	    throw new ConnectionException("Unsupported flow control");
      CFunction.putHintString(1,
                              "端口流控制參數不支持 " + "端口號:" +
                              m_SerialParameters.getPortName());
      return -1;
         }
     */
    // wj modi at hangzhou 20040531

    //CollectorDefine.SystemPrintln ("lllllll : " + m_SerialParameters.toString ());
    return 1;
  }

  /**
   * Close the port and clean up associated elements.
   */
  public int closeConnection() {
    // If port m_InputStream alread closed just return.
    CFunction.putHintString(1,
                            "hhh " + "端口號:" + m_SerialParameters.getPortName());

    if (!m_Open) {
      CFunction.writeLog("closeConnection In SerialConnection Error #1 " +
                         "port no:" + m_SerialParameters.getPortName(), null);
      return -1;
    }

    // Remove the key listener.
    /*messageAreaOut.removeKeyListener(keyHandler);*/
    // Check to make sure m_Port has reference to avoid a NPE.
    if (m_Port != null) {
      try {
        CFunction.putHintString(1,
                                "iii " + "端口號:" +
                                m_SerialParameters.getPortName());

        //close the i/o streams.
        //m_InputStream.reset ();
        m_OutputStream.close();
        m_InputStream.close();

        //close the port.
        m_Port.close();

        // wj add at hangzhou 20040531
        m_OutputStream = null;
        m_InputStream = null;
        m_Port = null;
        // wj add at hangzhou 20040531
      }
      catch (IOException e) {
        CFunction.writeLog("closeConnection In SerialConnection Error #2 " +
                           "port no:" + m_SerialParameters.getPortName(), e);
        return -1;
      }

      // Remove the ownership listener.
      //m_PortId.removePortOwnershipListener(this);
    }

    m_Open = false;
    CFunction.putHintString(1,
                            "jjj " + "端口號:" + m_SerialParameters.getPortName());

    return 1;
  }

  /**
   * Send a one second break signal.
   */
  public int sendBreak() {
    m_Port.sendBreak(1000);

    return 1;
  }

  /**
   * Reports the m_Open status of the port.
       * @return true if port m_InputStream m_Open, false if port m_InputStream closed.
   */
  public boolean isConnectionOpen() {
    return m_Open;
  }

  /**
   * Handles SerialPortEvents. The two types of SerialPortEvents that this
   * program m_InputStream registered to listen for are DATA_AVAILABLE and BI. During
   * DATA_AVAILABLE the port buffer m_InputStream read until it m_InputStream drained, when no more
       * data m_InputStream 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 m_InputStream returned. If \r m_InputStream received substitute
      // \n for correct newline handling.
      case SerialPortEvent.DATA_AVAILABLE:
        while (newData != -1) {

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
极品少妇一区二区三区精品视频| 国产一区二区调教| 乱一区二区av| 91在线porny国产在线看| 日韩一区二区精品葵司在线| 国产精品国产三级国产aⅴ原创 | 国产精品99精品久久免费| 91福利小视频| 国产精品免费aⅴ片在线观看| 丝袜诱惑亚洲看片| 在线亚洲一区观看| 国产精品毛片大码女人| 精品一区二区三区免费毛片爱 | 成人国产视频在线观看| 欧美一区中文字幕| 亚洲妇女屁股眼交7| 99久久精品99国产精品| 久久久久国色av免费看影院| 亚洲h在线观看| 欧美体内she精高潮| 最近中文字幕一区二区三区| 风间由美一区二区av101| 日韩欧美一二三| 久久99久久久久| 日韩视频在线一区二区| 日本最新不卡在线| 欧美日韩电影一区| 日韩 欧美一区二区三区| 69堂国产成人免费视频| 丝袜美腿亚洲综合| 宅男噜噜噜66一区二区66| 午夜精品福利视频网站| 欧美精品1区2区3区| 香蕉加勒比综合久久| 欧美巨大另类极品videosbest | 亚洲黄色尤物视频| 91在线免费看| 亚洲最大的成人av| 色域天天综合网| 亚洲a一区二区| 91麻豆精品国产91| 精品一区二区三区在线观看| 精品国产乱码久久久久久1区2区| 国产麻豆午夜三级精品| 欧美国产成人精品| 色综合亚洲欧洲| 亚洲国产精品一区二区久久恐怖片| 色婷婷香蕉在线一区二区| 亚洲精品高清在线| 91精品国产一区二区| 精品一区二区免费看| 亚洲国产精品成人综合 | 亚洲视频在线一区| 91国产精品成人| 免费成人av资源网| 中文欧美字幕免费| 91成人看片片| 理论片日本一区| 中文字幕av一区 二区| 日本国产一区二区| 奇米一区二区三区av| 国产亚洲精品超碰| 欧美亚洲综合另类| 国产精品影音先锋| 亚洲在线观看免费视频| 日韩欧美国产一区二区在线播放| 国产黄色成人av| 亚洲成人免费视频| 国产欧美精品国产国产专区| 91福利视频久久久久| 久久国产精品72免费观看| 亚洲丝袜自拍清纯另类| 欧美xxxx在线观看| 欧美综合天天夜夜久久| 国产一区二区美女诱惑| 亚洲香肠在线观看| 国产精品―色哟哟| 日韩欧美一级片| 欧美伊人久久久久久久久影院 | 成人性生交大片| 天天操天天综合网| 亚洲天堂av一区| 337p粉嫩大胆噜噜噜噜噜91av | 欧美调教femdomvk| 成人av电影在线| 国产在线精品一区在线观看麻豆| 综合婷婷亚洲小说| 国产亚洲1区2区3区| 51精品秘密在线观看| 99视频精品全部免费在线| 美女网站视频久久| 亚洲丰满少妇videoshd| 最新不卡av在线| 中文字幕第一区第二区| 欧美成人福利视频| 欧美日韩一区二区电影| 91免费小视频| 99在线精品一区二区三区| 久草中文综合在线| 日韩电影在线免费| 首页亚洲欧美制服丝腿| 一区二区三区不卡在线观看| 国产精品久久久久桃色tv| 337p日本欧洲亚洲大胆精品| 日韩视频永久免费| 欧美日本在线播放| 欧美日韩免费不卡视频一区二区三区| av成人老司机| 99精品欧美一区二区蜜桃免费 | 欧美日韩精品久久久| 91麻豆视频网站| 一本大道久久a久久综合婷婷 | 精品少妇一区二区三区免费观看| 在线一区二区三区四区五区| 色综合色狠狠综合色| 91蜜桃婷婷狠狠久久综合9色| 成人免费视频视频| 波多野结衣亚洲| 91视频精品在这里| 色系网站成人免费| 在线观看国产91| 欧美日韩视频不卡| 欧美一区二区三区在线看| 日韩一级免费观看| 精品处破学生在线二十三| 久久这里只有精品视频网| 国产欧美日韩在线| 亚洲欧美日韩在线| 亚洲va在线va天堂| 韩国女主播一区二区三区| 国产精品18久久久久久久久久久久| 国产精品亚洲第一区在线暖暖韩国| 国产精选一区二区三区| av综合在线播放| 欧美日韩免费视频| 欧美成人vps| 亚洲品质自拍视频网站| 亚洲成人黄色影院| 韩国午夜理伦三级不卡影院| 粉嫩高潮美女一区二区三区| www.亚洲人| 欧美乱妇15p| 久久久久99精品国产片| 亚洲视频一区在线观看| 婷婷综合在线观看| 国产激情偷乱视频一区二区三区| 波多野结衣中文字幕一区 | 性欧美大战久久久久久久久| 老司机免费视频一区二区| 国产一区二区视频在线播放| 色婷婷国产精品| 精品久久久久久久久久久久久久久| 国产精品欧美综合在线| 日日摸夜夜添夜夜添亚洲女人| 国产尤物一区二区| 欧美三级视频在线观看| 久久久久99精品一区| 天天色图综合网| av成人动漫在线观看| 日韩三级中文字幕| 亚洲精品一二三| 国产制服丝袜一区| 91精品免费在线| 亚洲人成伊人成综合网小说| 精品一区二区在线视频| 在线观看国产精品网站| 国产精品青草综合久久久久99| 日本成人在线电影网| 91久久精品日日躁夜夜躁欧美| 久久女同精品一区二区| 日日摸夜夜添夜夜添亚洲女人| 99riav一区二区三区| 精品国产精品一区二区夜夜嗨| 亚洲一区免费观看| 99久久精品99国产精品| 中文字幕第一区综合| 狠狠色丁香婷婷综合久久片| 欧美嫩在线观看| 洋洋av久久久久久久一区| av毛片久久久久**hd| 国产亚洲制服色| 激情偷乱视频一区二区三区| 欧美男女性生活在线直播观看| 亚洲人精品一区| 成人av手机在线观看| 欧美国产丝袜视频| 丰满亚洲少妇av| 国产精品视频在线看| 国产成人av电影在线| 精品国产一区二区三区不卡 | 色噜噜狠狠成人中文综合| 国产精品视频一区二区三区不卡| 国内精品久久久久影院薰衣草| 日韩欧美视频在线| 免费av网站大全久久| 欧美一区二区三区四区五区| 日韩在线a电影| 日韩一级视频免费观看在线| 免费观看一级特黄欧美大片| 欧美一区二区视频免费观看|