當前位置: 首頁>>代碼示例>>Java>>正文


Java SerialPortEventListener類代碼示例

本文整理匯總了Java中gnu.io.SerialPortEventListener的典型用法代碼示例。如果您正苦於以下問題:Java SerialPortEventListener類的具體用法?Java SerialPortEventListener怎麽用?Java SerialPortEventListener使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


SerialPortEventListener類屬於gnu.io包,在下文中一共展示了SerialPortEventListener類的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: initialize

import gnu.io.SerialPortEventListener; //導入依賴的package包/類
public void initialize() {
        System.setProperty("gnu.io.rxtx.SerialPorts", getComPortName());        
        CommPortIdentifier portId = null;        
        Enumeration portEnum = CommPortIdentifier.getPortIdentifiers();
        
        while (portEnum.hasMoreElements()) {
            CommPortIdentifier currPortId = (CommPortIdentifier) portEnum.nextElement();
            if(currPortId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
                if (currPortId.getName().equals(txtComPortName.getText())) {
                    System.out.println(txtComPortName.getText());
                    portId = currPortId;
                    break;
                }
            }
        }
        if (portId == null) {
            
            JOptionPane.showMessageDialog(null," Portuna bağlı cihaz yok!","Hata",JOptionPane.ERROR_MESSAGE);
            System.out.println("Porta bağlı cihaz yok!");
            return;
        }
System.out.println(portId);
        try {
            serialPort = (SerialPort) portId.open(this.getClass().getName(), TIME_OUT);

            serialPort.setSerialPortParams(DATA_RATE, SerialPort.DATABITS_8, SerialPort.STOPBITS_1,
                    SerialPort.PARITY_NONE);

            input = new BufferedReader(new InputStreamReader(serialPort.getInputStream()));
            output = serialPort.getOutputStream();

            serialPort.addEventListener((SerialPortEventListener) this);
           serialPort.notifyOnDataAvailable(true);
        } catch (Exception e) {
            System.err.println(e.toString());
        }
    }
 
開發者ID:altnokburcu,項目名稱:uyariSistemi,代碼行數:38,代碼來源:UI_uyari.java

示例2: setSerialEventHandler

import gnu.io.SerialPortEventListener; //導入依賴的package包/類
/**
 * Set the serial event handler.
 *
 * @param serialPortEventListenser
 */
private void setSerialEventHandler(SerialPortEventListener serialPortEventListenser) {
    try {
        // Add the serial port event listener
        serialPort.addEventListener(serialPortEventListenser);
        serialPort.notifyOnDataAvailable(true);
    } catch (TooManyListenersException tooManyListenersException) {
        logger.error("setSerialEventHandler(): Too Many Listeners Exception: {}",
                tooManyListenersException.getMessage());
    }
}
 
開發者ID:openhab,項目名稱:openhab2-addons,代碼行數:16,代碼來源:IT100BridgeHandler.java

示例3: addListener

import gnu.io.SerialPortEventListener; //導入依賴的package包/類
/**
 * 添加監聽器
 * 
 * @param port
 *            串口對象
 * @param listener
 *            串口監聽器
 * @throws TooManyListeners
 *             監聽類對象過多
 */
public static void addListener(SerialPort port,
		SerialPortEventListener listener) throws TooManyListeners {
	try {
		// 給串口添加監聽器
		port.addEventListener(listener);
		// 設置當有數據到達時喚醒監聽接收線程
		port.notifyOnDataAvailable(true);
		// 設置當通信中斷時喚醒中斷線程
		port.notifyOnBreakInterrupt(true);
	} catch (TooManyListenersException e) {
		throw new TooManyListeners();
	}
}
 
開發者ID:alidili,項目名稱:SerialPortDemo,代碼行數:24,代碼來源:SerialPortManager.java

示例4: setSerialEventHandler

import gnu.io.SerialPortEventListener; //導入依賴的package包/類
/**
 * Set the serial event handler
 */
private void setSerialEventHandler(SerialPortEventListener serialPortEventListenser) {
    try {
        // Add the serial port event listener
        serialPort.addEventListener(serialPortEventListenser);
        serialPort.notifyOnDataAvailable(true);
    } catch (TooManyListenersException tooManyListenersException) {
		logger.error("open(): Too Many Listeners Exception: ", tooManyListenersException);
    }
}
 
開發者ID:andrey-desman,項目名稱:openhab-hdl,代碼行數:13,代碼來源:SerialConnector.java

示例5: addEventListener

import gnu.io.SerialPortEventListener; //導入依賴的package包/類
public boolean addEventListener(SerialPortEventListener serialPortEventListener){
	if (serialPort != null) {
		try {
			serialPort.addEventListener(serialPortEventListener);
			serialPort.notifyOnDataAvailable(true);
			return true;
		} catch (TooManyListenersException e) {
			System.err.println(e.toString());
		}
	}
	return false;
}
 
開發者ID:claudiotrindade,項目名稱:contexttoolkit,代碼行數:13,代碼來源:SerialConnection.java

示例6: addListener

import gnu.io.SerialPortEventListener; //導入依賴的package包/類
public void addListener(SerialPortEventListener serialPortEventListener) {
    try {
        serialPort.addEventListener(serialPortEventListener);
        serialPort.notifyOnDataAvailable(true);
    } catch (TooManyListenersException e) {
        e.printStackTrace();
    }
}
 
開發者ID:hatboysam,項目名稱:muse-x,代碼行數:9,代碼來源:ArduinoConnection.java

示例7: connect

import gnu.io.SerialPortEventListener; //導入依賴的package包/類
/**
 * Connect.
 * @param portName RS232 port name.
 * @param baudrate Baud rate.
 * @param dataBits Data bits.
 * @param stopBits Stop bits.
 * @param parity Parity.
 * @return Success or not.
 * @throws Exception
 */
public boolean connect(String portName, int baudrate, int dataBits, int stopBits, int parity) throws Exception {
    this.monitor = this.protocol.createMonitor(this.aliasName);
    this.monitor.setController(this);

    if (this.started) {
        return true;
    }

    CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(portName);
    if (portIdentifier.isCurrentlyOwned()) {
        return false;
    }

    CommPort commPort = portIdentifier.open(getClass().getName(), 2000);

    this.serialPort = (SerialPort) commPort;
    this.serialPort.setSerialPortParams(baudrate, dataBits, stopBits, parity);

    this.in = this.serialPort.getInputStream();
    this.out = this.serialPort.getOutputStream();
    this.serialPort.addEventListener(new SerialPortEventListener() {

        @Override
        public void serialEvent(SerialPortEvent evt) {
            messageReceived();
        }
    });
    this.serialPort.notifyOnDataAvailable(true);

    this.started = true;

    return true;
}
 
開發者ID:gazer2kanlin,項目名稱:uia.comm4j,代碼行數:44,代碼來源:RS232.java

示例8: addDataAvailableEventHandler

import gnu.io.SerialPortEventListener; //導入依賴的package包/類
/**
 * Register event handler for data available event
 *
 * @param eventHandler Event handler
 */
public void addDataAvailableEventHandler(
        SerialPortEventListener eventHandler) {
    try {
        // Add the serial port event listener
        serialPort.addEventListener(eventHandler);
        serialPort.notifyOnDataAvailable(true);
    } catch (TooManyListenersException ex) {
        System.err.println(ex.getMessage());
    }
}
 
開發者ID:qoswork,項目名稱:opennmszh,代碼行數:16,代碼來源:LoopbackEventTest.java

示例9: addEventListener

import gnu.io.SerialPortEventListener; //導入依賴的package包/類
public void addEventListener ( SerialPortEventListener listener ) {
	try {
		sPort.addEventListener( listener );
	} catch ( TooManyListenersException e ) {
		sPort.close( );
		logger.warn( e.getMessage( ) , e );
	}
}
 
開發者ID:LSIR,項目名稱:gsn,代碼行數:9,代碼來源:SerialWrapper.java

示例10: setSerialEventHandler

import gnu.io.SerialPortEventListener; //導入依賴的package包/類
/**
 * Set the serial event handler
 */
private void setSerialEventHandler(SerialPortEventListener serialPortEventListenser) {
    try {
        // Add the serial port event listener
        serialPort.addEventListener(serialPortEventListenser);
        serialPort.notifyOnDataAvailable(true);
    } catch (TooManyListenersException tooManyListenersException) {
        logger.error("open(): Too Many Listeners Exception: ", tooManyListenersException);
    }
}
 
開發者ID:openhab,項目名稱:openhab1-addons,代碼行數:13,代碼來源:SerialConnector.java

示例11: addPortEventListener

import gnu.io.SerialPortEventListener; //導入依賴的package包/類
/**
 * F�gt den Listener der Instanz hinzu. Es kann dabei nur einen Listener geben, sonst wird eine Exception geworfen.
 * 
 * @param spel
 * @throws TooManyListenersException
 */
public void addPortEventListener(SerialPortEventListener spel) throws TooManyListenersException{
		serialPort.addEventListener(spel);
	
}
 
開發者ID:SecUSo,項目名稱:EasyVote,代碼行數:11,代碼來源:VCDSerialPort.java

示例12: addEventListener

import gnu.io.SerialPortEventListener; //導入依賴的package包/類
/**
 * Add a port listener to the serial port. Only one listener is allowed at
 * the same time. The port must be opened before a listener can be added.
 * 
 * @param listener is the listener to add.
 * @throws TooManyListenersException is thrown if another listener was
 *            previously added.
 */
public void addEventListener(SerialPortEventListener listener) throws TooManyListenersException
{
   serialPort.addEventListener(listener);
}
 
開發者ID:selfbus,項目名稱:tools-libraries,代碼行數:13,代碼來源:SerialPortWrapper.java


注:本文中的gnu.io.SerialPortEventListener類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。