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();
}
}
} |
Partager