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
|
System.setSecurityManager(null);
//recuperation du port de COM dans le fichier de conf
String com = EMIConfig.getUsbPort();
try{
// ouverture du port serie:
log.debug("Ouverture du port "+com);
portId=CommPortIdentifier.getPortIdentifier(com);
serialPort=(SerialPort)portId.open(EMIConfig.getLogin(),2000);
//parametrage du port
serialPort.notifyOnDataAvailable(true);
// on selectionne tous les parametres de la connexion serie:
serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);
//ajout du listener
try {
serialPort.addEventListener(this);
} catch (TooManyListenersException e) {
}
in = new BufferedReader(new InputStreamReader(serialPort.getInputStream()));
out = serialPort.getOutputStream();
try {
serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
} catch (UnsupportedCommOperationException ex) {
log.debug("Erreur de Setting de Parametres: "+ex.toString());
ready = USB_Not_Ready;
}
ready = USB_Ready;
}
catch (javax.comm.PortInUseException ex){
log.debug("Port en cours d'utilisation: "+ex.toString());
ready = USB_Not_Ready;
try{
serialPort.close();
}catch(Exception e){
if (log.isDebugEnabled()) {
log.debug("Toujours Occupe."+e.toString());
} else {
log.error(e, e);
}
ready = USB_Not_Ready;
}
}
catch (Exception e){
if (log.isDebugEnabled()) {
log.debug("Probleme d'ouverture de port.", e);
ready = USB_Not_Ready;
} else {
log.error(e, e);
}
ready = USB_Not_Ready;
}
if(ready == USB_Ready){
log.debug("port USB ouvert");
USBState = comUSBConstants.USB_READY;
}
else
log.debug("Erreur d'ouverture de port");
}//fin constructeur |
Partager