Subversion Repositories f9daq

Rev

Rev 139 | Rev 307 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 139 Rev 264
Line 11... Line 11...
11
#include <stdint.h>
11
#include <stdint.h>
12
#include <string.h>
12
#include <string.h>
13
#endif
13
#endif
14
 
14
 
15
#include "wusbvme_dll.h"
15
#include "wusbvme_dll.h"
-
 
16
#include <userint.h>
-
 
17
#include <utility.h>
16
 
18
 
17
usb_dev_handle *WUSB_udev;
19
usb_dev_handle *WUSB_udev;
18
 
20
 
19
static HINSTANCE DLLHandle;
21
static HINSTANCE DLLHandle;
20
 
22
 
Line 67... Line 69...
67
short __stdcall VME_write_16(usb_dev_handle *hdev, short Address_Modifier, long VME_Address, long Data);
69
short __stdcall VME_write_16(usb_dev_handle *hdev, short Address_Modifier, long VME_Address, long Data);
68
short __stdcall VME_write_32(usb_dev_handle *hdev, short Address_Modifier, long VME_Address, long Data);
70
short __stdcall VME_write_32(usb_dev_handle *hdev, short Address_Modifier, long VME_Address, long Data);
69
 
71
 
70
 
72
 
71
void _VI_FUNC WIENER_VMUSB_load (const char* module_path) {
73
void _VI_FUNC WIENER_VMUSB_load (const char* module_path) {
-
 
74
       
72
  if (module_path == NULL) {
75
  if (module_path == NULL) {
73
    DLLHandle = LoadLibrary("c:\\Windows\\system32\\libxxusb.dll");
76
    DLLHandle = LoadLibrary("c:\\Windows\\system32\\libxxusb.dll");
74
  } else {
77
  } else {
75
    DLLHandle = LoadLibrary(module_path);
78
    DLLHandle = LoadLibrary(module_path);
-
 
79
                printf("Module Path %s\n", module_path);
76
  }
80
  }
77
  if (!DLLHandle) {
81
  if (!DLLHandle) {
78
    printf ("\n\nFailed to Open libxxusb.dll  \n");
82
    printf ("\n\nFailed to Open libxxusb.dll \n");
79
    printf("LastError 0x%x\n",GetLastError() );
83
    printf("LastError 0x%x\n",GetLastError() );
-
 
84
                MessagePopup ("ERROR", "Failed to load libxxusb.dll ");
80
    return;
85
    return;
-
 
86
  } else {
-
 
87
                printf ("\n\nSuccesfully Opened libxxusb.dll  \n");    
81
  }
88
        }
82
  if (!(xxusb_register_read_Ptr = (void *) GetProcAddress(DLLHandle,"xxusb_register_read"))) exit(1);
89
  if (!(xxusb_register_read_Ptr = (void *) GetProcAddress(DLLHandle,"xxusb_register_read"))) exit(1);
83
  if (!(xxusb_stack_read_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_stack_read"))) exit(1);
90
  if (!(xxusb_stack_read_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_stack_read"))) exit(1);
84
  if (!(xxusb_stack_write_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_stack_write"))) exit(1);
91
  if (!(xxusb_stack_write_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_stack_write"))) exit(1);
85
  if (!(xxusb_stack_execute_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_stack_execute"))) exit(1);
92
  if (!(xxusb_stack_execute_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_stack_execute"))) exit(1);
86
  if (!(xxusb_longstack_execute_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_longstack_execute"))) exit(1);
93
  if (!(xxusb_longstack_execute_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_longstack_execute"))) exit(1);
Line 118... Line 125...
118
 
125
 
119
void _VI_FUNC WIENER_VMUSB_open (const char *serial) {
126
void _VI_FUNC WIENER_VMUSB_open (const char *serial) {
120
 
127
 
121
  xxusb_device_type devices[100];
128
  xxusb_device_type devices[100];
122
  struct usb_device *dev;
129
  struct usb_device *dev;
123
  if (serial != NULL)
130
  if (serial != NULL) {
124
    WUSB_udev = xxusb_serial_open((char *) serial);
131
    WUSB_udev = xxusb_serial_open((char *) serial);
125
  else  {
132
  } else  {
126
    //Find XX_USB devices and open the first one found
133
    //Find XX_USB devices and open the first one found
127
    xxusb_devices_find(devices);
134
    xxusb_devices_find(devices);
128
    dev = devices[0].usbdev;
135
    dev = devices[0].usbdev;
129
    WUSB_udev = xxusb_device_open(dev);
136
    WUSB_udev = xxusb_device_open(dev);
130
  }
137
  }
Line 155... Line 162...
155
 
162
 
156
void WIENER_VMUSB_StackClear() {
163
void WIENER_VMUSB_StackClear() {
157
  WIENER_VMUSB_StackInit();
164
  WIENER_VMUSB_StackInit();
158
}
165
}
159
 
166
 
160
int WIENER_VMUSB_StackGetUInt16(int maxn, uint16_t *stack) {
167
int WIENER_VMUSB_StackGetUint16(int maxn, uint16_t *stack) {
161
  int i;
168
  int i;
162
  uint16_t * u16Stack = (uint16_t *) fStack;
169
  uint16_t * u16Stack = (uint16_t *) fStack;
163
  for (i=0; i< fStackSize*2; i++) {
170
  for (i=0; i< fStackSize*2; i++) {
164
    if (i<maxn) stack[i]=u16Stack[i];
171
    if (i<maxn) stack[i]=u16Stack[i];
165
    else return -1;
172
    else return -1;
166
  }
173
  }
167
  return fStackSize*2;
174
  return fStackSize*2;
168
}
175
}
169
 
176
 
170
int WIENER_VMUSB_StackGetUInt32(int maxn, uint32_t *stack) {
177
int WIENER_VMUSB_StackGetUint32(int maxn, uint32_t *stack) {
171
  int i;
178
  int i;
172
  uint16_t * u16Stack = (uint16_t *) fStack;
179
  uint16_t * u16Stack = (uint16_t *) fStack;
173
  for (i=0; i< fStackSize*2; i++) {
180
  for (i=0; i< fStackSize*2; i++) {
174
    if (i<maxn) stack[i]=u16Stack[i];
181
    if (i<maxn) stack[i]=u16Stack[i];
175
    else return -1;
182
    else return -1;
Line 219... Line 226...
219
void WIENER_VMUSB_StackPrint() {
226
void WIENER_VMUSB_StackPrint() {
220
  uint16_t * u16Stack = (uint16_t *) fStack;
227
  uint16_t * u16Stack = (uint16_t *) fStack;
221
  uint32_t i;
228
  uint32_t i;
222
  for (i=0; i < fStackSize*2; i++) printf("0x%04x\n",u16Stack[i]);
229
  for (i=0; i < fStackSize*2; i++) printf("0x%04x\n",u16Stack[i]);
223
  printf("size of stack %d __________________________________\n",fStackSize*2-1);
230
  printf("size of stack %d __________________________________\n",fStackSize*2-1);
224
}
231
}
225
 
232
 
226
 
233
 
227
char wusbcc_stack[MAXSTACKSIZE*4];
234
char wusbcc_stack[MAXSTACKSIZE*4];
228
 
235
 
229
 
236
 
230
int _VI_FUNC WUSBXX_stack_execute (usb_dev_handle * dev, char * stack) {
237
int _VI_FUNC WUSBXX_stack_execute (usb_dev_handle * dev, char * stack) {
231
  int i, nb=0;
238
  int i, nb=0;
232
  if (!dev) {
239
  if (!dev) {
233
    printf("WUSBXX_stack_execute device not open\n");
240
    printf("WUSBXX_stack_execute device not open\n");
234
    return -1;
241
    return -1;
235
  }
242
  }
236
  uint16_t * exstack = (uint16_t *) wusbcc_stack;
243
  uint16_t * exstack = (uint16_t *) wusbcc_stack;
237
  exstack[0]=0;
244
  exstack[0]=0;
238
  nb = WIENER_VMUSB_StackGetUInt16(MAXSTACKSIZE, &exstack[1] );
245
  nb = WIENER_VMUSB_StackGetUint16(MAXSTACKSIZE, &exstack[1] );
239
  //printf("WUSBXX_stack_execute stack size %d\n", nb);
246
  //printf("WUSBXX_stack_execute stack size %d\n", nb);
240
  //WIENER_VMUSB_StackPrint();
247
  //WIENER_VMUSB_StackPrint();
241
  nb = xxusb_longstack_execute (dev,  exstack, nb, 1000);
248
  nb = xxusb_longstack_execute (dev,  exstack, nb, 1000);
242
  //DataBuffer(0 - (ReturnValue/2-1)) - (unsigned short)array of returned data when ReturnValue>0
249
  //DataBuffer(0 - (ReturnValue/2-1)) - (unsigned short)array of returned data when ReturnValue>0
243
  //printf("WUSBXX_stack_execute return size %d\n", nb);
250
  //printf("WUSBXX_stack_execute return size %d\n", nb);
244
  if (nb<0 ) printf("xxusb_longstack_execute %s line:%d err=%d %s\n",__FILE__,__LINE__,nb, strerror(-nb) );
251
  if (nb<0 ) printf("xxusb_longstack_execute %s line:%d err=%d %s\n",__FILE__,__LINE__,nb, strerror(-nb) );
245
  if (stack!=NULL) for ( i=0; i<nb; i++) stack[i]=wusbcc_stack[i];
252
  if (stack!=NULL) for ( i=0; i<nb; i++) stack[i]=wusbcc_stack[i];
246
  return nb/sizeof(uint32_t);
253
  return nb/sizeof(uint32_t);
247
}
254
}
-
 
255
 
-
 
256
 
248
 
257
 
249
 
258
 
250
 
259
 
251
#ifndef VME_D32
260
#ifndef VME_D32
252
 
261