本文整理匯總了Java中gnu.io.SerialPortEvent類的典型用法代碼示例。如果您正苦於以下問題:Java SerialPortEvent類的具體用法?Java SerialPortEvent怎麽用?Java SerialPortEvent使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
SerialPortEvent類屬於gnu.io包,在下文中一共展示了SerialPortEvent類的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();
}
示例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.
}
示例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;
}
}
示例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();
}
}
}
示例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());
}
}
}
示例6: serialEvent
import gnu.io.SerialPortEvent; //導入依賴的package包/類
public void serialEvent(SerialPortEvent arg0) {
int data;
try
{
int len = 0;
while ( ( data = inStream.read()) > -1 )
{
if ( data == '\n' ) {
break;
}
if (data >= 48 && data <= 57 ){buffer[len++] = (byte) data;}
}
inputData = Integer.parseInt(new String(buffer,0,len));
inputWaiting = true;
}
catch ( IOException e )
{
e.printStackTrace();
}
}
示例7: 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();
}
}
}
}
示例8: 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.
}
示例9: 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);
}
}
}
示例10: 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;
}
}
示例11: 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
示例12: 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");
}
示例13: 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.
}
示例14: 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);
}
}
}
示例15: serialEvent
import gnu.io.SerialPortEvent; //導入依賴的package包/類
@Override
public void serialEvent(SerialPortEvent event) {
if (event.getEventType() == SerialPortEvent.DATA_AVAILABLE) {
synchronized (inputStream) {
inputStream.notifyAll();
}
}
}