@@ -58,41 +58,6 @@ public class Serial implements SerialPortEventListener {
58
58
// for the classloading problem.. because if code ran again,
59
59
// the static class would have an object that could be closed
60
60
61
- /**
62
- * General error reporting, all correlated here just in case I think of
63
- * something slightly more intelligent to do.
64
- */
65
- static public void errorMessage (String where , Throwable e ) {
66
- Common .log (new Status (IStatus .WARNING , Const .CORE_PLUGIN_ID , "Error inside Serial. " + where , e )); //$NON-NLS-1$
67
-
68
- }
69
-
70
- /**
71
- * If this just hangs and never completes on Windows, it may be because the
72
- * DLL doesn't have its exec bit set. Why the hell that'd be the case, who
73
- * knows.
74
- */
75
- public static Vector <String > list () {
76
- try {
77
- String [] portNames ;
78
- String OS = System .getProperty ("os.name" ).toLowerCase (); //$NON-NLS-1$
79
- if (OS .indexOf ("mac" ) >= 0 ) { //$NON-NLS-1$
80
- portNames = SerialPortList .getPortNames ("/dev/" , Pattern .compile ("^cu\\ ..*(serial|usb).*" )); //$NON-NLS-1$ //$NON-NLS-2$
81
- } else {
82
- portNames = SerialPortList .getPortNames ();
83
- }
84
- return new Vector <>(Arrays .asList (portNames ));
85
- } catch (Error e ) {
86
- Common .log (new Status (IStatus .ERROR , Const .CORE_PLUGIN_ID ,
87
- "There is a config problem on your system.\n For more detail see https://github.com/jantje/arduino-eclipse-plugin/issues/252" , //$NON-NLS-1$
88
- e ));
89
- Vector <String > ret = new Vector <>();
90
- ret .add ("config error:" ); //$NON-NLS-1$
91
- ret .add ("see https://github.com/jantje/arduino-eclipse-plugin/issues/252" ); //$NON-NLS-1$
92
- return ret ;
93
- }
94
- }
95
-
96
61
SerialPort port = null ;
97
62
int rate ;
98
63
int parity ;
@@ -108,7 +73,7 @@ public static Vector<String> list() {
108
73
// RTS and DTR low.
109
74
boolean dtr = true ;
110
75
111
- String PortName ;
76
+ String portName ;
112
77
113
78
private ServiceRegistration <Serial > fServiceRegistration ;
114
79
@@ -123,7 +88,7 @@ public Serial(String iname, int irate, boolean dtr) {
123
88
}
124
89
125
90
public Serial (String iname , int irate , char iparity , int idatabits , float istopbits , boolean dtr ) {
126
- this .PortName = iname ;
91
+ this .portName = iname ;
127
92
this .rate = irate ;
128
93
this .dtr = dtr ;
129
94
@@ -144,6 +109,41 @@ public Serial(String iname, int irate, char iparity, int idatabits, float istopb
144
109
145
110
}
146
111
112
+ /**
113
+ * General error reporting, all correlated here just in case I think of
114
+ * something slightly more intelligent to do.
115
+ */
116
+ public static void errorMessage (String where , Throwable e ) {
117
+ Common .log (new Status (IStatus .WARNING , Const .CORE_PLUGIN_ID , "Error inside Serial. " + where , e )); //$NON-NLS-1$
118
+
119
+ }
120
+
121
+ /**
122
+ * If this just hangs and never completes on Windows, it may be because the
123
+ * DLL doesn't have its exec bit set. Why the hell that'd be the case, who
124
+ * knows.
125
+ */
126
+ public static Vector <String > list () {
127
+ try {
128
+ String [] portNames ;
129
+ String os = System .getProperty ("os.name" ).toLowerCase (); //$NON-NLS-1$
130
+ if (os .indexOf ("mac" ) >= 0 ) { //$NON-NLS-1$
131
+ portNames = SerialPortList .getPortNames ("/dev/" , Pattern .compile ("^cu\\ ..*(serial|usb).*" )); //$NON-NLS-1$ //$NON-NLS-2$
132
+ } else {
133
+ portNames = SerialPortList .getPortNames ();
134
+ }
135
+ return new Vector <>(Arrays .asList (portNames ));
136
+ } catch (Exception e ) {
137
+ Common .log (new Status (IStatus .ERROR , Const .CORE_PLUGIN_ID ,
138
+ "There is a config problem on your system.\n For more detail see https://github.com/jantje/arduino-eclipse-plugin/issues/252" , //$NON-NLS-1$
139
+ e ));
140
+ Vector <String > ret = new Vector <>();
141
+ ret .add ("config error:" ); //$NON-NLS-1$
142
+ ret .add ("see https://github.com/jantje/arduino-eclipse-plugin/issues/252" ); //$NON-NLS-1$
143
+ return ret ;
144
+ }
145
+ }
146
+
147
147
public void addListener (MessageConsumer consumer ) {
148
148
if (this .fConsumers == null ) {
149
149
this .fConsumers = new ArrayList <>();
@@ -166,7 +166,7 @@ public void connect(int maxTries) {
166
166
int count = 0 ;
167
167
while (true ) {
168
168
try {
169
- this .port = new SerialPort (this .PortName );
169
+ this .port = new SerialPort (this .portName );
170
170
this .port .openPort ();
171
171
this .port .setParams (this .rate , this .databits , this .stopbits , this .parity , this .dtr , this .dtr );
172
172
@@ -178,17 +178,17 @@ public void connect(int maxTries) {
178
178
if (++count == maxTries ) {
179
179
if (SerialPortException .TYPE_PORT_BUSY .equals (e .getExceptionType ())) {
180
180
Common .log (new Status (IStatus .ERROR , Const .CORE_PLUGIN_ID ,
181
- "Serial port " + this .PortName //$NON-NLS-1$
181
+ "Serial port " + this .portName //$NON-NLS-1$
182
182
+ " already in use. Try quiting any programs that may be using it" , //$NON-NLS-1$
183
183
e ));
184
184
} else if (SerialPortException .TYPE_PORT_NOT_FOUND .equals (e .getExceptionType ())) {
185
185
Common .log (new Status (IStatus .ERROR , Const .CORE_PLUGIN_ID , "Serial port " //$NON-NLS-1$
186
- + this .PortName
186
+ + this .portName
187
187
+ " not found. Did you select the right one from the project properties -> Arduino -> Arduino?" , //$NON-NLS-1$
188
188
e ));
189
189
} else {
190
190
Common .log (new Status (IStatus .ERROR , Const .CORE_PLUGIN_ID ,
191
- "Error opening serial port " + this .PortName , e )); //$NON-NLS-1$
191
+ "Error opening serial port " + this .portName , e )); //$NON-NLS-1$
192
192
}
193
193
return ;
194
194
}
@@ -225,7 +225,7 @@ public void dispose() {
225
225
}
226
226
227
227
public boolean IsConnected () {
228
- return ( this .port != null && this .port .isOpened () );
228
+ return this .port != null && this .port .isOpened ();
229
229
}
230
230
231
231
private void notifyConsumersOfData (byte [] message ) {
@@ -263,7 +263,7 @@ public void reset() {
263
263
}
264
264
265
265
@ Override
266
- synchronized public void serialEvent (SerialPortEvent serialEvent ) {
266
+ public synchronized void serialEvent (SerialPortEvent serialEvent ) {
267
267
switch (serialEvent .getEventType ()) {
268
268
case SerialPortEvent .RXCHAR :
269
269
int bytesCount = serialEvent .getEventValue ();
@@ -310,10 +310,10 @@ public void setup() {// JABA is not going to add code
310
310
// needed to fill viewers in jfases
311
311
@ Override
312
312
public String toString () {
313
- return this .PortName ;
313
+ return this .portName ;
314
314
}
315
315
316
- public void write (byte bytes [] ) {
316
+ public void write (byte [] bytes ) {
317
317
if (this .port != null ) {
318
318
try {
319
319
this .port .writeBytes (bytes );
@@ -351,13 +351,13 @@ public void write(String what) {
351
351
write (what .getBytes ());
352
352
}
353
353
354
- public void write (String what , String LineEnd ) {
354
+ public void write (String what , String lineEnd ) {
355
355
notifyConsumersOfEvent (
356
- System .getProperty ("line.separator" ) + ">>Send to " + this .PortName + ": \" " + what + "\" <<" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
356
+ System .getProperty ("line.separator" ) + ">>Send to " + this .portName + ": \" " + what + "\" <<" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
357
357
+ System .getProperty ("line.separator" )); //$NON-NLS-1$
358
358
write (what .getBytes ());
359
- if (LineEnd .length () > 0 ) {
360
- write (LineEnd .getBytes ());
359
+ if (lineEnd .length () > 0 ) {
360
+ write (lineEnd .getBytes ());
361
361
}
362
362
}
363
363
}
0 commit comments