public synchronized void sendEvent(RobotEvent ev) {
   try {
     output.write(ev.toStringSend().getBytes()); // write needs a byte array instead of a string
     long milli = (long) (1.0 / ((float) serialPort.getBaudRate() / (8.0 * 16.0)) * 1000.0);
     long nano =
         (long) (1.0 / ((float) serialPort.getBaudRate() / (8.0 * 16.0)) * 1000000000.0)
             - milli * 1000000;
     Thread.sleep((int) milli, (int) nano);
   } catch (Exception e) {
   }
 }
Example #2
0
 private void printPortStatus() {
   System.out.println("baud rate: " + port.getBaudRate());
   System.out.println("data bits: " + port.getDataBits());
   System.out.println("stop bits: " + port.getStopBits());
   System.out.println("parity:    " + port.getParity());
 }