|
@@ -38,6 +38,10 @@ public class SerialHelper {
|
38
|
38
|
private final short OK = 0x42;
|
39
|
39
|
private final short ERROR = 0x23;
|
40
|
40
|
|
|
41
|
+ // Timeout in milliseconds per byte
|
|
42
|
+ private final int transmitTimeout = 1000;
|
|
43
|
+ private final int recieveTimeout = 1000;
|
|
44
|
+
|
41
|
45
|
private Frame frame;
|
42
|
46
|
|
43
|
47
|
/**
|
|
@@ -325,9 +329,7 @@ public class SerialHelper {
|
325
|
329
|
SerialWriteThread t = new SerialWriteThread(data);
|
326
|
330
|
t.start();
|
327
|
331
|
while (!t.dataWasSent()) {
|
328
|
|
- if ((new Date()).getTime() >= (startdate + (data.length * 1000))) {
|
329
|
|
- // More than (length * 1000) milliseconds went by
|
330
|
|
- // => 1 second per byte
|
|
332
|
+ if ((new Date()).getTime() >= (startdate + (data.length * transmitTimeout))) {
|
331
|
333
|
return false;
|
332
|
334
|
}
|
333
|
335
|
}
|
|
@@ -337,16 +339,20 @@ public class SerialHelper {
|
337
|
339
|
private short[] readData(int length) {
|
338
|
340
|
// return data read or null if timeout
|
339
|
341
|
long startdate = (new Date()).getTime();
|
340
|
|
-
|
|
342
|
+ short[] result;
|
341
|
343
|
SerialReadThread t = new SerialReadThread(length);
|
342
|
344
|
t.start();
|
343
|
345
|
while (!t.dataIsReady()) {
|
344
|
|
- if ((new Date()).getTime() >= (startdate + (length * 1000))) {
|
345
|
|
- // More than (length * 1000) milliseconds went by
|
346
|
|
- // => 1 second per byte
|
|
346
|
+ if ((new Date()).getTime() >= (startdate + (length * recieveTimeout))) {
|
347
|
347
|
return null;
|
348
|
348
|
}
|
349
|
349
|
}
|
350
|
|
- return t.getSerialData();
|
|
350
|
+ result = t.getSerialData();
|
|
351
|
+ if (result == null) {
|
|
352
|
+ System.out.println("Data read was null!");
|
|
353
|
+ } else if (result.length == 0) {
|
|
354
|
+ System.out.println("No data read!");
|
|
355
|
+ }
|
|
356
|
+ return result;
|
351
|
357
|
}
|
352
|
358
|
}
|