Bonjour à tous !
J'ai un recepteur GPS qui m'envois des trames NMEA. J'utilise le logiciel PuTTY afin de visualiser ces dernières :
Mon code JAVA permet de récupérer les trames reçues par le récepteur GPS et les affiches en console. Mais voilà que je me retrouve avec ce genre de trame :
Voici mon code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58 public class GPSFrame extends Observable implements Runnable { static Thread myThread=null; static BufferedReader br; static BufferedWriter wr; static PrintWriter out; static InputStreamReader isr; static OutputStreamWriter osw; static java.io.RandomAccessFile port; /** CONSTRUCTOR **/ public GPSFrame() { myThread=new Thread(this); } public void start() { try { port=new java.io.RandomAccessFile("COM5","rwd"); port.writeBytes("\r\n"); port.writeBytes("c,31,0,0,5\r\n"); port.writeBytes("T,1000,1\r\n"); } catch (Exception e){ System.out.println("start "+e.toString()); } // The thread start automatically run() method myThread.start(); } /********************************************************************************************** *************************** RETRIEVE GPS FRAMES AND SEND TO SERVEUR ************************** **********************************************************************************************/ public void run() { System.out.println("lecture COM..."); // INFINIT LOOP - GPSFrame is always listening for the GPS receptor for(;;) { String st = null; try { st=port.readLine(); String[]gpsframe=st.split(","); /* IMPORTANT - DON'T FORGET SETCHANGED() or GPSFrame'll never * notify UPDATE() ServerBoard method - We'll never see any changes */ setChanged(); notifyObservers(st); } catch (IOException e){ System.out.println(e.getMessage()); } // Show in console System.out.println(st); } } }
Petite note : Lorsque je lance mon application SANS avoir lancé PuTTY une première fois avant, je tombe sur des trames encodées. Si j'ai déjà lancé PuTTY une première fois avant mon application, les trames reçues sont correctes.
Quelqu'un aurait une idée sur la provenance de ce "bug" ?
Je vous remercie par avance pour vos réponses !
Cordialement,
Tofuw
Partager