1

I'm trying to send command and read from rs 232 with no flow control. Sending command is successful (checked by Serial port monitoring). but no answer. when I send the exact same command from Serial port monitoring software it answers. Dose any one have any idea why?

public static void main(String[] args) {
    SerialPort serialPort = new SerialPort("COM10");
    try {

      int mask = SerialPort.MASK_RXCHAR + SerialPort.MASK_CTS + SerialPort.MASK_DSR + SerialPort.MASK_RING;


      serialPort.openPort();//Open serial port
      serialPort.setParams(9600, 8, 1, 0);//Set params.
      serialPort.setEventsMask(mask);// Set mask
      serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_XONXOFF_IN | SerialPort.FLOWCONTROL_XONXOFF_OUT );


      String command = "~ÿGjO~";          
        char[] chars = command.toCharArray();
        StringBuilder hex = new StringBuilder();
        for (char ch : chars) {
            hex.append(Integer.toHexString((int) ch));
        }

        System.out.println(command);
        serialPort.writeBytes(command.getBytes());

      byte[] buffer = serialPort.readBytes(16);//Read 10 bytes from serial port
      serialPort.closePort();//Close serial port
    }
    catch (SerialPortException ex) {
      System.out.println(ex);
    }
  }
user1699623
  • 23
  • 1
  • 5

0 Answers0