Skip to content

Commit 3670cb1

Browse files
author
jantje
committed
fix for #325
When you select a project (or more) and click on open serial port button on the toolbar (or in the arduino menu)The plugin will open serial connections for all selected projects based on the com port provided in the project properties and the baud rate in the Serial.begin in the arduino code
1 parent add7005 commit 3670cb1

File tree

7 files changed

+49
-123
lines changed

7 files changed

+49
-123
lines changed

it.baeyens.arduino.core/META-INF/MANIFEST.MF

+2-4
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,12 @@ Require-Bundle: org.eclipse.core.runtime,
1313
org.eclipse.cdt.core,
1414
org.eclipse.equinox.security;bundle-version="1.1.100",
1515
com.google.gson,
16-
org.apache.commons.compress,
17-
org.eclipse.ui.navigator
16+
org.apache.commons.compress
1817
Bundle-Vendor: Jan Baeyens
1918
Bundle-ActivationPolicy: lazy
20-
Export-Package: it.baeyens.arduino.tools,
21-
it.baeyens.arduino.ui
2219
Import-Package: it.baeyens.arduino.arduino,
2320
it.baeyens.arduino.common,
21+
it.baeyens.arduino.monitor,
2422
org.apache.commons.io;version="1.2.0",
2523
org.eclipse.cdt.core,
2624
org.eclipse.cdt.core.envvar,

it.baeyens.arduino.core/src/it/baeyens/arduino/actions/OpenSerialMonitorHandler.java

+11-12
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* serial monitor
3131
*
3232
*
33-
* The code looks for all selected projeects for the com port and the baudrate
33+
* The code looks for all selected projects for the com port and the baudrate
3434
* and connects if they both are found
3535
*
3636
* @author jan
@@ -54,10 +54,7 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
5454
String comPort = Common.getBuildEnvironmentVariable(curproject,
5555
ArduinoConst.ENV_KEY_JANTJE_COM_PORT, "");
5656
if (!comPort.isEmpty()) {
57-
58-
// it.baeyens.arduino.monitor.views.connectSerial(comPort,
59-
// Integer.toString(baud));
60-
// SerialPortsUpdated();
57+
it.baeyens.arduino.monitor.SerialConnection.add(comPort, baud);
6158
}
6259
}
6360
}
@@ -90,17 +87,19 @@ private int getBaudRate(IProject iProject) {
9087
index = CCorePlugin.getIndexManager().getIndex(curProject);
9188
index.acquireReadLock();
9289
// find bindings for name
93-
IIndexBinding[] bindings = index.findBindings(setupFunctionName.toCharArray(),
94-
IndexFilter.ALL_DECLARED_OR_IMPLICIT, new NullProgressMonitor());
95-
if (bindings.length != 1) {
96-
// there should be just 1 setup function
97-
return -1;
90+
IIndexBinding[] bindings = index.findBindings(setupFunctionName.toCharArray(), IndexFilter.ALL_DECLARED,
91+
new NullProgressMonitor());
92+
ICPPFunction setupFunc = null;
93+
for (IIndexBinding curbinding : bindings) {
94+
if (curbinding instanceof ICPPFunction) {
95+
setupFunc = (ICPPFunction) curbinding;
96+
}
97+
9898
}
9999

100-
if (!(bindings[0] instanceof ICPPFunction)) {
100+
if (setupFunc == null) {
101101
return -2;// that on found binding must be a function
102102
}
103-
ICPPFunction setupFunc = (ICPPFunction) bindings[0];
104103

105104
IIndexName[] names = index.findNames(setupFunc, org.eclipse.cdt.core.index.IIndex.FIND_DEFINITIONS);
106105
if (names.length != 1) {

it.baeyens.arduino.monitor/META-INF/MANIFEST.MF

+1-8
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,6 @@ Require-Bundle: org.eclipse.ui,
1010
it.baeyens.arduino.common
1111
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
1212
Bundle-ActivationPolicy: lazy
13-
Export-Package: it.baeyens.arduino.monitor;uses:="org.eclipse.jface.resource,org.eclipse.ui.plugin,org.osgi.framework",
14-
it.baeyens.arduino.monitor.views;
15-
uses:="it.baeyens.arduino.arduino,
16-
org.eclipse.jface.viewers,
17-
org.eclipse.ui.part,
18-
org.eclipse.swt.widgets,
19-
it.baeyens.arduino.common,
20-
org.eclipse.jface.dialogs"
13+
Export-Package: it.baeyens.arduino.monitor;uses:="org.eclipse.jface.resource,org.eclipse.ui.plugin,org.osgi.framework"
2114
Bundle-ClassPath: .,
2215
lib/org.eclipse.nebula.widgets.oscilloscope_1.2.0.201310192144.jar

it.baeyens.arduino.monitor/plugin.xml

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<?eclipse version="3.4"?>
33
<plugin>
4-
<extension-point id="it.baeyens.arduino.monitor" name="A serial monitor" schema="schema/it.baeyens.arduino.monitor.exsd"/>
54
<extension point="org.eclipse.ui.views">
65
<category
76
name="Arduino"

it.baeyens.arduino.monitor/schema/it.baeyens.arduino.monitor.exsd

-84
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
package it.baeyens.arduino.monitor;
22

3+
import it.baeyens.arduino.monitor.views.SerialMonitor;
4+
35
public class SerialConnection {
4-
static void add(String comPort, int baudrate) {
6+
public static void add(String comPort, int baudrate) {
7+
SerialMonitor.getSerialMonitor().connectSerial(comPort, baudrate);
58

69
}
710

8-
static void remove(String comPort) {
9-
11+
public static void remove(String comPort) {
12+
SerialMonitor.getSerialMonitor().disConnectSerialPort(comPort);
1013
}
1114

1215
}

it.baeyens.arduino.monitor/src/it/baeyens/arduino/monitor/views/SerialMonitor.java

+29-11
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,24 @@ public class SerialMonitor extends ViewPart implements ISerialUser {
106106
protected boolean myAutoScroll; // is auto scroll on or off?
107107
private static final String myFlagMonitor = "FmStatus"; //$NON-NLS-1$
108108
String uri = "h tt p://ba eye ns. i t/ec li pse/d ow nlo ad/mo nito rSta rt.ht m l?m="; //$NON-NLS-1$
109+
private static SerialMonitor me = null;
110+
111+
public static SerialMonitor getSerialMonitor() {
112+
if (me == null) {
113+
me = new SerialMonitor();
114+
}
115+
return me;
116+
}
109117

110118
/**
111119
* The constructor.
112120
*/
113121
public SerialMonitor() {
122+
if (me != null) {
123+
Common.log(new Status(IStatus.ERROR, ArduinoConst.CORE_PLUGIN_ID, "You can only have one serial monitor"));
124+
125+
}
126+
me = this;
114127
this.mySerialConnections = new LinkedHashMap<>(myMaxSerialPorts);
115128
IThemeManager themeManager = PlatformUI.getWorkbench().getThemeManager();
116129
ITheme currentTheme = themeManager.getCurrentTheme();
@@ -356,7 +369,7 @@ public void widgetDefaultSelected(SelectionEvent e) {
356369
*
357370
* @return the serial port selected in the combobox
358371
*/
359-
Serial GetSelectedSerial() {
372+
private Serial GetSelectedSerial() {
360373
return GetSerial(this.mySerialPorts.getCombo().getText());
361374
}
362375

@@ -402,7 +415,7 @@ public void run() {
402415
comportSelector.create();
403416
if (comportSelector.open() == Window.OK) {
404417
connectSerial(comportSelector.GetComPort(), comportSelector.GetBaudRate());
405-
SerialPortsUpdated();
418+
406419
}
407420
}
408421
};
@@ -414,15 +427,7 @@ public void run() {
414427
this.myDisconnectSerialPort = new Action() {
415428
@Override
416429
public void run() {
417-
Serial newSerial = GetSelectedSerial();
418-
if (newSerial != null) {
419-
SerialListener theListener = SerialMonitor.this.mySerialConnections.get(newSerial);
420-
SerialMonitor.this.mySerialConnections.remove(newSerial);
421-
newSerial.removeListener(theListener);
422-
newSerial.dispose();
423-
theListener.dispose();
424-
SerialPortsUpdated();
425-
}
430+
disConnectSerialPort(getSerialMonitor().mySerialPorts.getCombo().getText());
426431
}
427432
};
428433
this.myDisconnectSerialPort.setText(Messages.SerialMonitor_disconnected_from);
@@ -508,6 +513,7 @@ public void connectSerial(String ComPort, int BaudRate) {
508513
theListener.event(System.getProperty("line.separator") + Messages.SerialMonitor_connectedt_to + ComPort //$NON-NLS-1$
509514
+ Messages.SerialMonitor_at + BaudRate + System.getProperty("line.separator")); //$NON-NLS-1$
510515
this.mySerialConnections.put(newSerial, theListener);
516+
SerialPortsUpdated();
511517
return;
512518
}
513519
} else {
@@ -517,6 +523,18 @@ public void connectSerial(String ComPort, int BaudRate) {
517523

518524
}
519525

526+
public void disConnectSerialPort(String comPort) {
527+
Serial newSerial = GetSerial(comPort);
528+
if (newSerial != null) {
529+
SerialListener theListener = SerialMonitor.this.mySerialConnections.get(newSerial);
530+
SerialMonitor.this.mySerialConnections.remove(newSerial);
531+
newSerial.removeListener(theListener);
532+
newSerial.dispose();
533+
theListener.dispose();
534+
SerialPortsUpdated();
535+
}
536+
}
537+
520538
/**
521539
*
522540
*/

0 commit comments

Comments
 (0)