Subversion Repositories f9daq

Compare Revisions

Ignore whitespace Rev 99 → Rev 100

/cvi/instr/WUSBVME_DLL/wusbvme_dll.c
1,21 → 1,82
#ifdef LINUX
#include <dlfcn.h>
#define LoadLibrary(x) dlopen( (x), RTLD_NOW );
#define GetProcAddress(x,y) dlsym((x),(y))
#define __stdcall
#define UCHAR unsigned char
#define HINSTANCE void *
#define _VI_FUNC
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#endif
 
#include "wusbvme_dll.h"
 
 
usb_dev_handle *WUSB_udev;
 
static HINSTANCE DLLHandle;
 
void _VI_FUNC WIENER_VMUSB_load (char* module_path)
 
short __stdcall WIENER_VMUSB_VME_R( uint16_t AM, uint16_t DW, uint32_t VME_Address, uint32_t *Data);
 
short __stdcall WIENER_VMUSB_VME_W( uint16_t AM, uint16_t DW, uint32_t VME_Address, uint32_t Data);
 
short __stdcall WIENER_VMUSB_VME_MW( uint16_t AM, uint16_t DW, uint32_t VME_Address, uint32_t Data);
short __stdcall WIENER_VMUSB_VME_MWRST( void );
short __stdcall WIENER_VMUSB_VME_MWEXEC( void );
 
short __stdcall WIENER_VMUSB_VME_MR( uint16_t AM, uint16_t DW, uint32_t VME_Address, uint32_t *Data);
short __stdcall WIENER_VMUSB_VME_MRRST( void );
short __stdcall WIENER_VMUSB_VME_MREXEC( uint32_t *Data );
 
 
short __stdcall xxusb_register_read(usb_dev_handle *hDev, short RegAddr, long *RegData);
short __stdcall xxusb_stack_read(usb_dev_handle *hDev, short StackAddr, long *StackData);
short __stdcall xxusb_stack_write(usb_dev_handle *hDev, short StackAddr, long *StackData);
short __stdcall xxusb_stack_execute(usb_dev_handle *hDev, long *StackData);
short __stdcall xxusb_longstack_execute(usb_dev_handle *hDev, void *DataBuffer, int lDataLen, int timeout);
short __stdcall xxusb_register_write(usb_dev_handle *hDev, short RegAddr, long RegData);
short __stdcall xxusb_usbfifo_read(usb_dev_handle *hDev, long *DataBuffer, short lDataLen, int timeout);
short __stdcall xxusb_bulk_read(usb_dev_handle *hDev, char *DataBuffer, short lDataLen, int timeout);
short __stdcall xxusb_bulk_write(usb_dev_handle *hDev, char *DataBuffer, short lDataLen, int timeout);
short __stdcall xxusb_reset_toggle(usb_dev_handle *hDev);
 
short __stdcall xxusb_devices_find(xxusb_device_type *xxusbDev);
short __stdcall xxusb_device_close(usb_dev_handle *hDev);
usb_dev_handle* __stdcall xxusb_device_open(struct usb_device *dev);
short __stdcall xxusb_flash_program(usb_dev_handle *hDev, char *config, short nsect);
short __stdcall xxusb_flashblock_program(usb_dev_handle *hDev, UCHAR *config);
usb_dev_handle* __stdcall xxusb_serial_open(char *SerialString);
 
short __stdcall VME_register_write(usb_dev_handle *hdev, long VME_Address, long Data);
short __stdcall VME_register_read(usb_dev_handle *hdev, long VME_Address, long *Data);
short __stdcall VME_LED_settings(usb_dev_handle *hdev, int LED, int code, int invert, int latch);
 
short __stdcall VME_DGG(usb_dev_handle *hdev, unsigned short channel, unsigned short trigger,unsigned short output, long delay, unsigned short gate, unsigned short invert, unsigned short latch);
 
short __stdcall VME_Output_settings(usb_dev_handle *hdev, int Channel, int code, int invert, int latch);
 
short __stdcall VME_read_16(usb_dev_handle *hdev,short Address_Modifier, long VME_Address, long *Data);
short __stdcall VME_read_32(usb_dev_handle *hdev, short Address_Modifier, long VME_Address, long *Data);
short __stdcall VME_BLT_read_32(usb_dev_handle *hdev, short Address_Modifier, int count, long VME_Address, long Data[]);
short __stdcall VME_write_16(usb_dev_handle *hdev, short Address_Modifier, long VME_Address, long Data);
short __stdcall VME_write_32(usb_dev_handle *hdev, short Address_Modifier, long VME_Address, long Data);
 
 
void _VI_FUNC WIENER_VMUSB_load (const char* module_path)
{
if (module_path == NULL)
if (module_path == NULL) {
DLLHandle = LoadLibrary("libxxusb.dll");
else
} else {
DLLHandle = LoadLibrary(module_path);
}
if (!DLLHandle) {
printf ("\n\nFailed to Open libxxusb.dll \n");
return;
return;
}
if (!(xxusb_register_read_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_register_read"))) exit(1);
if (!(xxusb_register_read_Ptr = (void *) GetProcAddress(DLLHandle,"xxusb_register_read"))) exit(1);
if (!(xxusb_stack_read_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_stack_read"))) exit(1);
if (!(xxusb_stack_write_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_stack_write"))) exit(1);
if (!(xxusb_stack_execute_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_stack_execute"))) exit(1);
44,13 → 105,13
if (!(VME_write_32_Ptr = (void*) GetProcAddress(DLLHandle,"VME_write_32"))) exit(1);
}
 
void _VI_FUNC WIENER_VMUSB_open (char *serial)
void _VI_FUNC WIENER_VMUSB_open (const char *serial)
{
xxusb_device_type devices[100];
struct usb_device *dev;
if (serial != NULL)
WUSB_udev = xxusb_serial_open(serial);
WUSB_udev = xxusb_serial_open((char *) serial);
else {
//Find XX_USB devices and open the first one found
xxusb_devices_find(devices);
189,10 → 250,10
if (!WUSB_udev) return -222;
switch (DW){
case VME_D16: nb= VME_read_16(WUSB_udev, AM,VME_Address,Data); break;
case VME_D32: nb= VME_read_32(WUSB_udev, AM,VME_Address,Data); break;
default: return 0;
}
case VME_D16: nb= VME_read_16(WUSB_udev, AM,VME_Address,(long int *) Data); break;
case VME_D32: nb= VME_read_32(WUSB_udev, AM,VME_Address,(long int *)Data); break;
default: return 0;
}
//printf("R 0x%02x 0x%02x 0x%08x %x\n", AM , DW, VME_Address, *Data);
if (nb<0) printf("%s %d %d %s\n",__FILE__,__LINE__,nb, strerror(-nb) );