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
|
/******************************************************************************
use_dll_auto2.c :
Utilisation d'une dll créée sous LabVIEW
******************************************************************************/
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
/******************************************************************************
main : point d'entrée du programme.
******************************************************************************/
int main()
{
/* variables locales */
long g_hCOM, pbitread, nIdIn, loopVol;
long len=1;
char BufferRead[256];
unsigned char boolFctOPEN, boolFctWRITE, boolFctREAD, boolFctCLOSE;
/*
void __stdcall OpenCOM(long nIdIn, unsigned char *boolFctOPEN, long *g_hCOMOut);
void __stdcall Initialise(long g_hCOMIn, long *pbitread, char BufferRead[], long len);
void __stdcall Pfc_req_loop_vol(long g_hCOMIn, long *loopVol, unsigned char *boolFctREAD, unsigned char *boolFctWRITE, long *pbitread, char BufferRead[], long len);
void __stdcall CloseCOM(long g_hCOMIn, unsigned char *boolFctCLOSE);
*/
int nChoice = 1;
HINSTANCE DLLHandle;
typedef void(*Type_Pointeur_De_Fonction_OpenCOM)(long, unsigned char*, long*);
Type_Pointeur_De_Fonction_OpenCOM Pointeur_Fonction_OpenCOM;
typedef void(*Type_Pointeur_De_Fonction_Initialise)(long, long*, char, long);
Type_Pointeur_De_Fonction_Initialise Pointeur_Fonction_Initialise;
typedef void(*Type_Pointeur_De_Fonction_Pfc_req_loop_vol)(long, long*, unsigned char*, unsigned char*, long*, char, long);
Type_Pointeur_De_Fonction_Pfc_req_loop_vol Pointeur_Fonction_Pfc_req_loop_vol;
typedef void(*Type_Pointeur_De_Fonction_CloseCOM)(long, unsigned char*);
Type_Pointeur_De_Fonction_CloseCOM Pointeur_Fonction_CloseCOM;
DLLHandle = LoadLibrary("dll_auto2.dll");
Pointeur_Fonction_OpenCOM = (Type_Pointeur_De_Fonction_OpenCOM)GetProcAddress(DLLHandle,"OpenCOM");
Pointeur_Fonction_Initialise = (Type_Pointeur_De_Fonction_Initialise)GetProcAddress(DLLHandle,"Initialise");
Pointeur_Fonction_Pfc_req_loop_vol = (Type_Pointeur_De_Fonction_Pfc_req_loop_vol)GetProcAddress(DLLHandle,"Pfc_req_loop_vol");
Pointeur_Fonction_CloseCOM = (Type_Pointeur_De_Fonction_CloseCOM)GetProcAddress(DLLHandle,"CloseCOM");
/* demande du numéro du port COM */
printf("Entrez le numero du port COM : ");
scanf("%ld", &nIdIn);
/* tentative d'ouverture */
printf("Ouverture et configuration du port COM%ld...\r\n", nIdIn);
Pointeur_Fonction_OpenCOM(nIdIn, &boolFctOPEN, &g_hCOM);
if(boolFctOPEN==1){
printf("...OK\r\n");
}
else
{
return -1;
}
/* boucle tant que l'on ne quitte pas */
while(nChoice != 3)
{
/*menu*/
printf("\r\n");
printf("1 : Init.\r\n");
printf("2 : Loop vol.\r\n");
printf("3 : Quitter.\r\n");
printf("Choix : ");
scanf("%d", &nChoice);
if(nChoice == 1)
{
/*initialisation*/
Pointeur_Fonction_Initialise(g_hCOM, &pbitread, BufferRead, len);
printf("BufferRead : %s /r/n", BufferRead);
}
if(nChoice == 2)
{
/*lecture loop vol*/
printf("\r\n");
printf("Reception de donnees...\r\n");
Pointeur_Fonction_Pfc_req_loop_vol(g_hCOM, &loopVol, &boolFctREAD, &boolFctWRITE, &pbitread, BufferRead, len);
printf("%s, soit %ld bit lus\r\n", BufferRead, pbitread);
}
}
/* fermeture du port COM et retour */
Pointeur_Fonction_CloseCOM(g_hCOM, &boolFctCLOSE);
printf("fermeture COM : %u \r\n", boolFctCLOSE);
FreeLibrary(DLLHandle); //on décharge la bibliothèque de la mémoire.
return 0;
} |
Partager