@@ -84,8 +84,7 @@ public Serial(String iname, int irate) {
84
84
this (iname , irate , 'N' , 8 , 1.0f );
85
85
}
86
86
87
- public Serial (String iname , int irate , char iparity , int idatabits ,
88
- float istopbits ) {
87
+ public Serial (String iname , int irate , char iparity , int idatabits , float istopbits ) {
89
88
PortName = iname ;
90
89
this .rate = irate ;
91
90
@@ -107,57 +106,40 @@ public Serial(String iname, int irate, char iparity, int idatabits,
107
106
}
108
107
109
108
private void registerService () {
110
- fServiceRegistration = FrameworkUtil .getBundle (getClass ())
111
- .getBundleContext ().registerService (Serial .class , this , null );
109
+ fServiceRegistration = FrameworkUtil .getBundle (getClass ()).getBundleContext ().registerService (Serial .class , this , null );
112
110
}
113
111
114
112
public void connect () {
115
113
if (port == null ) {
116
114
try {
117
- CommPortEnumerator portList = CommPortIdentifier
118
- .getPortIdentifiers ();
115
+ CommPortEnumerator portList = CommPortIdentifier .getPortIdentifiers ();
119
116
while (portList .hasMoreElements ()) {
120
- CommPortIdentifier portId = (CommPortIdentifier ) portList
121
- .nextElement ();
117
+ CommPortIdentifier portId = (CommPortIdentifier ) portList .nextElement ();
122
118
123
119
if (portId .getPortType () == CommPortIdentifier .PORT_SERIAL ) {
124
120
if (portId .getName ().equals (PortName )) {
125
- port = (SerialPort ) portId .open ("serial madness" ,
126
- 2000 );
121
+ port = (SerialPort ) portId .open ("serial madness" , 2000 );
127
122
input = port .getInputStream ();
128
123
output = port .getOutputStream ();
129
- port .setSerialPortParams (rate , databits , stopbits ,
130
- parity );
124
+ port .setSerialPortParams (rate , databits , stopbits , parity );
131
125
port .addEventListener (this );
132
126
port .notifyOnDataAvailable (true );
133
127
}
134
128
}
135
129
}
136
130
} catch (PortInUseException e ) {
137
- Common .log (new Status (
138
- IStatus .ERROR ,
139
- ArduinoConst .CORE_PLUGIN_ID ,
140
- "Serial port "
141
- + PortName
142
- + " already in use. Try quiting any programs that may be using it" ,
143
- e ));
131
+ Common .log (new Status (IStatus .ERROR , ArduinoConst .CORE_PLUGIN_ID , "Serial port " + PortName
132
+ + " already in use. Try quiting any programs that may be using it" , e ));
144
133
return ;
145
134
} catch (Exception e ) {
146
- Common .log (new Status (IStatus .ERROR ,
147
- ArduinoConst .CORE_PLUGIN_ID ,
148
- "Error opening serial port " + PortName , e ));
135
+ Common .log (new Status (IStatus .ERROR , ArduinoConst .CORE_PLUGIN_ID , "Error opening serial port " + PortName , e ));
149
136
return ;
150
137
}
151
138
152
139
if (port == null ) {
153
140
// jaba 28 feb 2012. I made the log below a warning for issue #7
154
- Common .log (new Status (
155
- IStatus .WARNING ,
156
- ArduinoConst .CORE_PLUGIN_ID ,
157
- "Serial port "
158
- + PortName
159
- + " not found. Did you select the right one from the project properties -> Arduino -> Arduino?" ,
160
- null ));
141
+ Common .log (new Status (IStatus .WARNING , ArduinoConst .CORE_PLUGIN_ID , "Serial port " + PortName
142
+ + " not found. Did you select the right one from the project properties -> Arduino -> Arduino?" , null ));
161
143
return ;
162
144
}
163
145
}
@@ -392,11 +374,8 @@ public int readBytesUntil(int interesting, byte outgoing[]) {
392
374
393
375
int length = found - bufferIndex + 1 ;
394
376
if (length > outgoing .length ) {
395
- Common .log (new Status (IStatus .WARNING ,
396
- ArduinoConst .CORE_PLUGIN_ID ,
397
- "readBytesUntil() byte buffer is too small for the "
398
- + length + " bytes up to and including char "
399
- + interesting , null ));
377
+ Common .log (new Status (IStatus .WARNING , ArduinoConst .CORE_PLUGIN_ID , "readBytesUntil() byte buffer is too small for the " + length
378
+ + " bytes up to and including char " + interesting , null ));
400
379
return -1 ;
401
380
}
402
381
// byte outgoing[] = new byte[length];
@@ -479,8 +458,7 @@ public void write(String what) {
479
458
}
480
459
481
460
public void write (String what , String LineEnd ) {
482
- notifyConsumers (System .getProperty ("line.separator" ) + ">>Send to "
483
- + PortName + ": \" " + what + "\" <<"
461
+ notifyConsumers (System .getProperty ("line.separator" ) + ">>Send to " + PortName + ": \" " + what + "\" <<"
484
462
+ System .getProperty ("line.separator" ));
485
463
write (what .getBytes ());
486
464
if (LineEnd .length () > 0 ) {
@@ -504,11 +482,9 @@ public void setRTS(boolean state) {
504
482
static public Vector <String > list () {
505
483
Vector <String > list = new Vector <String >();
506
484
try {
507
- CommPortEnumerator portList = CommPortIdentifier
508
- .getPortIdentifiers ();
485
+ CommPortEnumerator portList = CommPortIdentifier .getPortIdentifiers ();
509
486
while (portList .hasMoreElements ()) {
510
- CommPortIdentifier portId = (CommPortIdentifier ) portList
511
- .nextElement ();
487
+ CommPortIdentifier portId = (CommPortIdentifier ) portList .nextElement ();
512
488
513
489
if (portId .getPortType () == CommPortIdentifier .PORT_SERIAL ) {
514
490
String name = portId .getName ();
@@ -533,8 +509,7 @@ static public Vector<String> list() {
533
509
* something slightly more intelligent to do.
534
510
*/
535
511
static public void errorMessage (String where , Throwable e ) {
536
- Common .log (new Status (IStatus .WARNING , ArduinoConst .CORE_PLUGIN_ID ,
537
- "Error inside Serial. " + where , e ));
512
+ Common .log (new Status (IStatus .WARNING , ArduinoConst .CORE_PLUGIN_ID , "Error inside Serial. " + where , e ));
538
513
539
514
}
540
515
0 commit comments