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

Entrée/Sortie Java Discussion :

probleme structure jna


Sujet :

Entrée/Sortie Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé Avatar de L4BiN
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juin 2006
    Messages
    432
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2006
    Messages : 432
    Par défaut probleme structure jna
    Bonjour,

    je souhaite passer des informations via une Structure jna.

    J'ai déja utiliser cette structure pour faire des appel java du c.
    Maintenant je souhaiterai en plus passer un certain nombre de donnée...

    voici ma Structure:
    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
    package jna.structure;
     
    import jna.interfaceJna.HubOptLibrary;
    import jna.interfaceJna.RunSimul;
    import jna.interfaceJna.WriteResult;
     
     
    import com.sun.jna.IntegerType;
    import com.sun.jna.Pointer;
    import com.sun.jna.Structure;
     
    /**
     * 
     * Structur permettant d'envoyer vers le C des pointeurs de fonctions.
     * 
     * @author binot
     *
     */
    public class StructureCondor extends Structure {
     
        /**
         * variable global permettant de contenir le chargement de la lib dll
         */
        private HubOptLibrary lib;
     
        private StructureCondor moi = this;
        public StructureCondor(HubOptLibrary lib){
            this.lib = lib;
        }
        /******************
         * 
         *  pointeur de données
         * 
         * ********************/
     
     
     
         public int scanBDO = 1;
        /*
        public int maxIter = 10;
        
        //public String method = "Test methode";
        
        public double epscon = 0.0;
        
        public double minVar = 0.0;
        
        public double maxVar = 100;
        
        public int npar = 5;*/
     
        //public String[] par_name = {"yann","florent","emilie","clement","mickael"};
     
     
     
     
     
     
     
     
        /********************
         * 
         * Pointeurs de fonctions
         * 
         * **************************/
        public RunSimul runSimul = new RunSimul() {
     
            @Override
            public void invoke(int nbIteration) {
     
                for(int i = 0 ; i < nbIteration; i++){
                    System.out.println("Simulation : "+ i+" commence");
     
                    try {
     
                        //  ici on devrait trouver l'appel pour le lancement des simulations coté java.
                        Thread.sleep(2000);
                    } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
     
                    System.out.println("Simulation : "+ i+" termine");
                }
     
     
                lib.envoirResultSimulation(nbIteration, moi);
     
     
            }
        };
     
     
     
     
        public WriteResult writeResult = new WriteResult() {
     
            @Override
            public void invoke(Pointer tabp, int taille) {
     
                System.out.println("Je suis dans runSimul \n la table envoye est : ");
     
                int[]tab = tabp.getIntArray(0, taille);
     
                for (int i = 0 ; i < tab.length; i++){
                    System.out.println("index "+i+" : "+ tab[i]);
                }
     
            }
        };
     
     
     
    }
    le public de public int scanDBO a l'air de causer une erreur ACCES_VIOLATION tels que ceci:
    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
     
    # An unexpected error has been detected by Java Runtime Environment:
    #
    #  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00000001, pid=1236, tid=5152
    #
    # Java VM: Java HotSpot(TM) Client VM (11.3-b02 mixed mode, sharing windows-x86)
    # Problematic frame:
    # C  0x00000001
    #
    # An error report file with more information is saved as:
    # C:\Users\binot\Desktop\HubOptLiaison\testJNI_JNA\worspace\CondorInterfaceJNA4Hubopt\hs_err_pid1236.log
    #
    # If you would like to submit a bug report, please visit:
    #   http://java.sun.com/webapps/bugreport/crash.jsp
    # The crash happened outside the Java Virtual Machine in native code.
    # See problematic frame for where to report the bug.
    #
    de plus au niveau du c (le code est si dessous), les printf n'indique pas la bonne valeur comme si elles ne trouvaient rien... elles indiquent :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    les datas  5636136je suis rentrer dans le mainj appel runSim de java
    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
     
     
    #include<stdio.h>
     
     
     
     typedef struct condorFunctionStruct {
     /********************
     poiteur de fonctions
     **********************/
     
        void (*runSimul)(int  nb);
        void (*writeResult)(int *tab, int taille);
     
        /*********
        poiteur de variables
        **********/
         int scanBDO;
     
        /*
         int *maxIter;
        
         //char *method[20];
        
         double *epscon ;
        
         double *minVar;
        
         double *maxVar ;
        
         int *npar ;*/
     
        // char *par_name [20][5];
     
     
     
     
       } condorFunctionStruct;
     
    int main(condorFunctionStruct *mastruct){
     
     
    printf("les datas  ");
    printf(mastruct->scanBDO);
    /*
    printf(mastruct-> maxIter);
    //printf(mastruct->method);
    printf(mastruct->epscon);
    printf(mastruct->minVar);
    printf(mastruct->maxVar);
    printf(mastruct->npar);
    //printf(mastruct->par_name);
    printf("");*/
     
    printf("  je suis rentrer dans le main");
     
    printf("  j appel runSim de javavb           dddddddddddddddddddddddddddddddddd ");
     
    mastruct->runSimul(5);
     
     
     
    return 5;
    }
     
    void envoirResultSimulation(int nb, condorFunctionStruct *mastruct ){
     
    //printf("il y a un nombre de resltat de ; "); printf(nb);
     
    int tab[nb] ;
    for(int i = 0 ; i < nb; i++){
    tab[i] = i;
    }
     
    mastruct->writeResult(tab, nb);
     
     
     
     
    }
    D'ou vient le probleme? on ne peut pas passer des valeurs par les structures ?

    Merdci d'avance

  2. #2
    Membre éclairé Avatar de L4BiN
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juin 2006
    Messages
    432
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2006
    Messages : 432
    Par défaut
    J'ai finalement trouver la réponse c'est qu'il faut déclarer les variables dans le meme ordre dans les structures c et java.


    Du coup j'ai une autre question...

    Comment passer un tableau de String avec JNA

    Car à apriori la déclaration String[] monTabString n'est pas accepté ?

    Merci d'avance

  3. #3
    Membre éclairé Avatar de L4BiN
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juin 2006
    Messages
    432
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2006
    Messages : 432
    Par défaut
    J'ai vu que l'on peut utiliser les StringArray, mais je n'arrive pas a faire fonctionner ... j'ai cette erreur :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    Exception in thread "main" java.lang.IllegalArgumentException: Invalid Structure field in class jna.structure.StructureCondor, field name 'par_name', class com.sun.jna.StringArray: Type class com.sun.jna.StringArray has unknown native alignment
        at com.sun.jna.Structure.calculateSize(Structure.java:784)
        at com.sun.jna.Structure.allocateMemory(Structure.java:242)
        at com.sun.jna.Structure.ensureAllocated(Structure.java:234)
        at com.sun.jna.Structure.write(Structure.java:509)
        at com.sun.jna.Structure.autoWrite(Structure.java:1344)
        at com.sun.jna.Function.convertArgument(Function.java:462)
        at com.sun.jna.Function.invoke(Function.java:258)
        at com.sun.jna.Library$Handler.invoke(Library.java:216)
        at $Proxy0.main(Unknown Source)
        at jna.Main.main(Main.java:17)

    si vous avez une idée je suis prenneur merci d'avance

  4. #4
    Membre éclairé Avatar de L4BiN
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juin 2006
    Messages
    432
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2006
    Messages : 432
    Par défaut
    alors en fait faut faire

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    public class MaStructure extends Structure{
     
    // declaration d'un tableau de String
     
    Pointer tab = new StringArray(new String[]{"string1","string2"});
     
    }

Discussions similaires

  1. Probleme structure et liste
    Par xillion dans le forum C
    Réponses: 6
    Dernier message: 26/03/2008, 20h45
  2. probleme structure case
    Par monsieur77 dans le forum Linux
    Réponses: 4
    Dernier message: 07/11/2007, 12h14
  3. Probleme structure / realloc
    Par bobgeldof7 dans le forum C
    Réponses: 4
    Dernier message: 30/11/2006, 21h33
  4. probleme structure en parametre
    Par ciberju dans le forum C
    Réponses: 2
    Dernier message: 21/08/2006, 03h26
  5. Réponses: 3
    Dernier message: 02/03/2006, 11h25

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