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


Java SerialPortEvent.CD屬性代碼示例

本文整理匯總了Java中gnu.io.SerialPortEvent.CD屬性的典型用法代碼示例。如果您正苦於以下問題:Java SerialPortEvent.CD屬性的具體用法?Java SerialPortEvent.CD怎麽用?Java SerialPortEvent.CD使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在gnu.io.SerialPortEvent的用法示例。


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

示例1: serialEvent

/**
 * Handles serial event.
 */
public void serialEvent(final int state, final InputStream inputStream, final SerialPortEvent e)
	throws IOException{
	
	switch (e.getEventType()) {
	case SerialPortEvent.BI:
	case SerialPortEvent.OE:
	case SerialPortEvent.FE:
	case SerialPortEvent.PE:
	case SerialPortEvent.CD:
	case SerialPortEvent.CTS:
	case SerialPortEvent.DSR:
	case SerialPortEvent.RI:
	case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
		break;
	case SerialPortEvent.DATA_AVAILABLE:
		dataAvailable(inputStream);
		break;
	}
	
}
 
開發者ID:elexis,項目名稱:elexis-3-base,代碼行數:23,代碼來源:AfinionConnection.java

示例2: serialEvent

public void serialEvent(SerialPortEvent event) {
	switch (event.getEventType()) {
	case SerialPortEvent.BI:
	case SerialPortEvent.OE:
	case SerialPortEvent.FE:
	case SerialPortEvent.PE:
	case SerialPortEvent.CD:
	case SerialPortEvent.CTS:
	case SerialPortEvent.DSR:
	case SerialPortEvent.RI:
	case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
		break;
	case SerialPortEvent.DATA_AVAILABLE:
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(inputStream), 32*1024*1024);
			if(br.ready()) {
				String line = br.readLine();
				line = StringUtils.chomp(line);
				line = line.replace(",",".");
				response = line.trim();
			}
		} catch (IOException e) {
			logger.debug("Error receiving data on serial port {}: {}", new Object[] { port, e.getMessage() });
		}
		break;
	}
}
 
開發者ID:andrey-desman,項目名稱:openhab-hdl,代碼行數:27,代碼來源:OceanicBinding.java

示例3: serialEvent

/**
 * Event notification must be enabled for every event in setSerialPort() above.
 * We can't call displayMessage.display() from this method, as we are not in FX thread.
 * 
 * @param event
 */
@Override
public void serialEvent(SerialPortEvent event) {
	
	switch(event.getEventType()) {
	case SerialPortEvent.BI:
	case SerialPortEvent.CD:
	case SerialPortEvent.CTS:
	case SerialPortEvent.DSR:
	case SerialPortEvent.FE:
	case SerialPortEvent.OE:
	case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
	case SerialPortEvent.PE:
	case SerialPortEvent.RI:
		break;
	case SerialPortEvent.DATA_AVAILABLE:
		short[] payload;
		int b;
		while (true) {
			try {
				if (in.available() == 0) {
					// No more data available.
					break;
				}
				b = in.read();
			} catch (IOException e) {
				displayMessage.displayLogLater("error on receive: " + e.getMessage());
				break;
			}
			payload = frameHandler.frameAssembler(b);
			if (payload != null) {
				displayMessage.displayFrameLater(frameHandler.displayFrame(payload));
			}
		}
		break;
	default:
		displayMessage.displayLogLater("FrameHandler.serialEvent() - unknown event type: " + event.getEventType());
	}
	
}
 
開發者ID:Orange-OpenSource,項目名稱:iot-libelium-lora-gateway,代碼行數:45,代碼來源:PortHandler.java

示例4: serialEvent

/**
 * Serial port event listener.
 * @param event an event
 */
public void serialEvent(final SerialPortEvent event) {
    switch (event.getEventType()) {
    case SerialPortEvent.BI:
    case SerialPortEvent.OE:
    case SerialPortEvent.FE:
    case SerialPortEvent.PE:
    case SerialPortEvent.CD:
    case SerialPortEvent.CTS:
    case SerialPortEvent.DSR:
    case SerialPortEvent.RI:
    case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
        break;
    case SerialPortEvent.DATA_AVAILABLE:
        // we get here if data has been received
        String line = "";
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
            // read data
            while (inputStream.available() > 0) {
                while (reader.ready()) {
                    line = reader.readLine();
                }
            }
            LOG.finer("Read: " + line);
            if (!gpsFound) {
                gpsFound = isGpsStream(line);
            }
        } catch (IOException e) {
            LOG.log(Level.FINE, "IOException in serial-port -event", e);
        }
        break;
        default:
            break;
    }
}
 
開發者ID:xafero,項目名稱:travelingsales,代碼行數:39,代碼來源:GpsFinder.java

示例5: serialEvent

@Override
public void serialEvent(SerialPortEvent ev) {
    switch (ev.getEventType()) {
        case SerialPortEvent.BI:
        case SerialPortEvent.OE:
        case SerialPortEvent.FE:
        case SerialPortEvent.PE:
        case SerialPortEvent.CD:
        case SerialPortEvent.CTS:
        case SerialPortEvent.DSR:
        case SerialPortEvent.RI:
        case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
            break;

        case SerialPortEvent.DATA_AVAILABLE:
            try {
                while (in.available() > 0) {
                    if (!doRead()) {
                        break;
                    }
                }
            } catch (IOException ex) {
                LOGGER.warn("I/O exception on read.", ex);
            }
            break;

        default:
            LOGGER.warn("Unknown case.");
            break;
    }
}
 
開發者ID:spezialy,項目名稱:aleoncean,代碼行數:31,代碼來源:USB300ReaderListener.java

示例6: serialEvent

public void serialEvent(SerialPortEvent ev) {

			switch( ev.getEventType() )
			{
			case SerialPortEvent.BI:
				intp.println(String.format("EVENT: Received BI event: changed %s to %s", ev.getOldValue(), ev.getNewValue()));
				break;
			case SerialPortEvent.CD:
				intp.println(String.format("EVENT: Received CD event: changed %s to %s", ev.getOldValue(), ev.getNewValue()));
				break;
			case SerialPortEvent.CTS:
				intp.println(String.format("EVENT: Received CTS event: changed %s to %s", ev.getOldValue(), ev.getNewValue()));
				break;
			case SerialPortEvent.DATA_AVAILABLE:
				intp.println(String.format("EVENT: Received DATA_AVAIL event: changed %s to %s", ev.getOldValue(), ev.getNewValue()));
				break;
			case SerialPortEvent.DSR:
				intp.println(String.format("EVENT: Received DSR event: changed %s to %s", ev.getOldValue(), ev.getNewValue()));
				break;
			case SerialPortEvent.FE:
				intp.println(String.format("EVENT: Received FE event: changed %s to %s", ev.getOldValue(), ev.getNewValue()));
				break;
			case SerialPortEvent.OE:
				intp.println(String.format("EVENT: Received OE event: changed %s to %s", ev.getOldValue(), ev.getNewValue()));
				break;
			case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
				intp.println(String.format("EVENT: Received OUT_BUF_EMPTY event: changed %s to %s", ev.getOldValue(), ev.getNewValue()));
				break;
			case SerialPortEvent.PE:
				intp.println(String.format("EVENT: Received PE event: changed %s to %s", ev.getOldValue(), ev.getNewValue()));
				break;
			case SerialPortEvent.RI:
				intp.println(String.format("EVENT: Received RI event: changed %s to %s", ev.getOldValue(), ev.getNewValue()));
				break;
			}
		}
 
開發者ID:qoswork,項目名稱:opennmszh,代碼行數:36,代碼來源:RxtxCommands.java

示例7: serialEvent

/**
 * SerialPortEventListener method.  This just calls the notify
 * method on this object, so that all blocking methods are kicked
 * awake whenever a serialEvent occurs.
 */
public void serialEvent(SerialPortEvent spe) {

    switch(spe.getEventType())
    {
    case SerialPortEvent.BI:
        logger.debug("SerialPortEvent: Break interrupt.");
        break;
    case SerialPortEvent.CD:
        logger.debug("SerialPortEvent: Carrier detect.");
        break;
    case SerialPortEvent.CTS:
        logger.debug("SerialPortEvent: Clear to send.");
        break;
    case SerialPortEvent.DATA_AVAILABLE:
        logger.debug("SerialPortEvent: Data available at the serial port.");
        break;
    case SerialPortEvent.DSR:
        logger.debug("SerialPortEvent: Data set ready.");
        break;
    case SerialPortEvent.FE:
        logger.debug("SerialPortEvent: Framing error.");
        break;
    case SerialPortEvent.OE:
        logger.debug("SerialPortEvent: Overrun error.");
        break;
    case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
        logger.debug("SerialPortEvent: Output buffer is empty.");
        break;
    case SerialPortEvent.PE:
        logger.debug("SerialPortEvent: Parity error.");
        break;
    case SerialPortEvent.RI:
        logger.debug("SerialPortEvent: Ring indicator.");
        break;
    }
    
    logger.debug("SerialService.SerialEvent: oldValue=" + spe.getOldValue());
    logger.debug("SerialService.SerialEvent: newValue=" + spe.getNewValue());
}
 
開發者ID:home-climate-control,項目名稱:dz,代碼行數:44,代碼來源:SerialService.java

示例8: initEventListener

private void initEventListener() {
    try {

        if (resetSignalName.toLowerCase().equals("cts")) {
            this.resetSignal = SerialPortEvent.CTS;
            transport.getSerialPort().notifyOnCTS(true);
        }
        else if (resetSignalName.toLowerCase().equals("dsr")) {
            this.resetSignal = SerialPortEvent.DSR;
            transport.getSerialPort().notifyOnDSR(true);
        }
        else if (resetSignalName.toLowerCase().equals("dcd")) {
            this.resetSignal = SerialPortEvent.CD;
            transport.getSerialPort().notifyOnCarrierDetect(true);
        }
        else if (resetSignalName.toLowerCase().equals("ri")) {
            this.resetSignal = SerialPortEvent.RI;
            transport.getSerialPort().notifyOnRingIndicator(true);
        } else {
            console.println("Missing resetSignal definition, defaulting to CTS");
            this.resetSignal = SerialPortEvent.CTS;
            transport.getSerialPort().notifyOnCTS(true);
        }

        transport.getSerialPort().notifyOnDataAvailable(true);
        transport.getSerialPort().addEventListener(this);

    } catch (TooManyListenersException e) {
        console.println("Could not register eventlistener with rxtx");
    }
}
 
開發者ID:therealcouchpotato,項目名稱:conaxe,代碼行數:31,代碼來源:EventDrivenConaxCard.java

示例9: serialEvent

public void serialEvent(SerialPortEvent event) {
    switch (event.getEventType()) {
        case SerialPortEvent.BI:
        case SerialPortEvent.OE:
        case SerialPortEvent.FE:
        case SerialPortEvent.PE:
        case SerialPortEvent.CD:
        case SerialPortEvent.CTS:
        case SerialPortEvent.DSR:
        case SerialPortEvent.RI:
        case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
            break;
        case SerialPortEvent.DATA_AVAILABLE:
            try {
                BufferedReader br = new BufferedReader(new InputStreamReader(inputStream), 32 * 1024 * 1024);
                if (br.ready()) {
                    String line = br.readLine();
                    line = StringUtils.chomp(line);
                    line = line.replace(",", ".");
                    response = line.trim();
                }
            } catch (IOException e) {
                logger.debug("Error receiving data on serial port {}: {}",
                        new Object[] { port, e.getMessage() });
            }
            break;
    }
}
 
開發者ID:openhab,項目名稱:openhab1-addons,代碼行數:28,代碼來源:OceanicBinding.java

示例10: serialEvent

@Override
public void serialEvent(SerialPortEvent event) {
    switch (event.getEventType()) {
        case SerialPortEvent.BI:
        case SerialPortEvent.OE:
        case SerialPortEvent.FE:
        case SerialPortEvent.PE:
        case SerialPortEvent.CD:
        case SerialPortEvent.CTS:
        case SerialPortEvent.DSR:
        case SerialPortEvent.RI:
        case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
            break;
        case SerialPortEvent.DATA_AVAILABLE:
            // we get here if data has been received
            try {
                // read data from serial device
                while (serialPort.getInputStream().available() > 0) {
                    int currentByte = serialPort.getInputStream().read();
                    // Plugwise sends ASCII data, but for some unknown reason we sometimes get data with unsigned
                    // byte value >127 which in itself is very strange. We filter these out for the time being
                    if (currentByte < 128) {
                        readBuffer.put((byte) currentByte);
                        if (previousByte == CR && currentByte == LF) {
                            readBuffer.flip();
                            parseAndQueue(readBuffer);
                            readBuffer.clear();
                            previousByte = -1;
                        } else {
                            previousByte = currentByte;
                        }
                    }
                }
            } catch (IOException e) {
                logger.debug("Error receiving data on serial port {}: {}", port, e.getMessage());
            }
            break;
    }
}
 
開發者ID:openhab,項目名稱:openhab1-addons,代碼行數:39,代碼來源:Stick.java

示例11: serialEvent

/**
 * 處理監控到的串口事件
 */
public void serialEvent(SerialPortEvent serialPortEvent) {

	switch (serialPortEvent.getEventType()) {

	case SerialPortEvent.BI: // 10 通訊中斷
		ShowUtils.errorMessage("與串口設備通訊中斷");
		break;

	case SerialPortEvent.OE: // 7 溢位(溢出)錯誤

	case SerialPortEvent.FE: // 9 幀錯誤

	case SerialPortEvent.PE: // 8 奇偶校驗錯誤

	case SerialPortEvent.CD: // 6 載波檢測

	case SerialPortEvent.CTS: // 3 清除待發送數據

	case SerialPortEvent.DSR: // 4 待發送數據準備好了

	case SerialPortEvent.RI: // 5 振鈴指示

	case SerialPortEvent.OUTPUT_BUFFER_EMPTY: // 2 輸出緩衝區已清空
		break;

	case SerialPortEvent.DATA_AVAILABLE: // 1 串口存在可用數據
		byte[] data = null;
		try {
			if (serialport == null) {
				ShowUtils.errorMessage("串口對象為空!監聽失敗!");
			} else {
				// 讀取串口數據
				data = SerialPortManager.readFromPort(serialport);
				dataView.append(ByteUtils.byteArrayToHexString(data,
						true) + "\r\n");
			}
		} catch (Exception e) {
			ShowUtils.errorMessage(e.toString());
			// 發生讀取錯誤時顯示錯誤信息後退出係統
			System.exit(0);
		}
		break;
	}
}
 
開發者ID:alidili,項目名稱:SerialPortDemo,代碼行數:47,代碼來源:MainFrame.java

示例12: serialEvent

@Override
public void serialEvent(SerialPortEvent event) {
	switch (event.getEventType()) {
		/* Break interrupt */
		case SerialPortEvent.BI:
			
		/* Overrun error */
		case SerialPortEvent.OE:
		
		/* Framing error */
		case SerialPortEvent.FE:
		
		/* Parity error */
		case SerialPortEvent.PE:
		
		/* Carrier detect */
		case SerialPortEvent.CD:
		
		/* Clear to send */
		case SerialPortEvent.CTS:
		
		/* Data set ready */
		case SerialPortEvent.DSR:
		
		/* Ring indicator */
		case SerialPortEvent.RI:
		
		/* OUTPUT_BUFFER_EMPTY */
		case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
			
		break;
		
		/* Data Available */
		case SerialPortEvent.DATA_AVAILABLE:
			SerialCommunication serialComm = new SerialCommunication(in);
			serialComm.communicate();
		break;
		default:
			close();
		break;
	}
}
 
開發者ID:lishiyun19,項目名稱:Serial,代碼行數:42,代碼來源:SerialEvent.java

示例13: serialEvent

public void serialEvent(SerialPortEvent event) {
	switch (event.getEventType()) {
	case SerialPortEvent.BI:
	case SerialPortEvent.OE:
	case SerialPortEvent.FE:
	case SerialPortEvent.PE:
	case SerialPortEvent.CD:
	case SerialPortEvent.CTS:
	case SerialPortEvent.DSR:
	case SerialPortEvent.RI:
	case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
		break;
	case SerialPortEvent.DATA_AVAILABLE:

		try {

			BufferedReader br = new BufferedReader(new InputStreamReader(inputStream), 32*1024*1024);
			while (br.ready()) {
				String line = br.readLine();
				line = StringUtils.chomp(line);

				// little hack to overcome Locale limits of the RME Rain Manager
				// note to the attentive reader : should we add support for system locale's
				// in the Type classes? ;-)
				line = line.replace(",",".");
				line = line.trim();

				if(previousLine==null) {
					previousLine = line;
				}

				if(!previousLine.equals(line)) {
					processData(line);
					previousLine=line;
				}
			}

		} catch (IOException e) {
			logger.debug("Error receiving data on serial port {}: {}", new Object[] { port, e.getMessage() });
		}
		break;
	}
}
 
開發者ID:andrey-desman,項目名稱:openhab-hdl,代碼行數:43,代碼來源:RMEBinding.java

示例14: serialEvent

public void serialEvent(SerialPortEvent event) {
	switch (event.getEventType()) {
	case SerialPortEvent.BI:
	case SerialPortEvent.OE:
	case SerialPortEvent.FE:
	case SerialPortEvent.PE:
	case SerialPortEvent.CD:
	case SerialPortEvent.CTS:
	case SerialPortEvent.DSR:
	case SerialPortEvent.RI:
	case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
		break;
	case SerialPortEvent.DATA_AVAILABLE:
		// we get here if data has been received
		boolean newlineFound = false;
		if(readBuffer == null) {
			readBuffer = ByteBuffer.allocate(maxBufferSize);
		}
		try {
			// read data from serial device
			while (serialPort.getInputStream().available() > 0) {
				int aByte = serialPort.getInputStream().read();
				if ((aByte)==13) {
					readBuffer.put((byte)aByte);
					int cr = serialPort.getInputStream().read();
					readBuffer.put((byte)cr);
					newlineFound = true;
					break;
				}
				//Plugwise sends ASCII data, but for some unknown reason we sometimes get data with unsigned byte value >127
				//which in itself is very strange. We filter these out for the time being
				if(aByte < 128) {
					readBuffer.put((byte)aByte);
				}
			}

			// process data
			if(readBuffer.position()!=0 && newlineFound==true) {
				readBuffer.flip();
				parseAndQueue(readBuffer);
				readBuffer = null;
			}						
		} catch (IOException e) {
			logger.debug("Error receiving data on serial port {}: {}", new String[] { port, e.getMessage() });
		}		
		break;
	}
}
 
開發者ID:andrey-desman,項目名稱:openhab-hdl,代碼行數:48,代碼來源:Stick.java

示例15: serialEvent

public void serialEvent(SerialPortEvent event) {
    switch (event.getEventType()) {
        case SerialPortEvent.BI:
        case SerialPortEvent.OE:
        case SerialPortEvent.FE:
        case SerialPortEvent.PE:
        case SerialPortEvent.CD:
        case SerialPortEvent.CTS:
        case SerialPortEvent.DSR:
        case SerialPortEvent.RI:
        case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
            break;
        case SerialPortEvent.DATA_AVAILABLE:

            try {

                BufferedReader br = new BufferedReader(new InputStreamReader(inputStream), 32 * 1024 * 1024);
                while (br.ready()) {
                    String line = br.readLine();
                    line = StringUtils.chomp(line);

                    // little hack to overcome Locale limits of the RME Rain Manager
                    // note to the attentive reader : should we add support for system locale's
                    // in the Type classes? ;-)
                    line = line.replace(",", ".");
                    line = line.trim();

                    if (previousLine == null) {
                        previousLine = line;
                    }

                    if (!previousLine.equals(line)) {
                        processData(line);
                        previousLine = line;
                    }
                }

            } catch (IOException e) {
                logger.debug("Error receiving data on serial port {}: {}",
                        new Object[] { port, e.getMessage() });
            }
            break;
    }
}
 
開發者ID:openhab,項目名稱:openhab1-addons,代碼行數:44,代碼來源:RMEBinding.java


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