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 115 116 117 118 119 120 121 122 123
| /*Algorithme----------------------------------------------------------
//Test communication UDP, clignotement d'une Led à la cadence des réceptions (500 ms en théorie)
#include <cvirte.h>
#include <userint.h>
#include "TestCom.h"
#include <tcpsupp.h>
#include <toolbox.h>
#include <utility.h>
#include <udpsupp.h>
#include <string.h>
#include <UDPReaderWriterCommon.h>*/
static int panelHandle;
static int readerChannel = 0;
static int Nb=0;
int CVICALLBACK UDPCallback (unsigned channel, int eventType, int errCode, void *callbackData);
int main (int argc, char *argv[])
{
if (InitCVIRTE (0, argv, 0) == 0)
return -1; /* out of memory */
if ((panelHandle = LoadPanel (0, "TestCom.uir", PANEL)) < 0)
return -1;
DisplayPanel (panelHandle);
RunUserInterface ();
DiscardPanel (panelHandle);
return 0;
}
int CVICALLBACK UDPCallback (unsigned channel, int eventType, int errCode, void *callbackData)
{
int size, error;
if(eventType==UDP_DATAREADY)
{
SetCtrlVal( panelHandle, PANEL_LED, 1);
size = UDPRead(channel, NULL, 0, 1000, NULL, NULL);
Nb++;
Ecriture de la valeur de Nb:
SetCtrlVal( panelHandle, PANEL_NB_TRAMES, Nb);
}
return 0;
}
//Après appuie sur le bouton "deconnexion"-------------------------------------------------------------
int CVICALLBACK FermerComEth (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
SetCtrlVal( panelHandle, PANEL_ConfigRecept_2, 1);
UDPMulticastUnsubscribe(readerChannel, "231.20.1.2", "66.21.200.120");
DisposeUDPChannel(readerChannel);
SetCtrlVal( panelHandle, PANEL_NB_TRAMES, 0);
SetCtrlVal( panelHandle, PANEL_LED, 0);
break;
}
return 0;
}
//Après appuie sur le bouton "connexion"-------------------------------------------------------------------
int CVICALLBACK OuvrirComEth (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
int status;
switch (event)
{
case EVENT_COMMIT:
CreateUDPChannelConfig(50003, UDP_ANY_ADDRESS, 0, UDPCallback, NULL, &readerChannel);
status =UDPMulticastSubscribe(readerChannel, "231.20.1.2", "66.21.200.120");
if(status<0)
{ MessagePopup("Warning message", "Connexion ERROR");
SetCtrlVal( panelHandle, PANEL_ConfigRecept_1, 0);
SetCtrlVal( panelHandle, PANEL_LED, 0);
}
else
{
SetCtrlVal( panelHandle, PANEL_ConfigRecept_1, 1);
}
break;
}
return 0;
}
int CVICALLBACK quitterAcqui (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
QuitUserInterface (0);
break;
}
return 0;
} |
Partager