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
|
public class projetBluetooth {
private static Enumeration<CommPortIdentifier> ports;
private static CommPortIdentifier port;
private static String type;
private static String etat;
public static void main(String[] args) throws NoSuchPortException, PortInUseException
{
rxtxAffichage();
System.out.println("getClass.Getname:" + getNomClass());
rxtxOuverturePort("COM6");
}
public static void rxtxAffichage()
{
ports = CommPortIdentifier.getPortIdentifiers();
int i = 1;
while (ports.hasMoreElements())
{
port = (CommPortIdentifier) ports.nextElement();
if (port.getPortType() == CommPortIdentifier.PORT_SERIAL) type = "Serie"; else type = "Parallèle";
if (port.isCurrentlyOwned()) etat = "Possédé par "+port.getCurrentOwner(); else etat = "Libre";
System.out.println("Port : "+ port.getName() + " Type:" + type+ " Etat:"+etat);
}
}
public static void rxtxOuverturePort(String nomPort) throws NoSuchPortException, PortInUseException
{
CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(nomPort);
CommPort commPort = portIdentifier.open(getNomClass(),2000);
}
public static String getNomClass()
{
projetBluetooth classAdress = new projetBluetooth();
return classAdress.getClass().getName();
}
} |
Partager