本文整理匯總了Java中gnu.io.SerialPortEvent.DATA_AVAILABLE屬性的典型用法代碼示例。如果您正苦於以下問題:Java SerialPortEvent.DATA_AVAILABLE屬性的具體用法?Java SerialPortEvent.DATA_AVAILABLE怎麽用?Java SerialPortEvent.DATA_AVAILABLE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類gnu.io.SerialPortEvent
的用法示例。
在下文中一共展示了SerialPortEvent.DATA_AVAILABLE屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: serialEvent
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();
}
示例2: serialEvent
/**
* 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.
}
示例3: serialEvent
@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;
}
}
示例4: serialEvent
@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();
}
}
}
示例5: serialEvent
/**
* 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());
}
}
}
示例6: serialEvent
@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();
}
}
}
}
示例7: serialEvent
/**
* 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.
}
示例8: 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;
}
}
示例9: serialEvent
@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,代碼行數:13,代碼來源:AbstractSpringSerialPortConnector.java
示例10: serialEvent
@Override
public void serialEvent(SerialPortEvent event) {
if (event.getEventType() == SerialPortEvent.DATA_AVAILABLE)
fireDataAvailable();
else
System.out.println("other event");
}
示例11: serialEvent
/**
* 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.
}
示例12: serialEvent
@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);
}
}
}
示例13: serialEvent
@Override
public void serialEvent(SerialPortEvent event) {
if (event.getEventType() == SerialPortEvent.DATA_AVAILABLE) {
synchronized (inputStream) {
inputStream.notifyAll();
}
}
}
示例14: serialEvent
/**
* 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.
}
示例15: serialEvent
@Override
public void serialEvent(SerialPortEvent spe) {
if (SerialPortEvent.DATA_AVAILABLE == spe.getEventType()) {
// avoid the high frequency of the notifying
// just check the read thread first
// and then choose to restart or ignore the notity
if((null != serialReadThread) && serialReadThread.isAlive()){
// do nothing here
// or you can close the notify here
// and open when the thread is done
serialPort.notifyOnDataAvailable(false);
}else{
// you must re-run the thread
// here you need only one method but using thread.start() with two
// same thread
// here you can use start, because we already know that the
// thread is dead
// here you can't use the start method again
// the data is already exist,
// so just use run to make it run again
//srialReadThread.start();
// you can never restart a thread again
serialReadThread = new Thread(new SerialReader(serialIn));
// start it
serialReadThread.start();
}
}// end if
}