Bonjour à tous,
Je suis nouveau ici, et je cherche de l'aide.
Après avoir lu tout ce qui concernait RXTX et la connexion de ports, javacomm, incluant le tutoriel http://christophej.developpez.com/tu...java/javacomm/, et que je pouvais digérer, je n'ai malheureusement pas réussi à m'en sortir.
Voici la situation : je cherche à connecter un ordinateur à une carte en bluetooth, pour pouvoir récupérer les données qui sont stockées dessus (dans une SD card). Ensuite, traiter ces données sur MatLab (mais cela viendra dans un autre post).L'idée étant de le faire en temps réel ou presque.
IDE : Eclipse
Langage utilisé : Java
Librairie utilisée (j'essaye) : RXTX
Système d'exploitation : Windows 7 64bits
Pour tester l'installation de RXTX, j'ai récupéré le code d'anima.5 http://www.developpez.net/forums/d87...nuseexception/ :
Et je reçois le rapport suivant :
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119 import gnu.io.CommPort; import gnu.io.CommPortIdentifier; import gnu.io.SerialPort; import java.io.FileDescriptor; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import gnu.io.RXTXCommDriver; public class Dialogue { public Dialogue() { super(); } //connexion au port: void connect ( String portName ) throws Exception { CommPortIdentifier COM7 = CommPortIdentifier.getPortIdentifier(portName); // si le port est deja connecté: if ( COM7.isCurrentlyOwned() ) { System.out.println("Error: Port is currently in use"); } else { CommPort commPort = COM7.open(this.getClass().getName(),2000); if ( commPort instanceof SerialPort ) { //si le port est présent mais pas connecté SerialPort serialPort = (SerialPort) commPort; serialPort.setSerialPortParams(57600,SerialPort.DATABITS_8,SerialPort.STOPBITS_1,SerialPort.PARITY_NONE); InputStream in = serialPort.getInputStream(); OutputStream out = serialPort.getOutputStream(); (new Thread(new SerialReader(in))).start(); (new Thread(new SerialWriter(out))).start(); } else // si le port n'est pas présent { System.out.println("Error: Only serial ports are handled by this example."); } } } /** */ public static class SerialReader implements Runnable { InputStream in; public SerialReader ( InputStream in ) { this.in = in; } public void run () { byte[] buffer = new byte[1024]; int len = -1; try { while ( ( len = this.in.read(buffer)) > -1 ) { System.out.print(new String(buffer,0,len));//tampon } } catch ( IOException e ) { e.printStackTrace(); } } } /** */ public static class SerialWriter implements Runnable { OutputStream out; public SerialWriter ( OutputStream out ) { this.out = out; } public void run () { try { int c = 0; while ( ( c = System.in.read()) > -1 ) { this.out.write(c); } } catch ( IOException e ) { e.printStackTrace(); } } } public static void main ( String[] args ) { try { new Dialogue().connect("COM7"); } catch ( Exception e ) { // TODO Auto-generated catch block e.printStackTrace(); } } }
L'installation s'est faite de la manière suivante : (site de RxTx :
Stable Library
=========================================
Native lib Version = RXTX-2.2-20081207 Cloudhopper Build rxtx.cloudhopper.net
Java lib Version = RXTX-2.1-7
WARNING: RXTX Version mismatch
Jar version = RXTX-2.1-7
native lib Version = RXTX-2.2-20081207 Cloudhopper Build rxtx.cloudhopper.net
gnu.io.NoSuchPortException
at gnu.io.CommPortIdentifier.getPortIdentifier(CommPortIdentifier.java:266)
at artisynth.models.AQM_Project.Dialogue.connect(Dialogue.java:23)
at artisynth.models.AQM_Project.Dialogue.main(Dialogue.java:112)
Je comprends qu'il y a un problème de compatibilité, bien que l'ensemble reste stable. J'ai essayé avec plusieurs sources pour RXTX mais je n'ai pas réussi à régler ce problème de mismatch. J'ai déjà essayé de rajouter RXTX en tant que plugin dans Eclipse, mais il ne le détectait pas (lorsque je faisais l'import, cela ne marchait).This is how I add and use RXTX in Eclipse for Win32 Projects, there are probably other ways but it works for me.
Copy RXTXcomm.jar, rxtxSerial.dll and rxtxParallel.dll files to the lib directory of your project
Under Project | Properties | Java Build Path | Libraries
click Add JARs... Button
Select the RXTXComm.jar from lib directory
Jar should now be in the Build Path
expand the RXTXComm.jar entry in the list and select "Native Library Location"
Select the project lib directory and apply
Be careful when using System.in.read() and rxtx in win32; It can trip across a known JRE deadlock bug
Je ne comprends pas les messages d'erreur non plus.
Pourriez-vous aider une âme en peine? Cela fait plusieurs jours que je suis bloqué.






Répondre avec citation
Partager