Pb d'erreur avec ma classe

mimi1255 Messages postés 87 Date d'inscription mardi 22 janvier 2008 Statut Membre Dernière intervention 14 mars 2024 - 19 mai 2008 à 21:01
cs_Chatbour Messages postés 764 Date d'inscription jeudi 27 juillet 2006 Statut Membre Dernière intervention 6 septembre 2010 - 19 mai 2008 à 22:59
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:
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.

3 réponses

cs_Chatbour Messages postés 764 Date d'inscription jeudi 27 juillet 2006 Statut Membre Dernière intervention 6 septembre 2010 19
19 mai 2008 à 22:00
Salut,

révise la signature de la méthode
serialEvent
apparemment ça ne devrait pas être de cette façon :


public static String serialEvent(SerialPortEvent event)








essaye plutôt :


public String serialEvent(javax.comm.SerialPortEvent)
0
mimi1255 Messages postés 87 Date d'inscription mardi 22 janvier 2008 Statut Membre Dernière intervention 14 mars 2024
19 mai 2008 à 22:33
en faite serialEvent ne retourne pas un String mais un void. Seulement mon problème, c'est que je voudrais récupérer NumCodeBarre pour pouvoir l'utiliser après, comment faire ?

Merci encore.
0
cs_Chatbour Messages postés 764 Date d'inscription jeudi 27 juillet 2006 Statut Membre Dernière intervention 6 septembre 2010 19
19 mai 2008 à 22:59
tu peux ajouter un attribut de type String et l'utiliser dans ce contexte..
0
Rejoignez-nous