()
| 2172 | } |
| 2173 | |
| 2174 | public void handleSerial() { |
| 2175 | if(serialPlotter != null) { |
| 2176 | if(serialPlotter.isClosed()) { |
| 2177 | serialPlotter = null; |
| 2178 | } else { |
| 2179 | statusError(tr("Serial monitor not available while plotter is open")); |
| 2180 | return; |
| 2181 | } |
| 2182 | } |
| 2183 | |
| 2184 | if (serialMonitor != null) { |
| 2185 | // The serial monitor already exists |
| 2186 | |
| 2187 | if (serialMonitor.isClosed()) { |
| 2188 | serialMonitor.dispose(); |
| 2189 | // If it's closed, clear the refrence to the existing |
| 2190 | // monitor and create a new one |
| 2191 | serialMonitor = null; |
| 2192 | } |
| 2193 | else { |
| 2194 | // If it's not closed, give it the focus |
| 2195 | try { |
| 2196 | serialMonitor.toFront(); |
| 2197 | serialMonitor.requestFocus(); |
| 2198 | return; |
| 2199 | } catch (Exception e) { |
| 2200 | // noop |
| 2201 | } |
| 2202 | } |
| 2203 | } |
| 2204 | |
| 2205 | BoardPort port = Base.getDiscoveryManager().find(PreferencesData.get("serial.port")); |
| 2206 | |
| 2207 | if (port == null) { |
| 2208 | statusError(I18n.format(tr("Board at {0} is not available"), PreferencesData.get("serial.port"))); |
| 2209 | return; |
| 2210 | } |
| 2211 | |
| 2212 | serialMonitor = new MonitorFactory().newMonitor(port); |
| 2213 | |
| 2214 | if (serialMonitor == null) { |
| 2215 | String board = port.getPrefs().get("board"); |
| 2216 | String boardName = BaseNoGui.getPlatform().resolveDeviceByBoardID(BaseNoGui.packages, board); |
| 2217 | statusError(I18n.format(tr("Serial monitor is not supported on network ports such as {0} for the {1} in this release"), PreferencesData.get("serial.port"), boardName)); |
| 2218 | return; |
| 2219 | } |
| 2220 | |
| 2221 | base.addEditorFontResizeListeners(serialMonitor); |
| 2222 | Base.setIcon(serialMonitor); |
| 2223 | |
| 2224 | // If currently uploading, disable the monitor (it will be later |
| 2225 | // enabled when done uploading) |
| 2226 | if (uploading || avoidMultipleOperations) { |
| 2227 | try { |
| 2228 | serialMonitor.suspend(); |
| 2229 | } catch (Exception e) { |
| 2230 | statusError(e); |
| 2231 | } |
no test coverage detected