title: Java RXTX not sending data
body: <p>I'm trying to make a Java interface to send some AT commands to a GPRS Module.</p>
  
  <p>I already had a working interface on Processing, but I migrated to pure Java because I find it easier to make graphic interfaces.</p>
  
  <p>The Processing program sends data over serial to COM#. COM# is an Arduino with a GPRS Shield. All the Arduino Code does is pass the data received to the GPRS module and viceversa:</p>
  
  <pre><code>void loop(){
      if (GPRS.available())
      {
          while(GPRS.available())
          {
              buffer[count++]=GPRS.read();
              if(count == 64)break;
          }
          Serial.write(buffer,count);
          clearBufferArray();
          count = 0;
      }
      if (Serial.available()){
                  delay(100);
                  while(Serial.available()){
                    GPRS.write(Serial.read());
                  }
          }
  }
  </code></pre>
  
  <p>So I know that works fine because I've tested it using the Processing interface, and an external tool called SSCOM and all the comands are interpreted correctly.</p>
  
  <p>Now the problem is, that when I tried to make the interface on java, using RXTX, it's not working at all. I'm not getting any errors on the console, and the only data I'm receiving on the Arduino is <code>ÿ</code> (char 255) each time I run java, and it's being sent when opening the port, not when writing to the serial port.</p>
  
  <p>Here's the <code>SerialHandler</code>class I'm using. I found it around the web.</p>
  
  <pre><code>import gnu.io.CommPortIdentifier;
  import gnu.io.NoSuchPortException;
  import gnu.io.PortInUseException;
  import gnu.io.SerialPort;
  import gnu.io.UnsupportedCommOperationException;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.OutputStream;
  
  public class SerialPortHandler {
      private SerialPort serialPort;
      private OutputStream outStream;
      private InputStream inStream;
  
      public void connect(String portName) throws IOException, PortInUseException, NoSuchPortException {
          try {
              // Obtain a CommPortIdentifier object for the port you want to open
              CommPortIdentifier portId =
                      CommPortIdentifier.getPortIdentifier(portName);
  
              // Get the port's ownership
              serialPort =
                      (SerialPort) portId.open("Demo application", 5000);
  
              // Set the parameters of the connection.
              setSerialPortParameters();
  
              // Open the input and output streams for the connection. If they won't
              // open, close the port before throwing an exception.
              outStream = serialPort.getOutputStream();
              inStream = serialPort.getInputStream();
          } catch (NoSuchPortException e) {
              throw new IOException(e.getMessage());
          } catch (PortInUseException e) {
              throw new IOException(e.getMessage());
          } catch (IOException e) {
              serialPort.close();
              throw e;
          }
      }
  
      /**
       * Get the serial port input stream
       * @return The serial port input stream
       */
      public InputStream getSerialInputStream() {
          return inStream;
      }
  
      /**
       * Get the serial port output stream
       * @return The serial port output stream
       */
      public OutputStream getSerialOutputStream() {
          return outStream;
      }
  
      /**
       * Sets the serial port parameters
       */
      private void setSerialPortParameters() throws IOException {
          int baudRate = 19200;
  
          try {
              serialPort.setSerialPortParams(
                      baudRate,
                      SerialPort.DATABITS_8,
                      SerialPort.STOPBITS_1,
                      SerialPort.PARITY_NONE);
  
              serialPort.setFlowControlMode(
                      SerialPort.FLOWCONTROL_NONE);
          } catch (UnsupportedCommOperationException ex) {
              throw new IOException("Unsupported serial port parameter");
          }
      }
  }
  </code></pre>
  
  <p>And here's my main class:</p>
  
  <pre><code>public class Main {
          SerialPortHandler serial = new SerialPortHandler();
          serial.connect("COM3");
          OutputStream serialOut = serial.getSerialOutputStream();
          String s = "AT+CPOWD=0\r\n";
          serialOut.write(s.getBytes());
          serialOut.flush();
      }
  
  }
  </code></pre>
  
  <p>rxtxSerial.dll and RXTXcomm.jar are in jre\bin and jre\lib\ext respectively.</p>
  
  <p>I can't find the problem, like I said, I don't get any errors or warnings anywhere.</p>
  
  <p>I'm using NetBeans 7.3.1, JDK 1.7 and Windows 8.1 x64.</p>
  
  <p>I also tried using <a href="https://code.google.com/p/java-simple-serial-connector/%20java-simple-serial-connector" rel="nofollow">jSSC</a> but I get the same results.</p>