|
|
|
@ -113,12 +113,13 @@ public class IspManager { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void clearBuffer(int size) { |
|
|
|
|
private int clearBuffer(int size) { |
|
|
|
|
if (serialPort == null) |
|
|
|
|
return; |
|
|
|
|
return -1; |
|
|
|
|
|
|
|
|
|
byte[] buf = new byte[size]; |
|
|
|
|
read(buf, size, 500); |
|
|
|
|
int ret = read(buf, size, 1000); |
|
|
|
|
return ret; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public String[] readUid() { |
|
|
|
@ -299,8 +300,16 @@ public class IspManager { |
|
|
|
|
private boolean synchronize(int crystal_freq) { |
|
|
|
|
if (serialPort == null) |
|
|
|
|
return false; |
|
|
|
|
int cpt = 0; |
|
|
|
|
while(clearBuffer(1000) > 0 && cpt < 20) |
|
|
|
|
{ |
|
|
|
|
cpt++; |
|
|
|
|
} |
|
|
|
|
serialPort.purge(D2xxManager.FT_PURGE_RX); |
|
|
|
|
serialPort.purge(D2xxManager.FT_PURGE_TX); |
|
|
|
|
if(cpt == 20) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
byte[] buf; |
|
|
|
|
if (serialPort.write(SYNC_START) != SYNC_START.length) { |
|
|
|
|
return false; |
|
|
|
@ -500,6 +509,7 @@ public class IspManager { |
|
|
|
|
|
|
|
|
|
private int parseRetCode(byte[] data) { |
|
|
|
|
String str = new String(data,0,2); |
|
|
|
|
str.replace(" ",""); |
|
|
|
|
str = str.replace("\r", ""); |
|
|
|
|
str = str.replace("\n", ""); |
|
|
|
|
if (!str.matches("[0-9 -+]*")||str.isEmpty()) |
|
|
|
|