コード例 #1
0
 // TODO: This a guess!!...untested!!
 public byte[] read() {
   try {
     serialConnection.readStaleData();
     long start = currentTimeMillis();
     while (currentTimeMillis() - start <= sendTimeout) {
       if (serialConnection.available() > 10) {
         byte[] bytes = serialConnection.readAvailable();
         LOGGER.trace("AEM UEGO input: " + asHex(bytes));
         int startIndex = findStart(bytes);
         LOGGER.trace("AEM UEGO start index: " + startIndex);
         if (startIndex < 0 || startIndex >= bytes.length) continue;
         List<Byte> buffer = new ArrayList<Byte>();
         for (int i = startIndex; i < bytes.length; i++) {
           byte b = bytes[i];
           if (b == (byte) 0x0D) {
             byte[] response = toArray(buffer);
             LOGGER.trace("AEM UEGO Response: " + asHex(response));
             return response;
           } else {
             buffer.add(b);
           }
         }
       }
       sleep(1);
     }
     LOGGER.warn("AEM UEGO Response [read timeout]");
     return new byte[0];
   } catch (Exception e) {
     close();
     throw new SerialCommunicationException(e);
   }
 }
コード例 #2
0
 public void close() {
   serialConnection.close();
   LOGGER.info("AEM disconnected");
 }