title: Java serial port Problem
body: <p>I am trying to turn the relay on/off but so far i couldnt succeed. I tried Coolterm program to see if the drivers were installed correctly and yes it worked and i was able to turn it on/off via GUI. However I have problem to send the command via java to turn the relay on..</p>
  
  <p>Communication Parameters:
  8 Data, 1 Stop, No Parity
  Baud rate : 9600 </p>
  
  <p>Commands:
  OFF command: FF 01 00 (HEX) or 255 1 0 (DEC)</p>
  
  <p>ON command: FF 01 01 (HEX) or 255 1 1 (DEC)</p>
  
  <p>My code is below:</p>
  
  <pre><code>public class Application {
  
  InputStream in;
  OutputStream out;
  String dataHex = "FF 01 01";
  
  void connect(String portName) throws Exception {
  
  CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(portName);
  System.out.println(portIdentifier);
  CommPort commPort = portIdentifier.open(this.getClass().getName(), 2000);
  System.out.println(commPort);
  SerialPort serialPort = (SerialPort) commPort;
  System.out.println(serialPort);
  serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
  
  this.in = serialPort.getInputStream();
  this.out = serialPort.getOutputStream();
  
  System.out.println(dataHex.getBytes());
  out.write(dataHex.getBytes());
  
  System.out.println("end");
  
  
  }
  
  InputStream getIn() {
  return this.in;
  }
  
  OutputStream getOut() {
  return this.out;
  }
  
  public static void main(String args[]) throws QTException, FileNotFoundException, IOException {
  Application app = new Application();
  try {
  
  app.connect("/dev/tty.usbserial-A400953X");
  
  } catch (Exception e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
  }
  
  
  }
  }
  </code></pre>
  
  <p>Thanks in advance...</p>