Exemplo n.º 1
0
 private void setDtrRts(boolean on) {
   if (on) {
     mComm.setDtrRts(true, true);
   } else {
     mComm.setDtrRts(false, false);
   }
 }
Exemplo n.º 2
0
  // タイムアウト型にしないとデータがうまくひろえない場合がある
  private int recv(byte[] buf, int length) {
    int retval = 0;
    int totalRetval = 0;
    long endTime;
    long startTime = System.currentTimeMillis();
    byte[] tmpbuf = new byte[length];

    while (true) {
      retval = mComm.read(tmpbuf, length);
      //            retval = mSerial.read(tmpbuf);
      if (retval > 0) {
        System.arraycopy(tmpbuf, 0, buf, totalRetval, retval);
        totalRetval += retval;
        startTime = System.currentTimeMillis();
        if (DEBUG_SHOW_RECV) {
          Log.d(TAG, "recv(" + retval + ") : " + toHexStr(buf, totalRetval));
        }
      }
      if (totalRetval >= length) {
        break;
      }

      endTime = System.currentTimeMillis();
      if ((endTime - startTime) > 250) {
        Log.e(TAG, "recv timeout.");
        break;
      }
    }
    return retval;
  }
Exemplo n.º 3
0
 private int send(byte[] buf, int length) {
   int retval = mComm.write(buf, length);
   if (DEBUG_SHOW_SEND) {
     if (retval > 0) {
       String str = "";
       for (int i = 0; i < retval; i++) {
         str += toHexStr(buf[i]) + " ";
       }
       Log.d(TAG, "send(" + retval + ") : " + str);
     }
   }
   return retval;
 }
Exemplo n.º 4
0
 // リードバッファをカラにする
 private int drain() {
   byte[] buf = new byte[1];
   int retval = 0;
   long endTime;
   long startTime = System.currentTimeMillis();
   while (true) {
     retval = mComm.read(buf, 1);
     if (retval > 0) {
       //                startTime = System.currentTimeMillis();
       if (DEBUG_SHOW_DRAIN) {
         Log.d(TAG, "drain(" + retval + ") : " + toHexStr(buf[0]));
       }
     }
     endTime = System.currentTimeMillis();
     if ((endTime - startTime) > 1000) {
       break;
     }
   }
   return retval;
 }