0

I'm using Netbeans to make a jfx app that talks to an arduino Uno. I have installed RXTX on my 64 bit OS X box and it seems to be working.

In the main controller of the application in the initialize() method I do this:

 CommPortIdentifier  portId = CommPortIdentifier.getPortIdentifier("/dev/tty.usbmodem1d1111");
 this.serialPort = (SerialPort) portId.open("Box App", 1000);
 // this.serialPort.close(); 

This is great except that when I close the application's only window without calling that serialPort.close() function, the app/jvm stays running in the background. I've tried overriding the dispose() method of the controller and adding Platform.exit(). Platform.setImplicitExit(true); is set to true, explicitly.

Not sure what else I can do. If a user closes the app before the serial I/O is done, apparently it will just hang. How can I force the port closed when the application window is closed?

adarshr
  • 61,315
  • 23
  • 138
  • 167
Binary
  • 21
  • 4

1 Answers1

1

This code:

   topFrame.addWindowListener(new WindowListener()
        {
            public void windowClosing(WindowEvent e)
            {
                emsClient.close();
            }
            public void windowOpened(WindowEvent e) {
            }
            public void windowClosed(WindowEvent e) {
            }
            public void windowIconified(WindowEvent e) {
            }
            public void windowDeiconified(WindowEvent e) {
            }
            public void windowActivated(WindowEvent e) {
            }
            public void windowDeactivated(WindowEvent e) {
            }
        });`

will help you attach event to close window

BVdjV
  • 116
  • 1
  • 1
  • 11