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
|
public UtilisationFlux(String port) {
//initialisation du driver
Win32Driver w32Driver = new Win32Driver();
w32Driver.initialize();
//récupération de l'identifiant du port
try {
portId = CommPortIdentifier.getPortIdentifier(port);
} catch (NoSuchPortException e) {
}
//ouverture du port
try {
sPort = (SerialPort) portId.open("UtilisationFlux", 30000);
} catch (PortInUseException e) {
}
//règle les paramètres de la connexion
try {
sPort.setSerialPortParams(
9600,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
} catch (UnsupportedCommOperationException e) {
}
//récupération du flux de lecture et écriture du port
try {
outStream = sPort.getOutputStream();
bufRead =
new BufferedReader(
new InputStreamReader(sPort.getInputStream()));
} catch (IOException e) {
}
}
public void communique(char envoie) {
try {
outStream.write((int) envoie);
} catch (IOException e) {
}
} |
Partager