IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Java Discussion :

Communication avec une carte RFID


Sujet :

Java

  1. #1
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2014
    Messages
    78
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Industrie Pharmaceutique

    Informations forums :
    Inscription : Avril 2014
    Messages : 78
    Points : 47
    Points
    47
    Par défaut Communication avec une carte RFID
    Bonjour, j'aimerais vous faire part d'un petit projet sur lequel je suis maintenant et j'aimerais savoir es ce que c'est correcte ou non
    Voici un bout de mon code qui sert a lire depuis la carte :


    je mets que l'essentiel j'ai pas mis mon GUI et la classe MAIN

    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
     
     public void connect() throws PortInUseException
        {
            String selectedPort = (String)window.cboxPorts.getSelectedItem();
            String selectedbaud = (String)window.bauds.getSelectedItem();  // SELECTION le FLUX 
     
            jcombox = selectedbaud.toString(); // STOCK DANS UNE VARIABLE
            flux = Integer.parseInt(jcombox);
            selectedPortIdentifier = (CommPortIdentifier)portMap.get(selectedPort);
     
            CommPort commPort = null;
     
            try
            {
                //the method below returns an object of type CommPort
                commPort = selectedPortIdentifier.open("TigerControlPanel", TIMEOUT);
                //the CommPort object can be casted to a SerialPort object
                serialPort = (SerialPort)commPort;
     
                //for controlling GUI elements
                setConnected(true);
     
                //logging
                logText = selectedPort + " opened successfully.\nBauds Selected : "+flux ;
                window.txtLog.setForeground(Color.black);
                window.txtLog.append(logText + "\n");
                      try {
                            serialPort.setSerialPortParams(flux,
                                    SerialPort.DATABITS_8,
                                    SerialPort.STOPBITS_1,
                                    SerialPort.PARITY_NONE);
                        } catch (UnsupportedCommOperationException e) {
                            System.out.println(e);
                        }
     
                //enables the controls on the GUI if a successful connection is made
                window.keybindingController.toggleControls();
     
     
            }           
            catch (PortInUseException e)
            {
                logText = selectedPort + " is in use. (" + e.toString() + ")";
     
                window.txtLog.setForeground(Color.RED);
                window.txtLog.append(logText + "\n");
            }
            catch (Exception e)
            {
                logText = "Failed to open " + selectedPort + "(" + e.toString() + ")";
                window.txtLog.append(logText + "\n");
                window.txtLog.setForeground(Color.RED);
            }
        }
     
     
     
      public void serialEvent(SerialPortEvent evt) {
            if (evt.getEventType() == SerialPortEvent.DATA_AVAILABLE)
            {
                try
                {
                    byte singleData = (byte)input.read();
                      System.out.println("Reçu! "+singleData+"\n");  
                    if (singleData != NEW_LINE_ASCII)
                    {
                        logText = new String(new byte[] {singleData});
                        window.txtLog.append(logText);
                    }
                    else
                    {
                        window.txtLog.append("\n");
                    }
                }
                catch (Exception e)
                {
                    logText = "Failed to read data. (" + e.toString() + ")";
                    window.txtLog.setForeground(Color.red);
                    window.txtLog.append(logText + "\n");
                }
            }
        }

    ofait quand je mets mon Fil TX avec mon RX tout ce que j'envoie je le reçois en retour ! mais dés que je branche les fils sur la cartes dés que j'envoie ( en Héxa d'aprés le manuel d'utilisation ) je reçois rien dutout.
    ma question es ce que mon code est faux ? ou bien c'est ma trame qui est fausse ?

  2. #2
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2014
    Messages
    78
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Industrie Pharmaceutique

    Informations forums :
    Inscription : Avril 2014
    Messages : 78
    Points : 47
    Points
    47
    Par défaut
    Bonjour, après une journée de réponse j'ai constaté que mon code est bon
    le problème maintenant c'est que je n'arrive pas à écrire correctement la trame !!!

    par exemple

    j'ai 4 Bytes à envoyer en Héxa 52 46 45 01
    es ce que je dois faire un String[] trame et envoyer Byte par Byte ? ou bien juste une concaténation puis envoyer le tous ???
    et aussi je dois mettre un .getBytes() pour ma trame avant l'envoi ???

    je suis perdu j'ai aucune idée comment envoyé

Discussions similaires

  1. Réponses: 2
    Dernier message: 08/08/2014, 18h48
  2. [WD15] communication RS232 avec une carte relais 8 canaux
    Par soufasoufa33 dans le forum WinDev
    Réponses: 9
    Dernier message: 25/10/2012, 03h41
  3. Communication avec une carte PCI
    Par faridaetudiante dans le forum Assembleur
    Réponses: 4
    Dernier message: 02/06/2010, 21h59
  4. Hardware : Freecom sécurise son nouveau disque dur avec une carte RFID
    Par Emmanuel Chambon dans le forum Actualités
    Réponses: 8
    Dernier message: 16/07/2009, 13h31
  5. Problème avec une carte Sound Blaster Live
    Par zogstrip dans le forum Matériel
    Réponses: 4
    Dernier message: 25/09/2004, 20h43

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo