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();
}
java类gnu.io.SerialPortEvent的实例源码
HyperTerminal.java 文件源码
项目:jaer
阅读 25
收藏 0
点赞 0
评论 0
SerialDataInterface.java 文件源码
项目:scorekeeperfrontend
阅读 19
收藏 0
点赞 0
评论 0
@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;
}
}
ZigBeeSerialPort.java 文件源码
项目:org.openhab.binding.zigbee
阅读 20
收藏 0
点赞 0
评论 0
@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();
}
}
}
comm.java 文件源码
项目:V2R
阅读 16
收藏 0
点赞 0
评论 0
/**
* 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());
}
}
}
SerialTest.java 文件源码
项目:lizard-enclosure
阅读 18
收藏 0
点赞 0
评论 0
/**
* 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.
}
SerialPortHandler.java 文件源码
项目:dammit
阅读 20
收藏 0
点赞 0
评论 0
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();
}
}
CULSerialHandlerImpl.java 文件源码
项目:openhab1-addons
阅读 18
收藏 0
点赞 0
评论 0
@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();
}
}
}
}
SerialInterface.java 文件源码
项目:Dirigino
阅读 26
收藏 0
点赞 0
评论 0
/**
* 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.
}
AbstractConnection.java 文件源码
项目:elexis-3-core
阅读 19
收藏 0
点赞 0
评论 0
/**
* 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);
}
}
}
AfinionConnection.java 文件源码
项目:elexis-3-base
阅读 19
收藏 0
点赞 0
评论 0
/**
* 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;
}
}
SerialTest.java 文件源码
项目:lizard-enclosure
阅读 17
收藏 0
点赞 0
评论 0
/**
* 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.
}
AbstractSpringSerialPortConnector.java 文件源码
项目:spring-serial-port-connector
阅读 21
收藏 0
点赞 0
评论 0
@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);
}
}
}
RXTXSerialPort.java 文件源码
项目:blackbird
阅读 21
收藏 0
点赞 0
评论 0
@Override
public void serialEvent(SerialPortEvent event) {
if (event.getEventType() == SerialPortEvent.DATA_AVAILABLE)
fireDataAvailable();
else
System.out.println("other event");
}
ArduinoSerialCommunication.java 文件源码
项目:GazePlay
阅读 22
收藏 0
点赞 0
评论 0
/**
* 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.
}
StreamCommand.java 文件源码
项目:jaer
阅读 23
收藏 0
点赞 0
评论 0
@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);
}
}
}
EBusSerialNRJavaSerialConnection.java 文件源码
项目:ebus
阅读 125
收藏 0
点赞 0
评论 0
@Override
public void serialEvent(SerialPortEvent event) {
if (event.getEventType() == SerialPortEvent.DATA_AVAILABLE) {
synchronized (inputStream) {
inputStream.notifyAll();
}
}
}
SerialReader.java 文件源码
项目:ArduinoDB
阅读 20
收藏 0
点赞 0
评论 0
/**
* 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.
}
PortRXTX.java 文件源码
项目:project-bianca
阅读 19
收藏 0
点赞 0
评论 0
/**
* rxtxlib's "serial event handling" - would be more simple if they just
* implemented InputStream correctly :P
*/
@Override
public void serialEvent(SerialPortEvent event) {
log.info(String.format("rxtx event on port %s", portName));
Integer newByte = -1;
try {
while (listening && ((newByte = read()) > -1)) {
// listener.onByte(newByte); // <-- FIXME ?? onMsg() < ???
for (String key : listeners.keySet()) {
listeners.get(key).onByte(newByte);
}
++stats.total;
if (stats.total % stats.interval == 0) {
stats.ts = System.currentTimeMillis();
log.error(String.format("===stats - dequeued total %d - %d bytes in %d ms %d Kbps", stats.total, stats.interval, stats.ts - stats.lastTS, 8 * stats.interval
/ (stats.ts - stats.lastTS)));
// publishQueueStats(stats);
stats.lastTS = stats.ts;
}
// log.info(String.format("%d",newByte));
// rxtx leave whenever it has no new data to delver with a -1
// which is not what an Java InputStream is supposed to do..
}
log.info(String.format("%d",newByte));
} catch (Exception e) {
++rxErrors;
Logging.logError(e);
}
}
WirelessLCDSystem.java 文件源码
项目:EmbeddedMonitor
阅读 18
收藏 0
点赞 0
评论 0
@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
}
OceanicBinding.java 文件源码
项目:openhab-hdl
阅读 23
收藏 0
点赞 0
评论 0
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;
}
}
ZWaveController.java 文件源码
项目:openhab-hdl
阅读 21
收藏 0
点赞 0
评论 0
@Override
public void serialEvent(SerialPortEvent arg0) {
try {
logger.trace("RXTX library CPU load workaround, sleep forever");
Thread.sleep(Long.MAX_VALUE);
} catch (InterruptedException e) {
}
}
NikobusInterface.java 文件源码
项目:openhab-hdl
阅读 19
收藏 0
点赞 0
评论 0
/**
* {@inheritDoc}
*
* Any data received from a serial event, is immediately passed on to the
* command receiver thread.
*/
@Override
public void serialEvent(SerialPortEvent event) {
if (event.getEventType() != SerialPortEvent.DATA_AVAILABLE) {
return;
}
InputStream is = null;
try {
lastEventTimestamp = System.currentTimeMillis();
is = port.getInputStream();
int available = is.available();
if (available == 0) {
log.warn("Received data available event, but no data was found!");
return;
}
byte[] buffer = new byte[available];
is.read(buffer, 0, available);
bufferQueue.add(buffer);
if (available != 1 || buffer[0] != 13) {
// don't print single CR's in log..
log.trace("Received: {}", new String(buffer));
}
} catch (IOException e) {
log.error("Error receiving data on serial port {}: {}",
port.getName(), e.getMessage());
}
}
RFXComSerialConnector.java 文件源码
项目:openhab-hdl
阅读 24
收藏 0
点赞 0
评论 0
@Override
public void serialEvent(SerialPortEvent arg0) {
try {
logger.trace("RXTX library CPU load workaround, sleep forever");
sleep(Long.MAX_VALUE);
} catch (InterruptedException e) {
}
}
EpsonProjectorSerialConnector.java 文件源码
项目:openhab-hdl
阅读 16
收藏 0
点赞 0
评论 0
@Override
public void serialEvent(SerialPortEvent arg0) {
try {
logger.trace("RXTX library CPU load workaround, sleep forever");
Thread.sleep(Long.MAX_VALUE);
} catch (InterruptedException e) {
}
}
SerialConnector.java 文件源码
项目:openhab-hdl
阅读 25
收藏 0
点赞 0
评论 0
/**
* Receives Serial Port Events and reads Serial Port Data
*/
public synchronized void serialEvent(SerialPortEvent serialPortEvent) {
if (serialPortEvent.getEventType() == SerialPortEvent.DATA_AVAILABLE) {
try {
String messageLine=serialInput.readLine();
handleIncomingMessage(messageLine);
} catch (IOException ioException) {
logger.error("serialEvent(): IO Exception: ", ioException);
}
}
}
SerialConnector.java 文件源码
项目:openhab-hdl
阅读 24
收藏 0
点赞 0
评论 0
@Override
public void serialEvent(SerialPortEvent event) {
if (event.getEventType() == SerialPortEvent.DATA_AVAILABLE) {
try {
String data = bReader.readLine();
logger.trace("Received raw message to process: '{}'", data);
notifyEventProcessors(data);
} catch (IOException e) {
logger.error("Exception while reading from serial port", e);
}
}
}
CULSerialHandlerImpl.java 文件源码
项目:openhab-hdl
阅读 19
收藏 0
点赞 0
评论 0
@Override
public void serialEvent(SerialPortEvent event) {
if (event.getEventType() == SerialPortEvent.DATA_AVAILABLE) {
try {
processNextLine();
} catch (CULCommunicationException e) {
log.error("Serial CUL connection read failed for " + deviceName);
}
}
}
UsbComm.java 文件源码
项目:Chequers
阅读 17
收藏 0
点赞 0
评论 0
public void serialEvent(SerialPortEvent evt) {
// if data available on serial port
if (evt.getEventType() == SerialPortEvent.DATA_AVAILABLE) {
try {
String inputLine = input.readLine();
System.out.println("Recieved: " + inputLine);
if (inputLine.equals("FINISHED"))
System.out.println("ACCORDING TO THE ARDUINO, ARM MOVEMENT IS COMPLETE");
} catch (Exception e) {
System.err.println(e.toString());
}
}
}
CommPortUtils.java 文件源码
项目:Brino
阅读 78
收藏 0
点赞 0
评论 0
public void serialEvent(SerialPortEvent event) {
// byte[] readBuffer = new byte[2000];
try {
while (inStream.available() > 0) {
// inStream.read(readBuffer);
SerialMonitor.display(String.valueOf((char) inStream.read()));
}
// SerialMonitor.display(new String(readBuffer));
} catch (IOException ioe) {
System.out.println("Exception " + ioe);
ioe.printStackTrace();
}
}
PortListener.java 文件源码
项目:mytourbook
阅读 17
收藏 0
点赞 0
评论 0
public void serialEvent(SerialPortEvent portEvent) {
// Determine type of event
switch (portEvent.getEventType()) {
case SerialPortEvent.DATA_AVAILABLE:
int iData = 0;
// Read data until -1 is returned
while (iData != -1) {
try {
iData = fInStream.read();
if (iData != -1) {
fDataListener.dataArrived(iData & 0xff);
}
} catch (IOException ex) {
System.out.println(ex);
return;
}
}
break;
}
}