Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
236 | f9daq | 1 | #include <utility.h> |
2 | #include <ansi_c.h> |
||
3 | #include <tcpsupp.h> |
||
4 | #include <cvirte.h> |
||
5 | #include <userint.h> |
||
6 | #include "testcli_ui.h" |
||
7 | |||
8 | static int panelHandle; |
||
9 | static CmtThreadPoolHandle poolHandle = 0; |
||
10 | #define MAX_THREADS 10 |
||
11 | |||
12 | static unsigned int chandle = 0; |
||
13 | static int tfID; |
||
14 | |||
15 | int main (int argc, char *argv[]) { |
||
16 | if (InitCVIRTE (0, argv, 0) == 0) |
||
17 | return -1; /* out of memory */ |
||
18 | SetStdioPort (CVI_STDIO_WINDOW); |
||
19 | SetSleepPolicy(VAL_SLEEP_MORE); |
||
20 | CmtNewThreadPool (MAX_THREADS, &poolHandle); |
||
21 | |||
22 | |||
23 | if ((panelHandle = LoadPanel (0, "testcli_ui.uir", PANEL)) < 0) |
||
24 | return -1; |
||
25 | DisplayPanel (panelHandle); |
||
26 | RunUserInterface (); |
||
27 | DiscardPanel (panelHandle); |
||
28 | return 0; |
||
29 | } |
||
30 | |||
31 | |||
32 | int CVICALLBACK SocketCB (unsigned handle, int xType, int errCode, void *callbackData) { |
||
33 | |||
34 | int nb = 0 ; |
||
35 | |||
36 | const int maxlen=0xFF; |
||
37 | char msg[maxlen]; |
||
38 | for (int i=0;i<maxlen; i++) msg[i]=0; |
||
39 | switch (xType) { |
||
40 | case TCP_DISCONNECT: |
||
41 | printf("TCP_DISCONNECT ErrorString %s\n",GetTCPErrorString(errCode)); |
||
42 | printf("TCP_DISCONNECT SystemErrorString %s\n",GetTCPSystemErrorString()); |
||
43 | //DisconnectFromTCPServer (&chandle); |
||
44 | chandle = 0; |
||
45 | break; |
||
46 | case TCP_DATAREADY: { |
||
47 | |||
48 | int hdr[2]={0,0}; |
||
49 | nb = ClientTCPRead(handle,&hdr[0],8,1000); |
||
50 | |||
51 | int size = hdr[1] - 8; |
||
52 | if (size>maxlen) size=maxlen; |
||
53 | nb = 0; |
||
54 | while (nb < size) { |
||
55 | int retval = ClientTCPRead(handle,&msg[nb],size-nb,1000); |
||
56 | if (retval<1) break; |
||
57 | nb += retval; |
||
58 | } |
||
59 | printf("Received RECID %d LEN %d: %s\n", hdr[0], hdr[1],msg); |
||
60 | |||
61 | break; |
||
62 | |||
63 | } |
||
64 | } |
||
65 | return 0; |
||
66 | } |
||
67 | |||
68 | int CVICALLBACK ExitCB (int panel, int control, int event, |
||
69 | void *callbackData, int eventData1, int eventData2) { |
||
70 | switch (event) { |
||
71 | case EVENT_COMMIT: |
||
72 | QuitUserInterface (0); |
||
73 | break; |
||
74 | } |
||
75 | return 0; |
||
76 | } |
||
77 | |||
78 | int CVICALLBACK SendCB (int panel, int control, int event, |
||
79 | void *callbackData, int eventData1, int eventData2) { |
||
80 | char data[0xFF]; |
||
81 | char *msg = &data[8]; |
||
82 | int *hdr = data; |
||
83 | static int ncount=0; |
||
84 | switch (event) { |
||
85 | case EVENT_COMMIT: |
||
86 | GetCtrlVal(panel,PANEL_TXT , msg); |
||
87 | sprintf(msg,"%s %d\n", msg, ncount++); |
||
88 | hdr[0]=ncount%4; |
||
89 | hdr[1]=strlen(msg) + 8; |
||
90 | ClientTCPWrite(chandle,data,hdr[1],1000); // init |
||
91 | break; |
||
92 | } |
||
93 | return 0; |
||
94 | } |
||
95 | |||
96 | int CVICALLBACK ConnectCB (int panel, int control, int event, |
||
97 | void *callbackData, int eventData1, int eventData2) { |
||
98 | switch (event) { |
||
99 | case EVENT_COMMIT: |
||
100 | ConnectToTCPServerEx (&chandle, 3210, "192.168.1.254", SocketCB, NULL, 0, TCP_ANY_LOCAL_PORT); |
||
101 | break; |
||
102 | } |
||
103 | return 0; |
||
104 | } |