本文整理匯總了Java中gnu.io.SerialPortEvent.BI屬性的典型用法代碼示例。如果您正苦於以下問題:Java SerialPortEvent.BI屬性的具體用法?Java SerialPortEvent.BI怎麽用?Java SerialPortEvent.BI使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類gnu.io.SerialPortEvent
的用法示例。
在下文中一共展示了SerialPortEvent.BI屬性的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;
}
}
示例2: serialEvent
/**
* 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 available and 30ms has passed the method returns. When a
* BI event occurs the words BREAK RECEIVED are written to the messageAreaIn.
*/
public void serialEvent(final SerialPortEvent e){
if (adjustEndTime) {
endTime = System.currentTimeMillis() + (timeout * 1000);
}
if (e.getEventType() == SerialPortEvent.BI) {
breakInterrupt(state);
} else {
try {
serialEvent(this.state, is, e);
} catch (Exception ex) {
ExHandler.handle(ex);
}
}
}
示例3: 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;
}
}
示例4: 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());
}
}
示例5: 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;
}
}
示例6: 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;
}
}
示例7: 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;
}
}
示例8: serialEvent
public void serialEvent ( SerialPortEvent e ) {
// if ( logger.isDebugEnabled( ) ) logger.debug( "Serial wrapper received a serial port event, reading..." );
// if ( !isActive( ) || listeners.isEmpty( ) ) {
// if ( logger.isDebugEnabled( ) ) logger.debug( "Serial wrapper dropped the input b/c there is no listener there or the wrapper is inactive." );
// return;
// }
// Determine type of event.
switch ( e.getEventType( ) ) {
// Read data until -1 is returned.
case SerialPortEvent.DATA_AVAILABLE :
/*
* int index = 0; while (newData != -1) { try { if (is == null) { if
* (logger.isDebugEnabled ()) logger.debug("SerialWrapper: Warning,
* is == null !"); is = wnetPort.getInputStream(); } else newData =
* is.read(); if (newData > -1 && newData < 256) {
* inputBuffer[index++] = (byte) newData; } } catch (IOException ex) {
* System.err.println(ex); return; } }
*/
try {
is.read( inputBuffer );
} catch ( IOException ex ) {
logger.warn( "Serial port wrapper couldn't read data : " + ex );
return;
}
break;
// If break event append BREAK RECEIVED message.
case SerialPortEvent.BI :
// messageAreaIn.append("\n--- BREAK RECEIVED ---\n");
}
if ( logger.isDebugEnabled( ) )
logger.debug( new StringBuilder( "Serial port wrapper processed a serial port event, stringbuffer is now : " ).append( new String(inputBuffer) ).toString( ) );
if ( useInputSeparator ) {
for ( String chunk : new String(inputBuffer).split( inputSeparator ) )
if ( chunk.length( ) > 0 )
post_item(chunk);
} else { //without separator character.
post_item(new String(inputBuffer) );
}
}
示例9: 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());
}
示例10: 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;
}
}
示例11: serialEvent
@Override
public void serialEvent(SerialPortEvent e) {
// Determine type of event.
switch (e.getEventType()) {
// This event is ignored, the application reads directly from
// the serial input stream
case SerialPortEvent.DATA_AVAILABLE:
/*
* try {
* int amount = m_SerialIn.available();
* while (amount > 0) {
* try {
* byte[] buffer = new byte[amount];
* if ((amount = m_SerialIn.read(buffer, 0, amount)) > 0) {
* m_Pipe.write (buffer, 0, amount);
* }
* amount = m_SerialIn.available();
* } catch (IOException ex) {
* logger.error("Error: Comm event read: {}", ex);
* ex.printStackTrace();
* return;
* }
* }
* } catch (Exception ex) {
* //handle
*
* }
*/
break;
case SerialPortEvent.BI:
logger.debug("Serial port break detected");
break;
default:
logger.debug("Serial port event: {}", e.getEventType());
}
}
示例12: 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;
}
}
示例13: 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;
}
}
示例14: 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;
}
}
示例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;
}
}