bonjour ....

j'arrive pas afaire un listener sur la fonction serialEvent ou faire apel a une autre fonction d'une autre class..

voici la class qui contient serialEvent .....
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
 
package client;
 
import javax.comm.*;
import com.sun.comm.Win32Driver;
import java.io.*;
import java.util.*;
 
public class RFIDTagReader extends Thread implements SerialPortEventListener {
    public RFIDTagReader() {
        try {
            jbInit();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
 
    String codeBarre = new String();
    CommPortIdentifier portId;
    SerialPort serialPort;
    BufferedReader fluxLecture;
    boolean running;
 
        /**
         * Constructeur qui récupère l'identifiant du port et lance l'ouverture.
         */
        public RFIDTagReader(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 {
                        serialPort = (SerialPort) portId.open("ModeEvenement", 2000);
                } catch (PortInUseException e) {
                }
                //récupération du flux
                try {
                        fluxLecture =
                                new BufferedReader(
                                        new InputStreamReader(serialPort.getInputStream()));
                } catch (IOException e) {
                }
                //ajout du listener
                try {
                        serialPort.addEventListener(this);
                } catch (TooManyListenersException e) {
                }
                //paramétrage du port
                serialPort.notifyOnDataAvailable(true);
                try {
                        serialPort.setSerialPortParams(
                                9600,
                                SerialPort.DATABITS_7,
                                SerialPort.STOPBITS_1,
                                SerialPort.PARITY_EVEN);
                } catch (UnsupportedCommOperationException e) {
                }
                System.out.println("port ouvert, attente de lecture");
        }
        public void run() {
                running = true;
                while (running) {
                        try {
                                Thread.sleep(2000);
                        } catch (InterruptedException e) {
                        }
                }
                //fermeture du flux et port
                try {
                        fluxLecture.close();
                } catch (IOException e) {
                }
                serialPort.close();
        }
        /**
         * Méthode de gestion des événements.
         */
        public void serialEvent(SerialPortEvent event) {
 
    //gestion des événements sur le port :
                //on ne fait rien sauf quand les données sont disponibles
 
                switch (event.getEventType()) {
                       case SerialPortEvent.BI :
                        case SerialPortEvent.OE :
                        case SerialPortEvent.FE :
                        case SerialPortEvent.PE :
                        case SerialPortEvent.CD :
                        case SerialPortEvent.CTS :
                        case SerialPortEvent.DSR :
                        case SerialPortEvent.RI :
                        case SerialPortEvent.OUTPUT_BUFFER_EMPTY :
                                break;
                        case SerialPortEvent.DATA_AVAILABLE :
 
                                try {
                                        //lecture du buffer et affichage
                                        codeBarre = (String) fluxLecture.readLine();
                                        System.out.println(codeBarre);
                                } catch (IOException e) {
                                }
                                break;
                }
        }
 
        /**
         * Permet l'arrêt du thread
         */
        public void stopThread() {
                running = false;
        }
 
    private void jbInit() throws Exception {
    }
}
[/code]