Working code for bidirectional communication using protocol buffers
This commit is contained in:
@@ -37,6 +37,7 @@ public class Local extends AbstractArduino {
|
||||
public void send(byte[] buffer) throws ArduinoException {
|
||||
try {
|
||||
outputStream.write(buffer);
|
||||
outputStream.flush();
|
||||
} catch (IOException e) {
|
||||
throw new ArduinoException("Failed to write to arduino");
|
||||
}
|
||||
|
||||
@@ -22,15 +22,11 @@ public class ParsingPort extends Port {
|
||||
|
||||
public void serialEvent(SerialPortEvent event) {
|
||||
try {
|
||||
Method m = messageClass.getMethod("parseDelimitedFrom", InputStream.class);
|
||||
Object object = m.invoke(null, inputStream);
|
||||
Method method = messageClass.getMethod("parseDelimitedFrom", InputStream.class);
|
||||
Object object = method.invoke(null, inputStream);
|
||||
for (Listen<Object> listen : listenList) {
|
||||
listen.add(object);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("", e);
|
||||
} catch (Throwable e) {
|
||||
logger.error("", e);
|
||||
}
|
||||
} catch (Exception e) {} catch (Throwable e) {} finally {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,13 +68,14 @@ public class Port implements SerialPortEventListener {
|
||||
CommPortIdentifier portid = null;
|
||||
Enumeration<?> portEnum = CommPortIdentifier.getPortIdentifiers();
|
||||
while (portEnum.hasMoreElements()) {
|
||||
portid = (CommPortIdentifier)portEnum.nextElement();
|
||||
portid = (CommPortIdentifier) portEnum.nextElement();
|
||||
if (portid != null) {
|
||||
System.out.println("Trying: " + portid.getName());
|
||||
for ( String portName: PORT_NAMES) {
|
||||
if (portid.getName().equals(portName) || portid.getName().contains(portName)) {
|
||||
try {
|
||||
serialPort = (SerialPort) portid.open("", TIME_OUT);
|
||||
serialPort.setSerialPortParams(19200, 8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
|
||||
serialPort.setFlowControlMode(
|
||||
SerialPort.FLOWCONTROL_XONXOFF_IN +
|
||||
SerialPort.FLOWCONTROL_XONXOFF_OUT);
|
||||
|
||||
Reference in New Issue
Block a user