@@ -160,6 +160,7 @@ public class SerialReader implements SerialPortEventListener {
160
160
private Pattern uid ;
161
161
List <String > lines = new ArrayList <String >();
162
162
String line = null ;
163
+ StringBuffer lineBuf = new StringBuffer ();
163
164
private boolean enableSerial =true ;
164
165
private boolean complete ;
165
166
protected InputStream in ;
@@ -197,8 +198,10 @@ public void serialEvent(SerialPortEvent event) {
197
198
198
199
//10=LF, 13=CR, lines should end in CR/LF
199
200
if (r ==10 ||x ==256 ){
200
- if (r ==10 )complete =true ;
201
- line = new String (buff );
201
+ if (r ==10 ){
202
+ complete =true ;
203
+ }
204
+ lineBuf .append (buff );
202
205
buff =new byte [256 ];
203
206
x =0 ;
204
207
}
@@ -209,16 +212,16 @@ public void serialEvent(SerialPortEvent event) {
209
212
return ;
210
213
}
211
214
//we have a line ending in CR/LF
212
- if (complete && StringUtils .isNotBlank (line )) {
213
- line = line .trim ();
215
+ if (complete && StringUtils .isNotBlank (lineBuf )) {
216
+ line = lineBuf . toString () .trim ();
214
217
if (logger .isDebugEnabled ())logger .debug (portName + ":Serial Received:" + line );
215
218
//its not empty!
216
219
if (line .length ()>0 ){
217
220
//map it if we havent already
218
221
if (!mapped && uid .matcher (line ).matches ()) {
219
222
// add to map
220
223
logger .debug (portName + ":Serial Received:" + line );
221
- String type = StringUtils .substringBetween (line , ConfigConstants .UID + ":" , "," );
224
+ String type = StringUtils .substringBetween (line . toString () , ConfigConstants .UID + ":" , "," );
222
225
if (type != null ) {
223
226
logger .debug (portName + ": device name:" + type );
224
227
deviceType = type .trim ();
@@ -244,6 +247,7 @@ public void serialEvent(SerialPortEvent event) {
244
247
}
245
248
complete =false ;
246
249
line =null ;
250
+ lineBuf = new StringBuffer ();
247
251
}
248
252
}
249
253
}
0 commit comments