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


Java SerialPortEvent.getEventType方法代碼示例

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


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

示例1: serialEvent

import gnu.io.SerialPortEvent; //導入方法依賴的package包/類
public void serialEvent(SerialPortEvent spe) {
    if (spe.getEventType() == SerialPortEvent.DATA_AVAILABLE) {
        StringBuilder line = new StringBuilder();
        try {
            while (isr.ready()) {
                if (hexi < 0) {
                    line.append((char) isr.read());
                } else {
                    int value = isr.read();
                    if (value >= 0) {
                        line.append(String.format("%02X ", (value & 0xFF)));
                        if (++hexi % 0x10 == 0) {
                            line.append("\n");
                        }
                    }
                }
            }

            appendString(line.toString());
        } catch (IOException ex) {
            Logger.getLogger(HyperTerminal.class.getName()).log(Level.WARNING, null, ex);
        }
    }

    updateFlags();
}
 
開發者ID:SensorsINI,項目名稱:jaer,代碼行數:27,代碼來源:HyperTerminal.java

示例2: serialEvent

import gnu.io.SerialPortEvent; //導入方法依賴的package包/類
/**
 * Handle an event on the serial port. Read the data and print it.
 */
@Override
public synchronized void serialEvent(SerialPortEvent oEvent) 
{
        if (oEvent.getEventType() == SerialPortEvent.DATA_AVAILABLE) 
        {
                try 
                {
                        String inputLine = input.readLine();
                        System.out.println(inputLine);
                } catch (Exception e) {
                        System.err.println(e.toString());
                }
        }
        // Ignore all the other eventTypes, but you should consider the other ones.
}
 
開發者ID:onebeartoe,項目名稱:lizard-enclosure,代碼行數:19,代碼來源:SerialTest.java

示例3: serialEvent

import gnu.io.SerialPortEvent; //導入方法依賴的package包/類
@Override
   public void serialEvent(SerialPortEvent e)
{
	int type = e.getEventType();
	switch (type)
	{
	    case SerialPortEvent.DATA_AVAILABLE:
			try
			{
				buffer.readData(is);
				byte[] newline;
				while ((newline = buffer.getNextLine()) != null)
					processData(newline);
			}
			catch (IOException ex)
			{
				log.log(Level.WARNING, "serial port read error: " + ex, ex);
			}
			break;

		default:
			log.log(Level.INFO, "Recieved serialEvent {0}", type);
			break;
	}
}
 
開發者ID:drytoastman,項目名稱:scorekeeperfrontend,代碼行數:26,代碼來源:SerialDataInterface.java

示例4: serialEvent

import gnu.io.SerialPortEvent; //導入方法依賴的package包/類
@Override
public void serialEvent(SerialPortEvent event) {
    if (event.getEventType() == SerialPortEvent.DATA_AVAILABLE) {
        try {
            synchronized (bufferSynchronisationObject) {
                int recv;
                while ((recv = inputStream.read()) != -1) {
                    buffer[end++] = recv;
                    if (end >= maxLength) {
                        end = 0;
                    }
                }
            }
        } catch (IOException e) {
        }

        synchronized (this) {
            this.notify();
        }
    }
}
 
開發者ID:openhab,項目名稱:org.openhab.binding.zigbee,代碼行數:22,代碼來源:ZigBeeSerialPort.java

示例5: serialEvent

import gnu.io.SerialPortEvent; //導入方法依賴的package包/類
/**
 * This Method is called when Serialdata is recieved
 */
public synchronized void serialEvent (SerialPortEvent oEvent) {
    if (oEvent.getEventType() == SerialPortEvent.DATA_AVAILABLE) {
        try {
            int available = input.available();
            for(int i=0;i<available;i++){
                int receivedVal=input.read();
                if(receivedVal!=10 && receivedVal!=13){
                    inputBuffer+=(char)receivedVal;
                }else if(receivedVal==10){
                	te.log("ARDUINO:-> "+inputBuffer);
                    inputBuffer="";
                }
            }
        } catch (Exception e) {
            System.err.println(e.toString());
        }
    }
}
 
開發者ID:agbishara,項目名稱:V2R,代碼行數:22,代碼來源:comm.java

示例6: serialEvent

import gnu.io.SerialPortEvent; //導入方法依賴的package包/類
@Override
public void serialEvent(SerialPortEvent event) {
    if (event.getEventType() == SerialPortEvent.DATA_AVAILABLE) {
        synchronized (serialPort) {
            try {
                if (br == null) {
                    logger.warn("BufferedReader for serial connection is null");
                } else {
                    String line = br.readLine();
                    logger.trace("Serial event: received '{}'", line);
                    processNextLine(line);
                }
            } catch (IOException e) {
                logger.warn("Can't read from serial device {}", config.getDeviceName(), e);
                tryReopenHardware();
            }
        }
    }
}
 
開發者ID:openhab,項目名稱:openhab1-addons,代碼行數:20,代碼來源:CULSerialHandlerImpl.java

示例7: serialEvent

import gnu.io.SerialPortEvent; //導入方法依賴的package包/類
/**
 * Handle an event on the serial port. Read the data and print it.
 */
public synchronized void serialEvent(SerialPortEvent oEvent) {
	if (oEvent.getEventType() == SerialPortEvent.DATA_AVAILABLE) {
		try {
			String inputLine=input.readLine();
			if (inputLine.length() > 0) {
				for(SerialListener s : listeners) {
					s.readPerformed(inputLine);
				}
			}
		} catch (Exception e) {
			System.err.println(e.toString());
		}
	}
	// Ignore all the other eventTypes, but you should consider the other ones.
}
 
開發者ID:mikand,項目名稱:Dirigino,代碼行數:19,代碼來源:SerialInterface.java

示例8: serialEvent

import gnu.io.SerialPortEvent; //導入方法依賴的package包/類
/**
 * 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);
		}
	}
}
 
開發者ID:elexis,項目名稱:elexis-3-core,代碼行數:22,代碼來源:AbstractConnection.java

示例9: serialEvent

import gnu.io.SerialPortEvent; //導入方法依賴的package包/類
/**
 * 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,代碼行數:24,代碼來源:AfinionConnection.java

示例10: serialEvent

import gnu.io.SerialPortEvent; //導入方法依賴的package包/類
@Override
public synchronized void serialEvent(SerialPortEvent serialPortEvent) {
    if (serialPortEvent.getEventType() == SerialPortEvent.DATA_AVAILABLE) {
        try {
            if (input.ready()) {
                processData(input.readLine());
            }

        } catch (Exception e) {
            log.error("Error ", e);
        }
    }
}
 
開發者ID:diegosep,項目名稱:spring-serial-port-connector,代碼行數:14,代碼來源:AbstractSpringSerialPortConnector.java

示例11: serialEvent

import gnu.io.SerialPortEvent; //導入方法依賴的package包/類
@Override
public void serialEvent(SerialPortEvent event) {
    if (event.getEventType() == SerialPortEvent.DATA_AVAILABLE)
        fireDataAvailable();
    else
        System.out.println("other event");
}
 
開發者ID:MatzeS,項目名稱:blackbird,代碼行數:8,代碼來源:RXTXSerialPort.java

示例12: serialEvent

import gnu.io.SerialPortEvent; //導入方法依賴的package包/類
/**
 * Handle an event on the serial port. Read the data and print it.
 */
public synchronized void serialEvent(SerialPortEvent oEvent) {
    if (oEvent.getEventType() == SerialPortEvent.DATA_AVAILABLE) {
        try {
            String inputLine = input.readLine();
            log.info("Reçoit : " + inputLine);
        } catch (Exception e) {
            log.error("error 2 " + e.toString());
        }
    }
    // Ignore all the other eventTypes, but you should consider the other ones.
}
 
開發者ID:schwabdidier,項目名稱:GazePlay,代碼行數:15,代碼來源:ArduinoSerialCommunication.java

示例13: serialEvent

import gnu.io.SerialPortEvent; //導入方法依賴的package包/類
@Override
  public void serialEvent(SerialPortEvent spe)
  {
      // we're only interested in streamed data
      if (spe.getEventType() == SerialPortEvent.DATA_AVAILABLE) {
	try
          {
              if (synced) {
			// either synced data (messages), or...
                  continueMessage();
		}
		else {
			// ...some unsynced characters; see setSynced()
                  while(true)
                  {
                      int i= saveRead();
                      if (i == -1) {
					break;
				}
                      listener.unsyncedChar((char) i);
                  }
		}
          } catch (IOException ex) {
              listener.streamingError(StreamCommandListener.STREAMING_IO_EXCEPTION,
                      "IOException while receiving (see log) : " + ex);
          }
}
  }
 
開發者ID:SensorsINI,項目名稱:jaer,代碼行數:29,代碼來源:StreamCommand.java

示例14: serialEvent

import gnu.io.SerialPortEvent; //導入方法依賴的package包/類
@Override
public void serialEvent(SerialPortEvent event) {
    if (event.getEventType() == SerialPortEvent.DATA_AVAILABLE) {
        synchronized (inputStream) {
            inputStream.notifyAll();
        }
    }
}
 
開發者ID:csowada,項目名稱:ebus,代碼行數:9,代碼來源:EBusSerialNRJavaSerialConnection.java

示例15: serialEvent

import gnu.io.SerialPortEvent; //導入方法依賴的package包/類
/**
 * Handle an event on the serial port. Read the data and print it.
 */
public synchronized void serialEvent(SerialPortEvent oEvent) {
	//System.out.println("Serial event successfully triggered");
           
           if (oEvent.getEventType() == SerialPortEvent.DATA_AVAILABLE) {
		try {
                               String inputLine = null;
                               if(input.ready()){
			inputLine=input.readLine();
			System.out.println(inputLine);
                               
                               //StringTokenizer to read an entire line of tata. It is expected that successive
                               //reads are in successive lines. 
                               StringTokenizer stringTokenizer = new StringTokenizer(inputLine,",");
                               
                               String arduinoID = stringTokenizer.nextToken();
                               statement.setString(1,arduinoID);
                               System.out.println(arduinoID);
                               String humidity = stringTokenizer.nextToken();
                               System.out.println(humidity);
                               statement.setString(2,humidity);                                
                               String temperature = stringTokenizer.nextToken();
                               System.out.println(temperature);
                               statement.setString(3,temperature);
                               statement.executeUpdate();
                               
                               
                               
                               }
		} catch (Exception e) {
			System.err.println(e.toString());
		}
	}
	// Ignore all the other eventTypes, but you should consider the other ones.
}
 
開發者ID:mulima,項目名稱:ArduinoDB,代碼行數:38,代碼來源:SerialReader.java


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