public void ClosePort() { if (portOpened) { if (serialPort != null) { try { // Close the I/O streams. out.close(); in.close(); // Close the port. serialPort.removeEventListener(); serialPort.close(); } catch (IOException e) { // Don't care } } ClearLog(); portOpened = false; portConfirmed = false; previewPane.setConnected(false); UpdateMenuBar(); } }
/** * Complete the handshake, load robot-specific configuration, update the menu, repaint the preview * with the limits. * * @return true if handshake succeeds. */ public boolean ConfirmPort() { if (portConfirmed == true) return true; String hello = "HELLO WORLD! I AM DRAWBOT #"; int found = line3.lastIndexOf(hello); if (found >= 0) { portConfirmed = true; // get the UID reported by the robot String[] lines = line3.substring(found + hello.length()).split("\\r?\\n"); if (lines.length > 0) { try { robot_uid = Long.parseLong(lines[0]); } catch (NumberFormatException e) { } } // new robots have UID=0 if (robot_uid == 0) GetNewRobotUID(); mainframe.setTitle("Drawbot #" + Long.toString(robot_uid) + " connected"); // load machine specific config GetRecentPaperSize(); LoadConfig(); if (limit_top == 0 && limit_bottom == 0 && limit_left == 0 && limit_right == 0) { UpdateConfig(); } previewPane.setMachineLimits(limit_top, limit_bottom, limit_left, limit_right); SendConfig(); UpdateMenuBar(); previewPane.setConnected(true); } return portConfirmed; }