comparison KKFX80E.c @ 89:c9e4f63c2033

Implement data acquisition through direct communication with the KK counter
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Thu, 21 Mar 2013 19:00:22 +0100
parents
children 4f1f353e84f5
comparison
equal deleted inserted replaced
88:9b7588cd4013 89:c9e4f63c2033
1 #include <ctype.h>
2 #include <windows.h>
3
4 int (_stdcall *FX_OpenPort)(char **Port) = NULL;
5 void (_stdcall *FX_ClosePort)(void) = NULL;
6 int (_stdcall *FX_SendCommand)(char **Command) = NULL;
7 int (_stdcall *FX_GetReport)(char **Data) = NULL;
8 void (_stdcall *FX_Debug)(BOOL DbgFlag) = NULL;
9 // int (_stdcall *GetFXM)(char **Data) = NULL;
10 // void (_stdcall *Log)(int DbgNum) = NULL;
11 // int (_stdcall *ReadMonitor)(char **Data) = NULL;
12 // BOOL (_stdcall *EnumeratePorts)(char **PortName, char *PortNamePrefix) = NULL;
13
14 static HMODULE module;
15
16
17 int FX_Init(void)
18 {
19 FARPROC funcp;
20
21 module = LoadLibrary("KK_FX80E.dll");
22 if (! module)
23 return 0;
24
25 funcp = GetProcAddress(module, "FX_OpenPort");
26 if (! funcp)
27 goto error;
28 FX_OpenPort = (void *)funcp;
29
30 funcp = GetProcAddress(module, "FX_ClosePort");
31 if (! funcp)
32 goto error;
33 FX_ClosePort = (void *)funcp;
34
35 funcp = GetProcAddress(module, "FX_SendCommand");
36 if (! funcp)
37 goto error;
38 FX_SendCommand = (void *)funcp;
39
40 funcp = GetProcAddress(module, "FX_GetReport");
41 if (! funcp)
42 goto error;
43 FX_GetReport = (void *)funcp;
44
45 funcp = GetProcAddress(module, "FX_Debug");
46 if (! funcp)
47 goto error;
48 FX_Debug = (void *)funcp;
49
50 return 1;
51
52 error:
53 FreeLibrary(module);
54 return 0;
55 }
56
57
58 void FX_Free(void)
59 {
60 FreeLibrary(module);
61 }
62
63
64 int FX_Open(char *port)
65 {
66 int rv = FX_OpenPort(&port);
67 #ifdef DEBUG
68 if (! rv)
69 fprintf(stderr, "%s\n", *port);
70 #endif
71 return rv;
72 }
73
74
75 void FX_Close(void)
76 {
77 FX_ClosePort();
78 }
79
80
81 int FX_Send(char *cmd)
82 {
83 int rv = FX_SendCommand(&cmd);
84 #ifdef DEBUG
85 if (! rv)
86 fprintf(stderr, "%s\n", cmd);
87 #endif
88 return rv;
89 }
90
91
92 char * FX_Recv(char **ret)
93 {
94 int rv;
95 char *data;
96 do {
97 data = ".";
98 rv = FX_GetReport(&data);
99 } while (! data);
100 #ifdef DEBUG
101 if (! rv)
102 fprintf(stderr, "%s\n", data);
103 #endif
104 if (! rv)
105 return NULL;
106 if (ret)
107 *ret = data;
108
109 return data;
110 }