I`m trying to send AT-command via COM-port, but reseived only the same command.
package SerialConnections;
import jssc.SerialPort;
import jssc.SerialPortEvent;
import jssc.SerialPortEventListener;
import jssc.SerialPortException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static ru.telemetria.qa.utils.Utilities.waitTime;
public class M234Serial {
private static Logger log = LoggerFactory.getLogger(M234Serial.class);
private SerialPort serialPort;
private byte[] receivedData;
private boolean isReceived;
public M234Serial() throws Exception {
serialPort = new SerialPort("COM55");
}
public void sendCommand() throws Exception {
open();
String command = "AT^SCFG?";
serialPort.writeBytes(command.getBytes());
log.debug("Send request: " + command);
while (!isReceived) {}
close();
}
private void open() throws Exception {
serialPort.openPort();
serialPort.setParams(SerialPort.BAUDRATE_115200, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
serialPort.addEventListener(new SerialPortEventListener() {
@Override
public void serialEvent(SerialPortEvent serialPortEvent) {
try {
waitTime(System.currentTimeMillis(), 2000);
receivedData = serialPort.readBytes();
log.debug("Received message: " + StringUtils.asciiToString(receivedData));
isReceived = true;
serialPort.removeEventListener();
} catch (SerialPortException spe) {
spe.printStackTrace();
}
}
});
}
private void close() throws Exception {
serialPort.closePort();
}
public static void main(String[] args) throws Exception {
log.debug("Create instance..");
M234Serial serial = new M234Serial();
serial.sendCommand();
log.debug("End");
}
}
Log:
16:19:21.910 [main] DEBUG SerialConnections.M234Serial - Create instance..
16:19:21.974 [main] DEBUG SerialConnections.M234Serial -Send request: AT^SCFG?
16:19:23.976 [EventThread COM55] DEBUG SerialConnections.M234Serial - Received message: AT^SCFG?
16:19:23.977 [main] DEBUG SerialConnections.M234Serial - End
What am I doing wrong and how can I fix it?