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
|
public void connect( String portName ) throws Exception
{
CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(portName);
if ( portIdentifier.isCurrentlyOwned() )
{
System.out.println("Erreur: le port de communication est déja utilisé");
}
else
{
CommPort commPort = portIdentifier.open(this.getClass().getName(),2000);
if ( commPort instanceof SerialPort )
{
SerialPort serialPort = (SerialPort) commPort;
serialPort.setSerialPortParams(19200,SerialPort.DATABITS_8,SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);
BufferedReader entree = new BufferedReader(new InputStreamReader(serialPort.getInputStream()));
PrintWriter sortie = new PrintWriter(new BufferedWriter(new OutputStreamWriter(serialPort.getOutputStream())),true);
}
else
{
System.out.println("Erreur: Seulement le port série RS232 est utilisable.");
}
}
} |
Partager