Bonjour, j'ai un problème au niveau de mon code, voici mon erreur:
D:\projet\Integration\src\Test\GestionLecteur.java:9: Test.GestionLecteur is not abstract and does not override abstract method serialEvent(javax.comm.SerialPortEvent) in javax.comm.SerialPortEventListener
public class GestionLecteur extends Thread implements SerialPortEventListener {
voici mon code:
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 package Test; import javax.comm.*; import com.sun.comm.Win32Driver; import java.io.*; import java.util.*; import javax.swing.JTextField; public class GestionLecteur extends Thread implements SerialPortEventListener { private static CommPortIdentifier portId; private static SerialPort serialPort; private static BufferedReader fluxLecture; private static boolean running; static String NumCodeBarre; /** * Constructeur qui récupère l'identifiant du port et lance l'ouverture. */ public String GestionLecteur(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_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); } catch (UnsupportedCommOperationException e) { } System.out.println("port ouvert, attente de lecture"); //return NumCodeBarre; } 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 static String 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.DATA_AVAILABLE : NumCodeBarre = new String(); try { //lecture du buffer et affichage NumCodeBarre = (String) fluxLecture.readLine(); //InterLC.Recup_Code.setText(NumCodeBarre); } catch (IOException e) { } return NumCodeBarre; break; } } /** * Permet l'arrêt du thread */ public void stopThread() { running = false; } /** * Méthode principale de l'exemple. */ /*public static void main() { //Récuperation du port en argument //String port = "COM3"; //lancement de l'appli GestionLecteur modeEve=new GestionLecteur(port); modeEve.start(); modeEve.stopThread(); }*/ }
Merci d'avance.
Partager