Rev 78 | Rev 124 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 78 | Rev 100 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | #include < |
1 | #include <stdlib.h> |
2 | #include |
2 | #include <stdio.h> |
- | 3 | ||
- | 4 | #ifdef _CVI_ |
|
3 | #include <utility.h> |
5 | #include <utility.h> |
- | 6 | #endif |
|
4 | 7 | ||
- | 8 | #ifdef LINUX |
|
- | 9 | #include <dlfcn.h> |
|
- | 10 | #define LoadLibrary(x) dlopen( (x), RTLD_NOW ); |
|
- | 11 | #define GetProcAddress(x,y) dlsym((x),(y)) |
|
- | 12 | static int GetCurrentPlatform(void ){return 0;}; |
|
- | 13 | #define __stdcall |
|
- | 14 | #define UCHAR unsigned char |
|
- | 15 | #define HINSTANCE void * |
|
- | 16 | #define _VI_FUNC |
|
- | 17 | #include <stdlib.h> |
|
- | 18 | #include <stdio.h> |
|
- | 19 | #include <stdint.h> |
|
- | 20 | #include <string.h> |
|
- | 21 | #endif |
|
- | 22 | ||
- | 23 | #include "wienvme_dll.h" |
|
5 | //----------- DEFINES ----------------------------------------------------- |
24 | //----------- DEFINES ----------------------------------------------------- |
- | 25 | #define DEVICENAME_LINUX "/dev/pcivme_0" // a device name 'template' for WINNT |
|
6 | #define DEVICENAME_NT "\\\\.\\PCIVME:\\VMEMMxx" // a device name 'template' for WINNT |
26 | #define DEVICENAME_NT "\\\\.\\PCIVME:\\VMEMMxx" // a device name 'template' for WINNT |
7 | #define DEVICENAME_9X "\\\\.\\C:\\windows\\system\\VWIENVMED.vxd" // the same for WIN95/98 |
27 | #define DEVICENAME_9X "\\\\.\\C:\\windows\\system\\VWIENVMED.vxd" // the same for WIN95/98 |
8 | #define MODULE_NUMBER 1 // number of connected CC32 module |
28 | #define MODULE_NUMBER 1 // number of connected CC32 module |
9 | 29 | ||
10 | #define VMEinit (*vme_init) |
30 | #define VMEinit (*vme_init) |
Line 19... | Line 39... | ||
19 | static int VMEclose (int); |
39 | static int VMEclose (int); |
20 | 40 | ||
21 | int hHandle24, hHandle32; |
41 | int hHandle24, hHandle32; |
22 | int VMEmodule; |
42 | int VMEmodule; |
23 | 43 | ||
- | 44 | static HINSTANCE DLLHandle; |
|
24 | void WIENVME_load (char* module_path) |
45 | void WIENVME_load (char* module_path) |
25 | { |
46 | { |
- | 47 | /* |
|
26 | int stat; |
48 | int stat; |
27 | 49 | |
|
28 | if (module_path == NULL) |
50 | if (module_path == NULL) |
29 | VMEmodule = LoadExternalModule |
51 | VMEmodule = LoadExternalModule |
30 | ("c:\\home\\CVI\\instr\\WIENVME_DLL\\pcivme_ni.lib"); |
52 | ("c:\\home\\CVI\\instr\\WIENVME_DLL\\pcivme_ni.lib"); |
31 | else |
53 | else |
32 | VMEmodule = LoadExternalModule (module_path); |
54 | VMEmodule = LoadExternalModule (module_path); |
33 | 55 | ||
34 | vme_init = GetExternalModuleAddr (VMEmodule, "VMEinit", &stat); |
56 | vme_init = GetExternalModuleAddr (VMEmodule, "VMEinit", &stat); |
35 | vme_read = GetExternalModuleAddr (VMEmodule, "VMEread", &stat); |
57 | vme_read = GetExternalModuleAddr (VMEmodule, "VMEread", &stat); |
36 | vme_write = GetExternalModuleAddr (VMEmodule, "VMEwrite", &stat); |
58 | vme_write = GetExternalModuleAddr (VMEmodule, "VMEwrite", &stat); |
37 | vme_reset = GetExternalModuleAddr (VMEmodule, "VMEreset", &stat); |
59 | vme_reset = GetExternalModuleAddr (VMEmodule, "VMEreset", &stat); |
38 | vme_close = GetExternalModuleAddr (VMEmodule, "VMEclose", &stat); |
60 | vme_close = GetExternalModuleAddr (VMEmodule, "VMEclose", &stat); |
- | 61 | */ |
|
- | 62 | if (module_path == NULL) { |
|
- | 63 | DLLHandle = LoadLibrary("c:\\home\\CVI\\instr\\WIENVME_DLL\\pcivme_ni.lib"); |
|
- | 64 | } else { |
|
- | 65 | DLLHandle = LoadLibrary(module_path); |
|
- | 66 | } |
|
- | 67 | if (!DLLHandle) { |
|
- | 68 | printf ("\n\nFailed to Open libxxusb.dll \n"); |
|
- | 69 | return; |
|
- | 70 | } |
|
- | 71 | ||
- | 72 | vme_init = (void *) GetProcAddress (DLLHandle , "VMEinit"); |
|
- | 73 | vme_read = (void *) GetProcAddress (DLLHandle , "VMEread"); |
|
- | 74 | vme_write =(void *) GetProcAddress (DLLHandle , "VMEwrite"); |
|
- | 75 | vme_reset =(void *) GetProcAddress (DLLHandle , "VMEreset"); |
|
- | 76 | vme_close =(void *) GetProcAddress (DLLHandle , "VMEclose"); |
|
39 | 77 | ||
40 | return; |
78 | return; |
41 | } |
79 | } |
42 | 80 | ||
43 | int WIENVME_open (int* hHandle, unsigned char AddMod, char* device_name, |
81 | int WIENVME_open (int* hHandle, unsigned char AddMod, char* device_name, |
Line 47... | Line 85... | ||
47 | 85 | ||
48 | /* open a path to a device. */ |
86 | /* open a path to a device. */ |
49 | if (device_name == NULL) |
87 | if (device_name == NULL) |
50 | switch (GetCurrentPlatform ()) |
88 | switch (GetCurrentPlatform ()) |
51 | { |
89 | { |
- | 90 | case 0: |
|
- | 91 | device_name = DEVICENAME_LINUX; |
|
52 | case 2: |
92 | case 2: |
53 | device_name = DEVICENAME_9X; |
93 | device_name = DEVICENAME_9X; |
54 | break; |
94 | break; |
55 | case 3: |
95 | case 3: |
56 | device_name = DEVICENAME_NT; |
96 | device_name = DEVICENAME_NT; |
Line 85... | Line 125... | ||
85 | return 0; |
125 | return 0; |
86 | } |
126 | } |
87 | 127 | ||
88 | void WIENVME_unload () |
128 | void WIENVME_unload () |
89 | { |
129 | { |
90 | UnloadExternalModule |
130 | //UnloadExternalModule (VMEmodule); |
91 | return; |
131 | return; |
92 | } |
132 | } |
93 | 133 | ||
94 | int WIENVME_close (int hHandle) |
134 | int WIENVME_close (int hHandle) |
95 | { |
135 | { |
Line 141... | Line 181... | ||
141 | int result; |
181 | int result; |
142 | 182 | ||
143 | /* D8 read */ |
183 | /* D8 read */ |
144 | result = VMEread(hHandle, at, 1, n, buff); |
184 | result = VMEread(hHandle, at, 1, n, buff); |
145 | if (result) { |
185 | if (result) { |
146 | printf("D8 read at |
186 | printf("D8 read at 0x%lX failed!\n", at); |
147 | } |
187 | } |
148 | // printf("0x%X, 0x%X, 0x%X, 0x%X\n", hHandle, at, n, * (unsigned short *) buff); |
188 | // printf("0x%X, 0x%X, 0x%X, 0x%X\n", hHandle, at, n, * (unsigned short *) buff); |
149 | return (result); |
189 | return (result); |
150 | } |
190 | } |
151 | 191 | ||
Line 154... | Line 194... | ||
154 | int result; |
194 | int result; |
155 | 195 | ||
156 | /* D16 read */ |
196 | /* D16 read */ |
157 | result = VMEread(hHandle, at, 2, n, buff); |
197 | result = VMEread(hHandle, at, 2, n, buff); |
158 | if (result) { |
198 | if (result) { |
159 | printf("D16 read at |
199 | printf("D16 read at 0x%lX failed!\n", at); |
160 | } |
200 | } |
161 | // printf("0x%X, 0x%X, 0x%X, 0x%X\n", hHandle, at, n, * (unsigned short *) buff); |
201 | // printf("0x%X, 0x%X, 0x%X, 0x%X\n", hHandle, at, n, * (unsigned short *) buff); |
162 | return (result); |
202 | return (result); |
163 | } |
203 | } |
164 | 204 | ||
Line 167... | Line 207... | ||
167 | int result; |
207 | int result; |
168 | 208 | ||
169 | /* D32 read */ |
209 | /* D32 read */ |
170 | result = VMEread(hHandle, at, 4, n, buff); |
210 | result = VMEread(hHandle, at, 4, n, buff); |
171 | if (result) { |
211 | if (result) { |
172 | printf("D32 read at |
212 | printf("D32 read at 0x%lX failed!\n", at); |
173 | } |
213 | } |
174 | //printf("0x%X, 0x%X, 0x%X, 0x%X\n", hHandle, at, n, * (unsigned short *) buff); |
214 | //printf("0x%X, 0x%X, 0x%X, 0x%X\n", hHandle, at, n, * (unsigned short *) buff); |
175 | return (result); |
215 | return (result); |
176 | } |
216 | } |
177 | 217 | ||
Line 180... | Line 220... | ||
180 | int result; |
220 | int result; |
181 | 221 | ||
182 | /* D8 write */ |
222 | /* D8 write */ |
183 | result = VMEwrite(hHandle, at, 1, n, buff); |
223 | result = VMEwrite(hHandle, at, 1, n, buff); |
184 | if (result) { |
224 | if (result) { |
185 | printf("D8 write at |
225 | printf("D8 write at 0x%lX failed!\n", at); |
186 | } |
226 | } |
187 | return (result); |
227 | return (result); |
188 | } |
228 | } |
189 | 229 | ||
190 | int WIENVME_write16 (int hHandle, unsigned long n, unsigned long at, void* buff) |
230 | int WIENVME_write16 (int hHandle, unsigned long n, unsigned long at, void* buff) |
Line 192... | Line 232... | ||
192 | int result; |
232 | int result; |
193 | 233 | ||
194 | /* D16 write */ |
234 | /* D16 write */ |
195 | result = VMEwrite(hHandle, at, 2, n, buff); |
235 | result = VMEwrite(hHandle, at, 2, n, buff); |
196 | if (result) { |
236 | if (result) { |
197 | printf("D16 write at |
237 | printf("D16 write at 0x%lX failed!\n", at); |
198 | } |
238 | } |
199 | return (result); |
239 | return (result); |
200 | } |
240 | } |
201 | 241 | ||
202 | int WIENVME_write32 (int hHandle, unsigned long n, unsigned long at, void* buff) |
242 | int WIENVME_write32 (int hHandle, unsigned long n, unsigned long at, void* buff) |
Line 204... | Line 244... | ||
204 | int result; |
244 | int result; |
205 | 245 | ||
206 | /* D32 write */ |
246 | /* D32 write */ |
207 | result = VMEwrite(hHandle, at, 4, n, buff); |
247 | result = VMEwrite(hHandle, at, 4, n, buff); |
208 | if (result) { |
248 | if (result) { |
209 | printf("D32 write at |
249 | printf("D32 write at 0x%lX failed!\n", at); |
210 | } |
250 | } |
211 | //printf("D32 write at 0x%X buff=0x%X\n", at,((int*) buff)[0]); |
251 | //printf("D32 write at 0x%X buff=0x%X\n", at,((int*) buff)[0]); |
212 | return (result); |
252 | return (result); |
213 | } |
253 | } |
214 | 254 |