Enumération des différents ports d'un PC en Java avec rxtx sous Ubuntu 14.04
Salut à toute la communauté,
Je travaille sur un projet consistant à faire communiquer le port série/parallèle d'un PC (RS 232) avec un terminal mobile. Mais bon, je suis encore loin d'en être au résultat.
Après avoir installé rxtx sur mon OS. J'ai compilé un exemple pour l'énumération des ports séries dans mon IDE Netbeans 8.0.
Voici le résultat de ma console:
Code:
1 2 3 4 5 6
| =========================================
Native lib Version = RXTX-2.1-7
Java lib Version = RXTX-2.1-7
false
Experimental: JNI_OnLoad called.
BUILD SUCCESSFUL (total time: 1 second) |
Mais le code inclut des instructions d'affichage des ports trouvés sur mon PC. et logiquement je m'attends à ce que ça le fasse, mais non.
Voici un code exemple que j'ai copié sur un pdf et dont le résultat d'exécution est celui que vous voyez ci-dessus.
Code:
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
| import gnu.io.CommPortIdentifier;
import gnu.io.NoSuchPortException;
import java.util.Enumeration;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
public class PortsEnumerator {
public static void main(String[] args) throws NoSuchPortException
{
Enumeration ports = CommPortIdentifier.getPortIdentifiers();
// CommPortIdentifier portId =
// CommPortIdentifier.getPortIdentifier("/dev/ttyUSB0");
// System.out.println(portId.getName());
System.out.println(ports.hasMoreElements());
int i = 1;
while (ports.hasMoreElements())
{
CommPortIdentifier port = (CommPortIdentifier) ports.nextElement();
System.out.println("Port n°"+i++);
System.out.println("\tNom\t:\t"+port.getName());
String type = null;
if (port.getPortType() == CommPortIdentifier.PORT_SERIAL) type = "Serie";
else type = "Parallèle";
System.out.println("\tType\t:\t"+type);
String etat = null;
if (port.isCurrentlyOwned()) etat = "Possédé par "+port.getCurrentOwner();
else etat = "Libre";
System.out.println("\tEtat\t:\t"+etat+"\n");
}
}
} |
Quel est le problème???Merci d'avance pour vos contributions