Closed habuif closed 1 year ago
What version of JSerialComm are you using? What OS are you running? What processor architecture are you using (armv5, armv6, armv7, armv8_32, armv8_64, ppc64le, x86, or x86_64) What Java version are you using? Can you please provide a small sample program?
I've tested with JSerial Comm 2.8.3 and 2.10.3 but both didnt work. Im using windows 11 with x64 processor architecture. Also, im using jdk17.0.7.7 I'm using javafx.concurrent.Service to manage creating and closing the Serial Port.
This is the code:
protected Task createTask() { return new Task() { @Override protected Object call() throws Exception { serialPort.setComPortParameters(PortSettingsController.getBaudRate(), PortSettingsController.getDataBits(), PortSettingsController.getStopBits(), PortSettingsController.getParity()); serialPort.setComPortTimeouts(SerialPort.TIMEOUT_READ_SEMI_BLOCKING,100,100);
if(serialPort.openPort(500)){
System.out.println("Open Successfully:" + serialPort.isOpen());
InputStreamReader inputStreamReader = new InputStreamReader(serialPort.getInputStream());
Scanner reader = new Scanner(inputStreamReader);
Pattern pattern = Pattern.compile("ww.*");
while(reader.hasNextLine()){
if(!isCancelled()){
Matcher matcher = pattern.matcher(reader.nextLine());
System.out.println(reader.nextLine());
if (matcher.find()){
String find = matcher.group().substring(2,matcher.group().length()-2).strip();
updateValue(find);
}
}else {
System.out.println("broke");
break;
}
}
reader.close();
inputStreamReader.close();
serialPort.closePort();
for ( SerialPort serialPort1 : SerialPort.getCommPorts()) {
System.out.println(serialPort1.getSystemPortName());
}
System.out.println("_____________");
}else {
System.out.println("Open failed");
}
return null;
}
};
I've initialize the SerialPort as:
private static volatile SerialPort serialPort = SerialPort.getCommPort("COM6");
When i try to switch my device to different ComPort this problem still arises.
1) Are your PortSettingsController.getXXX()
functions returning the internal jSerialComm
Constants for the respective items (data bits, stop bits, etc.)?
2) You are using TIMEOUT_READ_SEMI_BLOCKING
along with a Java Scanner...I believe there is a Scanner-specific TIMEOUT (TIMEOUT_SCANNER
) that you should be using to make sure it returns from a stalled scan.
3) When you say you can't re-open, do you mean you simply close in software then try to re-open in software, or do you mean something more involved (like physically unplugging the device, then plugging it back in and trying to re-open)?
Everytime i close the port it returns true. I dont understand why the problem is happening. When i used getLastErrorCode() and getLastErrorLocation(), it returned 31 and 850 respectively.
Same issue as #518.
Closing as duplicate issue of #518.
Hi. I cant openPort() successfully if i dont re-plug my usb - serial converter. And i can only openPort successfully once. If i close the port and try to re-open it without re-plugging the usb-serial converter, it wont work. Please help..