Bonjour,
Je dois "piloter" un lecteur RFID branché sur un port COM.
Je dois lire des cartes RFID contenant un simple numéro.
En exemple, j'ai une appli dévellopée en C++, et je dois insérer cette lecture de carte dans une appli existante dévellopée en VB.NET.
Mon code VB.NET compile, s'exécute mais ne retourne aucune valeur.Je précise que l'ouverture du port com ne pose aucun problème.
Voici le code C++:
SunComm.h
extern "C" __declspec(dllexport) int __stdcall CommRead(int index, int *id, char *function, char *data);
Main.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| void __fastcall TFrmMain::Timer1Timer(TObject *Sender)
{
int i;
if (CommRead(0,&i,Func,Data) != 0)
{
LRece->Caption = AnsiString(Func) + " " + AnsiString(Data);
if (StrLen(Data) == 17) EUID->Text = AnsiString(Data+1);
else EUID->Text = "";
Count = 5;
}
else
if (--Count == 0) LRece->Caption = "";
} |
Voici mon code:
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
| Imports System.Runtime.InteropServices
Module TestRFID
<DllImport("C:\DEV\TestRFIDCaisse\TestRFIDCaisse\SunComm.dll",
CallingConvention:=CallingConvention.StdCall, CharSet:=CharSet.Unicode)>
Public Function CommRead(ByVal idx As Integer, ByRef ID As Integer, _
<MarshalAs(UnmanagedType.VBByRefStr)> ByRef Functio As String, _
<MarshalAs(UnmanagedType.VBByRefStr)> ByRef DataR As String) As Long
End Function
End Module
Imports System.Runtime.InteropServices
Public Class Form1
Public Func As New String(vbNullChar, 10)
Public DataL As New String(vbNullChar, 100)
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim truc = New Long
Dim i As Integer = 1
Dim j As Integer = 0
Dim machin As String = ""
Dim machin2 As String = ""
truc = CommRead(0, i, Func(0), DataL(0))
For j = 0 To 100 - 1
MsgBox(j & " " & Asc(DataL(j)))
machin = machin & Convert.ToString(DataL(j))
Next
For j = 0 To 10 - 1
machin2 = machin2 & Convert.ToString(Func(j))
Next
End Sub
End Class |
Je fais une réservation en mémoire parce que la fonction ne peux pas elle même écrire en mémoire si la place n'est pas réservée.
Mes tableaux Datal et Func qui devraient contenir une valeur de retour sont vides.
Désolée pour les variables machin et truc, j'ai manqué d'inspiration...je mettrais de vrais nom de variable quand j'intégrerai mon code dans ma vraie appli.
Quelqu'un pour m'aider?
Merci
Fabienne
Partager