public void initilize2() {
    int i;
    msg = s2.toCharArray();
    for (i = 0; i < s2.length(); i++) {
      try {
        dos.write(msg[i]);
        // System.out.print(msg[i]);
      } catch (Exception e) {
        System.out.print("init 2 send" + e);
      }
    }

    try {

      while ((rs = dis.readLine()) != null) {
        // System.out.println(rs);
        if (rs.equals("OK")) {
          break;
        }
        if (rs.equals("ERROR")) {
          break;
        }
      }

    } catch (Exception e) {
      System.out.println("init 2 rec" + e);
    }
  }
コード例 #2
0
ファイル: Logger.java プロジェクト: ekiwi/tinyos-1.x
  public static void reset() {
    // network@ip:10002
    String address = source.substring(8, source.length() - 6);

    try {
      Socket server = new Socket(address, 9999);
      DataOutputStream out = new DataOutputStream(server.getOutputStream());
      out.writeBytes("\r\n");
      out.flush();
      out.writeBytes("9\r\n");
      out.flush();
    } catch (Exception e) {
      System.out.println("Sorry I can't reset the device fro some reason: " + e);
      System.exit(1);
    }
    System.out.println("Issued reset command to " + address);
  }
 public void connectionclose() {
   try {
     is.close();
     os.close();
     dis.close();
     dos.close();
     sPort.close();
   } catch (Exception e) {
     System.out.println("close" + e);
   }
 }
  public void read() {
    int i, j, k;
    String temp = "";
    String temp1 = "";

    msg = s3.toCharArray();
    for (i = 0; i < s3.length(); i++) {
      try {
        dos.write(msg[i]);
        // System.out.println(msg[i]);
      } catch (Exception e) {
        System.out.print("read send" + e);
      }
    }
    try {
      while ((rs = dis.readLine()) != null) {
        temp += rs;
        if (rs.equals("OK")) break;
        if (rs.equals("ERROR")) break;
      }

      k = 0;
      StringTokenizer t = new StringTokenizer(temp, "\"");
      while (t.hasMoreTokens()) {
        temp1 = "" + t.nextToken().trim();
        k++;
        if (k == 7) {
          System.out.println(temp1);
          VoiceManager voiceManager = VoiceManager.getInstance();
          Voice helloVoice = voiceManager.getVoice("kevin");
          helloVoice.allocate();
          helloVoice.speak(temp1);
          helloVoice.deallocate();
        }
      }

    } catch (Exception e) {
      System.out.print("read rec" + e);
    }
  }
  public void delete() {
    int i;
    msg = s4.toCharArray();
    try {
      for (i = 0; i < s4.length(); i++) {
        dos.write(msg[i]);
        System.out.print(msg[i]);
      }

    } catch (Exception e) {
      System.out.print("del send" + e);
    }
    try {
      while ((rs = dis.readLine()) != null) {
        System.out.println(rs);
        if (rs.equals("OK")) break;
        if (rs.equals("ERROR")) break;
        if (rs.equals("+CMS ERROR: 321")) break;
      }
    } catch (Exception e) {
      System.out.print("del rec" + e);
    }
  }