Hallo, habe folgendes Problem: Über ein Applet auf einem X-Port gebe ich einen ATmega1281v Befehle. Wenn der uC diese ausführt sendet er eine Antwort (z.B. COMMIT_C_OKAY). Diese Antwort wiederrum wird vom Java-Applet in einer Text Area angezeigt. Eine dieser Antworten vom uC enthält Zeichen die vom Applet nicht dargestellt werden können, weshalb ich diese Antwort abfange und in hexadezimale Darstellung konvertiere. Diese wird dann in Text Area ausgegeben. Das funktioniert auch einige Male (ca 17 Mal) ganz gut. Irgendwann werden keine Antworten des uCs mehr angezeigt. Der uC lässt sich allerdings weiterhin steuern. Ich vermute mal, dass es am Puffer liegen könnte. Hier mal der Empfangsteil des Codes:
1 | // print received data on text area |
2 | public void run() |
3 | { |
4 | //int test; |
5 | Thread me = Thread.currentThread(); |
6 | while (timer == me) { |
7 | int i; |
8 | |
9 | try { |
10 | Thread.currentThread().sleep(200); |
11 | } catch (InterruptedException e) { } |
12 | if ( (gtp != null) && ((i = gtp.available()) > 0) ) { |
13 | |
14 | String received; |
15 | byte[] in = new byte[100]; |
16 | |
17 | in = gtp.receive(); // write received bytes in in[] |
18 | received = new String(in); // covert byte[] to string |
19 | Ringbuffer ring = new Ringbuffer(200); |
20 | // if it's a response to a GET_CONF-command (GET_CONF_OKAY_), convert received frame to hex than display it in the text area |
21 | if((in[0]== 0x47) && (in[1]== 0x45) && (in[2]== 0x54) && (in[3] == 0x5F) && (in[4] == 0x43) && (in[5] == 0x4F) && (in[6] == 0x4E) && |
22 | (in[7]== 0x46) && (in[8]== 0x5F) && (in[9]== 0x4F) && (in[10]== 0x4B) && (in[11]== 0x41) && (in[12]== 0x59) && (in[13]== 0x5F)) |
23 | { |
24 | String tempStringBuffer = "GET_CONF_OKAY_("; // write prelude of the response |
25 | |
26 | // config frame data from in[14] to in[length-2] |
27 | for(int j = 14; j < in.length-2; j++) |
28 | { |
29 | String temp = Integer.toHexString(in[j] & 0xFF); // convert the byte array to a string of hexadecimal bytes |
30 | if (temp.length() < 2) |
31 | { |
32 | tempStringBuffer += "0"; // if hex number consists of only one digit, add a '0' in front of the value |
33 | } |
34 | tempStringBuffer += temp; // write converted hex to output string |
35 | tempStringBuffer += " "; // divider between the hexadecimal byte blocks |
36 | } |
37 | tempStringBuffer += ")\n\r"; // conclusion of config frame with additional "line feed" and "carriage return" symbol |
38 | |
39 | textArea.append(tempStringBuffer); // print string in text area |
40 | textArea.setCaretPosition(textArea.getText().length()); // view always last row in text area |
41 | } |
42 | // for every uC response of a command, except the GET_CONFIG command |
43 | else |
44 | { |
45 | textArea.append(received); // print received string in text area |
46 | textArea.setCaretPosition(textArea.getText().length()); // view always last row in text area |
47 | } |
48 | //java.util.Arrays.fill(in, 0); |
49 | received = ""; |
50 | } |
51 | } |
52 | } |
Vielleicht habt ihr ja eine Idee Vieln Dank im Voraus...