I am trying to close a Comm port using this:
public synchronized void closeComportButtonActionPerformed(
java.awt.event.ActionEvent evt) {
try {
twoWaySerCom.disconnect();
} catch (Exception e) {
e.printStackTrace();
}
}
and my disconnect is this:
void disconnect() throws Exception {
if (serialPort != null) {
InputStream in = serialPort.getInputStream();
OutputStream out = serialPort.getOutputStream();
try {
// close the i/o streams.
in.close();
out.close();
} catch (IOException ex) {
// don't care
}
// Close the port.
serialPort.close();
}
When i press the close button my app is just freezing and i eventually get an error in my console saying:
A fatal error has been detected by the Java Runtime Environment:
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00949e69, pid=7568, tid=4724
#
# JRE version: Java(TM) SE Runtime Environment (8.0_25-b18) (build 1.8.0_25-b18)
# Java VM: Java HotSpot(TM) Client VM (25.25-b02 mixed mode, sharing windows-x86 )
# Problematic frame:
# C [rxtxSerial.dll+0x9e69]
Can anyone explain what i have done wrong here? Thanks
This was partially resolved with the below. I can now successfully close the port once. If i re-open te port and then attempt to close it a second time then the same error occurs.
try {
serialPort.removeEventListener();
serialPort.close();
in.close();
out.close();
} catch (IOException ex) {
// don't care
}
// Close the port.
serialPort.close();
}