Double resultat avec javax.comm
Bonjour,
J'ai un petit souci avec javax.comm. J'ai suivi le tuto sur ce site pour piloter un port série, mais j'ai un problème lorsque ça liste les ports sur mon pc
Voici le code :
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 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
| package admin_switch;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.ConnectException;
import java.nio.channels.FileChannel;
import java.util.Enumeration;
import javax.comm.*;
import com.sun.comm.Win32Driver;
/**
*
* @author Sebastien Girard
*
* Pour que ca marche il faut copier la dll dans le C:\Windows\system32
*/
public class ListSerial
{
static int i = 0;
static String PortDisponible[];
public static void main(String[] args) throws IOException {
copyFile(new File("N:\\Java\\Projet\\bin\\admin_switch\\win32com.dll"),new File("C:\\WINDOWS\\system32\\win32com.dll"));
ListSerial();
ModeEvenement test = new ModeEvenement("COM1");
}
public static void ListSerial() {
//initialisation du driver
Win32Driver w32Driver= new Win32Driver();
w32Driver.initialize();
//récupération de l'énumération
Enumeration portList=CommPortIdentifier.getPortIdentifiers();
//affichage des noms des ports
CommPortIdentifier portId;
while (portList.hasMoreElements()){
portId=(CommPortIdentifier)portList.nextElement();
System.out.println(portId.getName());
}
}
public static void copyFile(File src, File dest) throws IOException {
FileChannel channelSrc = new FileInputStream(src).getChannel();
try {
FileChannel channelDest = new FileOutputStream(dest).getChannel();
try {
channelSrc.transferTo(0, channelSrc.size() , channelDest);
} finally {
channelDest.close();
}
} finally {
channelSrc.close();
}
}
} |
Ce code contient la fonction pour lister mais aussi une fonction pour copier la dll dans le bon dossier. Voila le resultat :
Code:
1 2 3 4 5 6 7 8 9 10
| COM3
COM4
COM5
LPT1
LPT2
COM3
COM4
COM5
LPT1
LPT2 |
Déjà c'est bizarre car ça m'affiche à double les ports disponible et ensuite sur mon PC je n'ai pas tout ces ports !
http://img509.imageshack.us/img509/3...1712ys3.th.pnghttp://img509.imageshack.us/images/thpix.gif
Une idée de mon problème ?