annotate KKFX80E.c @ 110:ce9ecc761bc5

New build
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Fri, 28 Jun 2013 14:46:34 +0200
parents 4f1f353e84f5
children 3427013e4f70
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
89
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
1 #include <ctype.h>
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
2 #include <windows.h>
102
4f1f353e84f5 Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 89
diff changeset
3 #include <utility.h>
4f1f353e84f5 Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 89
diff changeset
4 #include <ansi_c.h>
4f1f353e84f5 Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 89
diff changeset
5
89
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
6
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
7 int (_stdcall *FX_OpenPort)(char **Port) = NULL;
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
8 void (_stdcall *FX_ClosePort)(void) = NULL;
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
9 int (_stdcall *FX_SendCommand)(char **Command) = NULL;
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
10 int (_stdcall *FX_GetReport)(char **Data) = NULL;
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
11 void (_stdcall *FX_Debug)(BOOL DbgFlag) = NULL;
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
12 // int (_stdcall *GetFXM)(char **Data) = NULL;
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
13 // void (_stdcall *Log)(int DbgNum) = NULL;
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
14 // int (_stdcall *ReadMonitor)(char **Data) = NULL;
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
15 // BOOL (_stdcall *EnumeratePorts)(char **PortName, char *PortNamePrefix) = NULL;
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
16
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
17 static HMODULE module;
102
4f1f353e84f5 Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 89
diff changeset
18 static char *errormsg;
4f1f353e84f5 Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 89
diff changeset
19
4f1f353e84f5 Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 89
diff changeset
20
4f1f353e84f5 Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 89
diff changeset
21 char * FX_Error(void)
4f1f353e84f5 Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 89
diff changeset
22 {
4f1f353e84f5 Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 89
diff changeset
23 return errormsg;
4f1f353e84f5 Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 89
diff changeset
24 }
89
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
25
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
26
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
27 int FX_Init(void)
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
28 {
102
4f1f353e84f5 Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 89
diff changeset
29 FARPROC funcp = NULL;
4f1f353e84f5 Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 89
diff changeset
30 errormsg = "";
89
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
31
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
32 module = LoadLibrary("KK_FX80E.dll");
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
33 if (! module)
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
34 return 0;
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
35
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
36 funcp = GetProcAddress(module, "FX_OpenPort");
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
37 if (! funcp)
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
38 goto error;
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
39 FX_OpenPort = (void *)funcp;
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
40
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
41 funcp = GetProcAddress(module, "FX_ClosePort");
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
42 if (! funcp)
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
43 goto error;
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
44 FX_ClosePort = (void *)funcp;
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
45
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
46 funcp = GetProcAddress(module, "FX_SendCommand");
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
47 if (! funcp)
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
48 goto error;
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
49 FX_SendCommand = (void *)funcp;
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
50
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
51 funcp = GetProcAddress(module, "FX_GetReport");
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
52 if (! funcp)
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
53 goto error;
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
54 FX_GetReport = (void *)funcp;
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
55
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
56 funcp = GetProcAddress(module, "FX_Debug");
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
57 if (! funcp)
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
58 goto error;
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
59 FX_Debug = (void *)funcp;
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
60
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
61 return 1;
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
62
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
63 error:
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
64 FreeLibrary(module);
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
65 return 0;
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
66 }
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
67
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
68
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
69 void FX_Free(void)
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
70 {
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
71 FreeLibrary(module);
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
72 }
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
73
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
74
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
75 int FX_Open(char *port)
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
76 {
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
77 int rv = FX_OpenPort(&port);
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
78 if (! rv)
102
4f1f353e84f5 Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 89
diff changeset
79 errormsg = port;
89
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
80 return rv;
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
81 }
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
82
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
83
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
84 void FX_Close(void)
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
85 {
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
86 FX_ClosePort();
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
87 }
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
88
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
89
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
90 int FX_Send(char *cmd)
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
91 {
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
92 int rv = FX_SendCommand(&cmd);
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
93 if (! rv)
102
4f1f353e84f5 Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 89
diff changeset
94 errormsg = cmd;
89
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
95 return rv;
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
96 }
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
97
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
98
102
4f1f353e84f5 Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 89
diff changeset
99 int FX_Recv(char **ret, int timeout)
89
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
100 {
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
101 int rv;
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
102 char *data;
102
4f1f353e84f5 Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 89
diff changeset
103 double mark = Timer();
89
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
104 do {
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
105 data = ".";
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
106 rv = FX_GetReport(&data);
102
4f1f353e84f5 Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 89
diff changeset
107 if ((Timer() - mark) > timeout) {
4f1f353e84f5 Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 89
diff changeset
108 rv = 0;
4f1f353e84f5 Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 89
diff changeset
109 data = "Function FX_Recv: Timeout";
4f1f353e84f5 Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 89
diff changeset
110 }
4f1f353e84f5 Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 89
diff changeset
111 } while ((! data) && (rv == 1));
4f1f353e84f5 Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 89
diff changeset
112
4f1f353e84f5 Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 89
diff changeset
113 if (! rv) {
4f1f353e84f5 Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 89
diff changeset
114 errormsg = data;
4f1f353e84f5 Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 89
diff changeset
115 data = NULL;
4f1f353e84f5 Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 89
diff changeset
116 }
4f1f353e84f5 Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 89
diff changeset
117
89
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
118 if (ret)
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
119 *ret = data;
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
120
102
4f1f353e84f5 Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 89
diff changeset
121 return rv;
89
c9e4f63c2033 Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
122 }