Thank you for your guide, it's very accurate and refined
I need to send 620 bytes per second to Arduino.
I've run a try: I've used the first code (the one that uses the functions recvWithStartEndMarkers() and showNewData() ) of the message #1 of your guide, and I've used this Java code:
package main;
import jssc.SerialPort;
import jssc.SerialPortException;
public class CodeProjectTest1 {
  public static void main(String[] args) {
    SerialPort serialPort = new SerialPort("COM3");
    try {
      serialPort.openPort();
      serialPort.setParams(SerialPort.BAUDRATE_9600,
          SerialPort.DATABITS_8,
          SerialPort.STOPBITS_1,
          SerialPort.PARITY_NONE);
      serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_RTSCTS_IN
          | SerialPort.FLOWCONTROL_RTSCTS_OUT);
      System.out.println("String sent: " + serialPort.writeString("<Hello world>"));
    } catch (SerialPortException ex) {
      System.out.println("There is an error on writing string to port: " + ex);
    }
  }
}
This is the output in the Arduino Serial Monitor after a run of the Java program:
If I run again the Java program, I get a slightly different output in the Arduino Serial Monitor:
<Ar<Arduino is ready>
And if I run the Java program while Arduino Serial Monitor is opened, I get this output on the Java console:
run:
There is an error on writing string to port: jssc.SerialPortException: Port name - COM3; Method name - openPort(); Exception type - Port busy.
BUILD SUCCESSFUL (total time: 0 seconds)
You can't use the serial port for the Arduino Serial Monitor and for another program at the same time.
You may need to set some of the serial port parameters in JSSC. I think you may need to set rtscts to true. There is a JRuby example in this Python - Arduino demo - it may illustrate the issue. It's a good while since I wrote it.
As you said, I had to set RTS and DTR. In order to do this, I passed these arguments to setParams():
serialPort.setParams(SerialPort.BAUDRATE_9600,
          SerialPort.DATABITS_8,
          SerialPort.STOPBITS_1,
          SerialPort.PARITY_NONE,
          true, false);
where "true" is related to "setRTS" and "false" is related to "setDTR".
I'm working on a home automation system using Arduino Uno and wanted to use a JAVA server with Serial communication with the Uno and I found that I can use the JSSC library to do so but I ran into troubles.
my case is that I want the Arduino to wait for 2 consecutive values:
pin number -> corresponding to digital pin connected to a relay I want to control
value -> corresponding to HIGH or LOW
on the other hand the server asks respectively for both values and send them to the Serial port where the Arduino is connected.
BUT...I found that once I send the first value, ex: 1, relay on pin 1 directly turn on without waiting for another command.
This may mean that some garbage bytes are being sent after the 1 I sent !!
I suggest you to send Arduino the following strings:
<5,0,>
or the string:
<5,1,>
where 5 is the pin number, 0 is LOW and 1 is HIGH, "<" is the starting marker and ">" is the ending marker (in order to avoid garbage values). Then Arduino should parse it following the guide suggested by Robin2: Serial Input Basics