title: Send a String to serial port as a command for embedded device
body: <p>I am working on a project that involves an embedded device. I am expected to send a command to this device. This command is a string: "LAMP1_ON\r\n";</p>
  
  <p>I am using RXTX with java and sending the data via serial port. But when i send the String command, the device receives "AMP_N" and some other scattered string.</p>
  
  <p>I have no idea why it is so, and how i can fix it.</p>
  
  <p>My code is below:</p>
  
  <pre><code>public class SerialWriter implements Runnable {
  
      OutputStream out;
      String str;
      public SerialWriter(OutputStream out, String str) {
          this.out = out;
          this.str = str;
      }
  
      public void run() {
          try {
  
              byte[] array = this.str.getBytes();
  
                  this.out.write(array);
                  this.out.flush();
  
          } catch (IOException e) {
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>I expect to send the string to the port via the write method. It works but it doesn't send the exact String that is contained in <code>this.str</code> instead it sends "AMP_N" and "AMP" and scattered Strings</p>