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

C# Discussion :

DLL en C++ utilisé dans C#


Sujet :

C#

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre actif
    Homme Profil pro
    Inscrit en
    Mai 2008
    Messages
    84
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 84
    Par défaut DLL en C++ utilisé dans C#
    Bonjour tout le monde !

    Je dois programmer un logiciel pour lire sur un RFID Reader stronglink et j'ai vraiment pas grand chose pour comprendre comment ça marche : La doc avec la device est en chinois, et je n'ai pas d'exemple en C#. J'ai seulement un pdf avec les fonctions et un exemple en C++.

    Je crois être très prêt du but, j'ai la variable dans lequel, je crois, pouvoir trouver le ID, mais dans la doc C++ c'est un type char et moi en C# je chercherais plutôt un type string.

    Je vous donne la description de la function, mon code C# et l'exemple C++ :
    SL500-User-Manual.pdf
    6.5.3 INT WINAPI ISO15693_GET_SYSTEM_INFORMATION P.33

    C++
    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
    void CDemoDlg::OnButtonInventory() 
    {
    	WORD icdev = 0x0000;
    	int status;		
    	unsigned char pData[MAX_RF_BUFFER];
    	unsigned char len;
    	unsigned char type = 0x31;	
     
    	if(!m_bConnectDevice){		
    		MessageBox("Not connect device","Error",MB_OK|MB_ICONERROR);
    		return;
    	}
     
    	status = rf_init_type(icdev,type);
        if(status){		
    		MessageBox("rf_init_type failed","Error",MB_OK|MB_ICONERROR);
    		return;
    	}
     
    	m_edit_uid1.SetWindowText("");
    	m_edit_uid2.SetWindowText("");
    	m_edit_uid3.SetWindowText("");
    	m_edit_uid4.SetWindowText("");
     
    	 status = ISO15693_Inventorys(icdev,pData,&len);
    	 if(status){		 
    		 MessageBox("ISO15693_Inventorys failed","Error",MB_OK|MB_ICONERROR);
    		 return;
    	 }     
     
    	 for(int i = 0 ;i < len /9;i++ ){
     
    		 if(i == 0)
    			 m_edit_uid1.SetWindowTextEx(&pData[9 * i + 1],8);
    		 if(i == 1) 
    			 m_edit_uid2.SetWindowTextEx(&pData[9 * i + 1],8);
    		 if(i == 2) 
    			 m_edit_uid3.SetWindowTextEx(&pData[9 * i + 1],8);
    		 if(i == 3) 
    			 m_edit_uid4.SetWindowTextEx(&pData[9 * i + 1],8);
     
    	 }	 
     
    	  MessageBox("INVENTORY success","Success",MB_OK|MB_ICONASTERISK);
    }
    C#
    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
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
     
    using System.Runtime.InteropServices;
     
    namespace test_RFID_reader
    {
        public partial class Form1 : Form
        {
     
            [DllImport("MasterRD.dll")]
            static extern int rf_init_com(int port, int baud);
            [DllImport("MasterRD.dll")]
            static extern int rf_ClosePort();
            [DllImport("MasterRD.dll")]
            static extern int rf_beep(short icdev, int msec);
            [DllImport("MasterRD.dll")]
            static extern int ISO15693_Inventorys(short icdev, out int pData, out int pLen);
            [DllImport("MasterRD.dll")]
            static extern int rf_get_device_number(out short icdev);
            [DllImport("MasterRD.dll")]
            static extern int ISO15693_Get_System_Information(short icdev, char model, out char pUID, out int pData, out int pLen);
     
            private int _status;
            private short _icdev = 0x0000;
            private int _pData;
            private int _pLen;
            private char _pUID;
     
            public Form1()
            {
                InitializeComponent();
     
                test();
            }
     
            private void test()
            {
                _status = rf_init_com(3, 19200);
     
                _status = rf_get_device_number(out _icdev);
                //MessageBox.Show(_icdev.ToString());
     
                //_status = rf_beep(_icdev, 1000);
     
                _status = ISO15693_Inventorys(_icdev, out _pData, out _pLen);
                //MessageBox.Show(_pData.ToString());
     
                if (_status == 0)
                {
                    ISO15693_Get_System_Information(_icdev, '1', out _pUID, out _pData, out _pLen);
                    MessageBox.Show(_pData.ToString()); // affiche : 990361856
                }
     
                //rf_ClosePort();
            }
        }
    }
    Le ID de la puce test est E00401007C3B07B9

    PS : Si un modérateur trouve un meilleur titre ne vous gêner pas à le changer.

  2. #2
    Membre expérimenté
    Profil pro
    Inscrit en
    Février 2006
    Messages
    197
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Février 2006
    Messages : 197
    Par défaut
    Salut,
    Ton char pData[MAX_RF_BUFFER] est une tableau de char et pas un int.
    regarde par exemple ce poste :
    http://social.msdn.microsoft.com/For...to-c?forum=clr

    pour te donner une idée.

  3. #3
    Membre actif
    Homme Profil pro
    Inscrit en
    Mai 2008
    Messages
    84
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 84
    Par défaut
    J'avais déjà essayé de le mettre en char[], mais j'avais ce message là :

    Une exception non gérée du type 'System.AccessViolationException' s'est produite dans test_RFID_reader.exe
    Informations supplémentaires*: Tentative de lecture ou d'écriture de mémoire protégée. Cela indique souvent qu'une autre mémoire est endommagée.

  4. #4
    Membre actif
    Homme Profil pro
    Inscrit en
    Mai 2008
    Messages
    84
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 84
    Par défaut
    Dans le code en C++ j'ai :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    ISO15693_Inventorys(icdev,pData,&len);
    [...]
    m_edit_uid1.SetWindowTextEx(&pData[1],8);
    Mais en C# je ne trouve pas l'équivalent de '&variable' pour avoir la référence mémoire ?

  5. #5
    Membre actif
    Homme Profil pro
    Inscrit en
    Mai 2008
    Messages
    84
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 84
    Par défaut
    Je viens juste d'apprendre que le "/$%"/ de id est en hexadecimal. Donc je dois trouver une bigintger et le convertir en hexa.

  6. #6
    Membre actif
    Homme Profil pro
    Inscrit en
    Mai 2008
    Messages
    84
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 84
    Par défaut
    System.Numerics ne fonctionne pas ? J'ai ajouté la référance !!
    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
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    using System.Runtime.InteropServices;
    using System.Numerics;
    
    namespace test_RFID_reader
    {
        public partial class Form1 : Form
        {
    
            [DllImport("MasterRD.dll")]
            static extern int rf_init_com(int port, int baud);
            [DllImport("MasterRD.dll")]
            static extern int rf_ClosePort();
            [DllImport("MasterRD.dll")]
            static extern int rf_beep(short icdev, int msec);
            [DllImport("MasterRD.dll")]
            static extern int ISO15693_Inventorys(short icdev, ref long pData, ref int pLen);
            [DllImport("MasterRD.dll")]
            static extern int rf_get_device_number(ref short icdev);
            [DllImport("MasterRD.dll")]
            static extern int ISO15693_Get_System_Information(short icdev, char model, ref char pUID, ref long pData, ref int pLen);
    
    
            private int _status;
            private short _icdev = 0x0000;
            private long _pData;
            private int _pLen;
            private char _pUID;
    
            public Form1()
            {
                InitializeComponent();
    
                test();
            }
    
            private void test()
            {
                _status = rf_init_com(3, 19200);
    
                _status = rf_get_device_number(ref _icdev);
                //MessageBox.Show(_icdev.ToString());
    
                //_status = rf_beep(_icdev, 1000);
    
                _status = ISO15693_Inventorys(_icdev, ref _pData, ref _pLen);
                //MessageBox.Show(_pData.ToString());
    
                if (_status == 0)
                {
                    ISO15693_Get_System_Information(_icdev, '1', ref _pUID, ref _pData, ref _pLen);
    
                    MessageBox.Show(_pData.ToString("X"));
                }
    
                //rf_ClosePort();
            }
        }
    }

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 4
    Dernier message: 05/02/2006, 10h53
  2. Réponses: 9
    Dernier message: 19/12/2005, 16h41
  3. question idiote sur terme utilisé dans les offres
    Par coyott dans le forum Emploi
    Réponses: 4
    Dernier message: 24/08/2005, 17h16
  4. DLL Visual C++ appelée dans un programme Visual Basic
    Par marseillais57 dans le forum MFC
    Réponses: 7
    Dernier message: 21/07/2005, 14h57
  5. [MFC][DLL]Dialog Avec ActiveX dans une DLL ?
    Par matazz dans le forum MFC
    Réponses: 1
    Dernier message: 16/05/2005, 16h36

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