Skip to content
Snippets Groups Projects
Commit d34ce6d9 authored by tzhang74's avatar tzhang74
Browse files

initial

parents
No related branches found
No related tags found
No related merge requests found
Showing
with 1384 additions and 0 deletions
File added
File added
/* Simple program to demonstrate CC_USB in DAQ / stack mode
*
* Copyright (C) 2005-2014 WIENER, Plein & Baus, Corp.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, version 2.
*/
#include <libxxusb.h>
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <cstdlib>
#include <string.h>
int main (int argc, char *argv[])
{
int CamN, CamA, CamF;
long CamD;
//setup output file
FILE * DataFile;
DataFile = fopen("CC_Data.txt","w");
xxusb_device_type devices[100];
struct usb_device *dev;
usb_dev_handle *udev; // Device Handle
long loops, LAM;
long stack [100];
int i,j,k,k_loops, error_count=0, events=0, event_size=0;
// unsigned int IntArray [10000]; //-> produces 32 bit data structure, use only with event alignment!
short IntArray [10000]; //for FIFOREAD
// char IntArray [10000]; //for FIFOREAD
// char * ByteAP;
long data_lines;
long CamDummy;
int ret,CamQ, CamX;
int CAM_2249=3; // station number for 2249 ADC
//Find XX_USB devices and open the first one found
xxusb_devices_find(devices);
dev = devices[0].usbdev;
udev = xxusb_device_open(dev);
// Make sure CC_USB opened OK
if(!udev)
{
printf ("\n\nFailedto Open CC_USB \n\n");
return 0;
}
//Make some lights dance
printf("\n\n\nTesting data lines....");
CAMAC_Z(udev);
CAMAC_I(udev, true);
CAMAC_write(udev, 1, 0, 16, 0xaaaaaa,&CamQ, &CamX);
CAMAC_read(udev, 1, 0, 0, &CamD,&CamQ, &CamX);
CAMAC_C(udev);
CAMAC_I(udev, false);
CAMAC_Z(udev);
for (i=0; (i <= 100000); i++)
CAMAC_write(udev, 1, 0, 16, i,&CamQ, &CamX);
printf(" Done.\n\n");
//LeCroy 2249 DAQ test
// prepare stack and load to CC-USB
CamN=(CAM_2249<<9);
stack[0] = 14; // number of lines to follow
for (i=0; i<=11; i++) stack[i+1] = CamN+(i<<5)+2; // Read channels F(2) A(i)
// stack[13] = CamN+0x0009; // CLEAR LAM N()with F(9) A(0) ==> not needed with F(2)A(11)
stack[13] = 0x0010; // add marker
stack[14] = 0xffff; // marker = ffff
// Load stack into CC-USB
ret = xxusb_stack_write(udev, 2, stack);
// Define Trigger LAM=0 -> extern, otherwise LAM
ret = CAMAC_write(udev, 25,9,16,LAM,&CamQ, &CamX);
// Define Trigger Delay / LAM time out in Delay Register N(25) A(2) F(16) and enable /disable LAM
if (LAM = 0)
{
// Define Trigger Delay to 100us for external LAM; bits 0 to 15 in Delay Register N(25) A(2) F(16)
ret = CAMAC_write(udev, 25, 2, 16, 0x64,&CamQ, &CamX);
// Prepare LeCroy ADC (disable LAM)
ret = CAMAC_read(udev, CAM_2249, 0, 24, &CamDummy,&CamQ, &CamX);
}
else
{
// Define LAM time out to 100us for external LAM; bits 0 to 15 in Delay Register N(25) A(2) F(16)
ret = CAMAC_write(udev, 25, 2, 16, 0x640000,&CamQ, &CamX);
// Prepare LeCroy ADC (enable LAM)
ret = CAMAC_read(udev, CAM_2249, 0, 26, &CamDummy,&CamQ, &CamX);
}
// Set buffer size to 4k BuffOpt in Global Mode register N(25) A(1) F(16)
ret = CAMAC_write(udev, 25, 1, 16, 0x0,&CamQ, &CamX);
// Prepare data file
fprintf(DataFile,"CC-USB test data file \n");
// START DAQ
// printf("switch to DAQ & Reading data\n");
// Clear Data and LAM
ret = CAMAC_read(udev, CAM_2249, 0, 9, &CamDummy,&CamQ, &CamX);
// Start DAQ mode
ret = xxusb_register_write(udev, 1, 0x1); // start acquisition
k_loops=0;
while(k_loops<loops) // number of loops to read
{
ret = xxusb_bulk_read(udev, IntArray, 8192, 100); // use for32-bit data
data_lines = ret / 2;
event_size = (IntArray[1] & 0xffff);
if (event_size > 0x100) event_size = 0x100;
if (DataFile !=NULL)
{
if(ret>0)
{
events = (IntArray[0]& 0xffff);
// printf("Events in loop %i : %i\n ",k_loops, events);
for (j=0; j<=data_lines; j++) fprintf(DataFile,"%hx\t",IntArray[j]);
}
else
{
error_count ++;
printf("no read\n");
}
fprintf(DataFile,"\n");
}
k_loops ++;
}
// leave DAQ mode
xxusb_register_write(udev, 1, 0x0);
// drain all data from fifo
ret=1;
k=0;
while(ret>0)
{
ret = xxusb_bulk_read(udev, IntArray, 8192, 100);
if(ret>0)
{
// printf("drain loops: %i (result %i)\n ",k,ret);
k++;
if (k>100) ret=0;
}
}
// in case still DAQ mode -> leave!!!
// xxusb_register_write(hdev, 1, 0x0);
fclose(DataFile);
return 0;
// Close the Device
xxusb_device_close(udev);
printf("\n\n\n");
return 0;
}
CC-USB test data file
# basic makefile
here=$(shell pwd)
.LIBPATTERNS ="'lib%.so lib%.a' "
CXX = g++
FC = g77
F90 = f90
RM = rm -f
CC = g++
LD = g++
LDFLAGS = -O
SOFLAGS = -shared
CXXLIBDIRS = -L./../../lib/
CXXLIBS = -lxx_usb -lm -lusb -Wl,"-rpath=$(here)/../../lib"
INCLUDEDIRS = -I./../../include/
CXXFLAGS = -O -Wall -fPIC -g $(INCLUDEDIRS)
CFLAGS += $(INCLUDEDIRS) $(SOFLAG)
CFLAGS += $(CXXLIBDIRS) $(CXXLIBS)
LDFLAGS = $(CXXFLAGS)
OBJ = ./CC-DAQ2249
main:
$(CXX) $(CXXFLAGS) CC-DAQ_2249.cpp \
$(CXXLIBS) $(CXXLIBDIRS) -o $(OBJ)
@echo "Done"
clean:
$(RM) $(OBJ)
# basic makefile
.LIBPATTERNS ="'lib%.so lib%.a' "
CXX = g++
FC = g77
F90 = f90
RM = rm -f
CC = g++
LD = g++
LDFLAGS = -O
SOFLAGS = -shared
CXXLIBDIRS = -L./../../libs/
CXXLIBS = -lxx_usb -lm
INCLUDEDIRS = -I./../../include/
CXXFLAGS = -O -Wall -fPIC -g $(INCLUDEDIRS)
CFLAGS += $(INCLUDEDIRS) $(SOFLAG)
CFLAGS += $(CXXLIBDIRS) $(CXXLIBS)
LDFLAGS = $(CXXFLAGS)
OBJ = ./CC-DAQ_2249
main:
$(CXX) $(CXXFLAGS) \
$(CXXLIBS) $(CXXLIBDIRS) -o $(OBJ) CC-DAQ_2249.cpp
@echo "Done"
clean:
$(RM) $(OBJ)
# basic makefile
.LIBPATTERNS ="'lib%.so lib%.a' "
CXX = g++
FC = g77
F90 = f90
RM = rm -f
CC = g++
LD = g++
LDFLAGS = -O
SOFLAGS = -shared
CXXLIBDIRS = -L./../../libs/
CXXLIBS = -lxx_usb -lm
INCLUDEDIRS = -I./../../include/
CXXFLAGS = -O -Wall -fPIC -g $(INCLUDEDIRS)
CFLAGS += $(INCLUDEDIRS) $(SOFLAG)
CFLAGS += $(CXXLIBDIRS) $(CXXLIBS)
LDFLAGS = $(CXXFLAGS)
OBJ = ./CC-DAQ_2249
main:
$(CXX) $(CXXFLAGS) \
$(CXXLIBS) $(CXXLIBDIRS) -o $(OBJ) CC-DAQ_2249.cpp
@echo "Done"
clean:
$(RM) $(OBJ)
/* Simple program to demonstrate CC-USB
*
* Copyright (C) 2005-2014 WIENER, Plein & Baus, Corp
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, version 2.
*
*
*
*
*/
#include <libxxusb.h>
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <cstdlib>
#include <string.h>
int main (int argc, char *argv[])
{
int CamN, CamA, CamF;
long CamD;
int CamQ, CamX;
char nafin[20];
char nafinx[20];
int WriteMode;
int ret, i;
xxusb_device_type devices[100];
struct usb_device *dev;
usb_dev_handle *udev; // Device Handle
//Find XX_USB devices and open the first one found
xxusb_devices_find(devices);
dev = devices[0].usbdev;
udev = xxusb_device_open(dev);
// Make sure CC_USB opened OK
if(!udev)
{
printf ("\n\nFailedto Open CC_USB \n\n");
return 0;
}
//Make some lights dance
printf("\n\n\nTesting data lines....");
CAMAC_Z(udev);
CAMAC_I(udev, true);
CAMAC_write(udev, 1, 0, 16, 0xaaaaaa,&CamQ, &CamX);
CAMAC_read(udev, 1, 0, 0, &CamD,&CamQ, &CamX);
CAMAC_C(udev);
CAMAC_I(udev, false);
CAMAC_Z(udev);
for (i=0; (i <= 100000); i++)
CAMAC_write(udev, 1, 0, 16, i,&CamQ, &CamX);
printf(" Done.\n\n");
strcpy(nafin,"5,5,0");
sscanf(nafin,"%i,%i,%i",&CamN,&CamA,&CamF);
while (CamN>0)
{
printf(" N,A,F (Comma-separated; x for exit; p for NAF=%i,%i,%i) -> ",CamN, CamA, CamF);
fflush(stdin);
scanf("%s",&nafinx);
if (nafinx[0]=='X' || nafinx[0]=='x')
{
break;
}
if (strlen(nafinx)>4)
strcpy(&nafin[0], &nafinx[0]);
sscanf(nafin,"%i,%i,%i",&CamN,&CamA,&CamF);
fflush(stdin);
if (CamF < 8)
{
ret = CAMAC_read(udev, CamN, CamA, CamF, &CamD,&CamQ, &CamX);
if (ret < 0)
printf("Read Operation Failed\n");
else
printf("\n X = %i, Q = %i, D = %lx\n\n",CamX, CamQ, CamD);
}
if ((CamF > 7) && (CamF < 16))
{
ret = CAMAC_read(udev, CamN, CamA, CamF, &CamD,&CamQ, &CamX);
if (ret < 0)
printf("Write Operation Failed\n");
else
printf("\n X = %i, Q = %i\n\n",CamX, CamQ);
}
if ((CamF > 15) && (CamF < 24))
{
WriteMode=1;
printf(" D (Use 0x Prefix for Hexadecimal)-> ");
scanf("%li", &CamD);
fflush(stdin);
CAMAC_write(udev, CamN, CamA, CamF, CamD,&CamQ, &CamX);
}
}
// Close the Device
xxusb_device_close(udev);
printf("\n\n\n");
return 0;
}
/* Simple program to demonstrate VM_USB in multiple stack mode
*
* Copyright (C) 2005-2009 WIENER, Plein & Baus, Ltd (thoagland@wiener-us.com)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, version 2.
*
*
*
* This program file is an example of how to write two seperate stacks
* to the VM_USB and execute them on different triggers. To do this the
* WIENER VDIS module is used.
*
*/
#include <libxxusb.h>
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <cstdlib>
#include <string.h>
// Base address of VDIS
#define BA 0x8800
int main (int argc, char *argv[])
{
int CamN, CamA, CamF;
long CamD;
int CamQ, CamX;
char nafin[20];
char nafinx[20];
int WriteMode;
int ret, i;
xxusb_device_type devices[100];
struct usb_device *dev;
usb_dev_handle *udev; // Device Handle
//Find XX_USB devices and open the first one found
xxusb_devices_find(devices);
dev = devices[0].usbdev;
udev = xxusb_device_open(dev);
// Make sure VM_USB opened OK
if(!udev)
{
printf ("\n\nFailedto Open VM_USB \n\n");
return 0;
}
//Make some lights dance
printf("\n\n\nTesting data lines....");
CAMAC_Z(udev);
CAMAC_I(udev, true);
CAMAC_write(udev, 1, 0, 16, 0xaaaaaa,&CamQ, &CamX);
CAMAC_read(udev, 1, 0, 0, &CamD,&CamQ, &CamX);
CAMAC_C(udev);
CAMAC_I(udev, false);
CAMAC_Z(udev);
for (i=0; (i <= 100000); i++)
CAMAC_write(udev, 1, 0, 16, i,&CamQ, &CamX);
printf(" Done.\n\n");
strcpy(nafin,"5,5,0");
sscanf(nafin,"%i,%i,%i",&CamN,&CamA,&CamF);
while (CamN>0)
{
printf(" N,A,F (Comma-separated; x for exit; p for NAF=%i,%i,%i) -> ",CamN, CamA, CamF);
fflush(stdin);
scanf("%s",&nafinx);
if (nafinx[0]=='X' || nafinx[0]=='x')
{
break;
}
if (strlen(nafinx)>4)
strcpy(&nafin[0], &nafinx[0]);
sscanf(nafin,"%i,%i,%i",&CamN,&CamA,&CamF);
fflush(stdin);
if (CamF < 8)
{
ret = CAMAC_read(udev, CamN, CamA, CamF, &CamD,&CamQ, &CamX);
if (ret < 0)
printf("Read Operation Failed\n");
else
printf("\n X = %i, Q = %i, D = %lx\n\n",CamX, CamQ, CamD);
}
if ((CamF > 7) && (CamF < 16))
{
ret = CAMAC_read(udev, CamN, CamA, CamF, &CamD,&CamQ, &CamX);
if (ret < 0)
printf("Write Operation Failed\n");
else
printf("\n X = %i, Q = %i\n\n",CamX, CamQ);
}
if ((CamF > 15) && (CamF < 24))
{
WriteMode=1;
printf(" D (Use 0x Prefix for Hexadecimal)-> ");
scanf("%li", &CamD);
fflush(stdin);
CAMAC_write(udev, CamN, CamA, CamF, CamD,&CamQ, &CamX);
}
}
// Close the Device
xxusb_device_close(udev);
printf("\n\n\n");
return 0;
}
File added
# basic makefile
here=$(shell pwd)
.LIBPATTERNS ="'lib%.so lib%.a' "
CXX = g++
FC = g77
F90 = f90
RM = rm -f
CC = g++
LD = g++
LDFLAGS = -O
SOFLAGS = -shared
CXXLIBDIRS = -L./../../lib/
CXXLIBS = -lxx_usb -lm -lusb -Wl,"-rpath=$(here)/../../lib"
INCLUDEDIRS = -I./../../include/
CXXFLAGS = -O -Wall -fPIC -g $(INCLUDEDIRS)
CFLAGS += $(INCLUDEDIRS) $(SOFLAG)
CFLAGS += $(CXXLIBDIRS) $(CXXLIBS)
LDFLAGS = $(CXXFLAGS)
OBJ = ./CC_demo
main:
$(CXX) $(CXXFLAGS) CC-USB_demo.cpp \
$(CXXLIBS) $(CXXLIBDIRS) -o $(OBJ)
@echo "Done"
clean:
$(RM) $(OBJ)
# basic makefile
.LIBPATTERNS ="'lib%.so lib%.a' "
CXX = g++
FC = g77
F90 = f90
RM = rm -f
CC = g++
LD = g++
LDFLAGS = -O
SOFLAGS = -shared
CXXLIBDIRS = -L./../../libs/
CXXLIBS = -lxx_usb -lm
INCLUDEDIRS = -I./../../include/
CXXFLAGS = -O -Wall -fPIC -g $(INCLUDEDIRS)
CFLAGS += $(INCLUDEDIRS) $(SOFLAG)
CFLAGS += $(CXXLIBDIRS) $(CXXLIBS)
LDFLAGS = $(CXXFLAGS)
OBJ = ./CC_demo
main:
$(CXX) $(CXXFLAGS) \
$(CXXLIBS) $(CXXLIBDIRS) -o $(OBJ) CC-USB_demo.cpp
@echo "Done"
clean:
$(RM) $(OBJ)
# basic makefile
here=$(shell pwd)
.LIBPATTERNS ="'lib%.so lib%.a' "
CXX = g++
FC = g77
F90 = f90
RM = rm -f
CC = g++
LD = g++
LDFLAGS = -O
SOFLAGS = -shared
CXXLIBDIRS = -L./../../lib/
CXXLIBS = -lxx_usb -lm -lusb -Wl,"-rpath=$(here)/../../lib"
INCLUDEDIRS = -I./../../include/
CXXFLAGS = -O -Wall -fPIC -g $(INCLUDEDIRS)
CFLAGS += $(INCLUDEDIRS) $(SOFLAG)
CFLAGS += $(CXXLIBDIRS) $(CXXLIBS)
LDFLAGS = $(CXXFLAGS)
OBJ = ./CC-DAQ2249
main:
$(CXX) $(CXXFLAGS) CC-DAQ_2249.cpp \
$(CXXLIBS) $(CXXLIBDIRS) -o $(OBJ)
@echo "Done"
clean:
$(RM) $(OBJ)
# basic makefile
.LIBPATTERNS ="'lib%.so lib%.a' "
CXX = g++
FC = g77
F90 = f90
RM = rm -f
CC = g++
LD = g++
LDFLAGS = -O
SOFLAGS = -shared
CXXLIBDIRS = -L./../../libs/
CXXLIBS = -lxx_usb -lm
INCLUDEDIRS = -I./../../include/
CXXFLAGS = -O -Wall -fPIC -g $(INCLUDEDIRS)
CFLAGS += $(INCLUDEDIRS) $(SOFLAG)
CFLAGS += $(CXXLIBDIRS) $(CXXLIBS)
LDFLAGS = $(CXXFLAGS)
OBJ = ./IRQ
main:
$(CXX) $(CXXFLAGS) \
$(CXXLIBS) $(CXXLIBDIRS) -o $(OBJ) VDIS_IRQ_test_001.cpp
@echo "Done"
clean:
$(RM) $(OBJ)
/* Simple VM_USB program
*
* Copyright (C) 2005-2009 WIENER, Plein & Baus, Ltd (thoagland@wiener-us.com)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, version 2.
*
*
*
* This file will show the basic principles of using the xx_usb
* Library. It is offerered as a simple version idea of how to:
* Open the Device
* Set up the LEDs
* Set up a DGG
* Close the Device
* In order for it to work be sure to change the serial number
* To that of your VM_USB.
*
include <libxxusb.h>
#include <stdio.h>
*/
#include <libxxusb.h>
#include <stdio.h>
#include <time.h>
#include <math.h>
#define V785_BA 0x00400000
#define V785_FIRMWARE_ID 0x1000
#define V785_SERIAL_MSB 0x8F02
#define V785_SERIAL_LSB 0x8F06
#define V785_IRQ_LEVEL 0x100A
#define V785_IRQ_VECTOR 0x100C
#define V785_EVENT_TRIGGER 0x1020
int main (int argc, char *argv[])
{
int ret, j;
//int *Data_Array=malloc(1000);
long Data=0;
xxusb_device_type devices[100];
struct usb_device *dev;
usb_dev_handle *udev; // Device Handle
long Stack[6];
Stack[0] = 0x0005;
Stack[1] = 0;
Stack[2] = 0x010B;
Stack[3] = 0x2200;
Stack[4] = 0;
Stack[5] = 0x0040;
long Stack_read [10];
//setup output file
FILE * DataFile;
DataFile = fopen("VHQ_Info.txt","w");
//Find XX_USB devices and open the first one found
xxusb_devices_find(devices);
dev = devices[0].usbdev;
udev = xxusb_device_open(dev);
// Make sure VM_USB opened OK
if(!udev)
{
printf ("\n\nFailedto Open VM_USB \n\n");
return 0;
}
// Set Red LED to light with NIM1
VME_LED_settings(udev, 1,1,0,0);
// Set DGG channel B to trigger on NIM1, output on O2,
// with delay =500 x 12.5ns,
// and width = 500 x 12.5ns,
// not latching or inverting
VME_DGG(udev,0,2,0,0,0x200,0,0);
//Read the Firmware ID of the V785
VME_read_16(udev, 0x9, V785_BA+V785_FIRMWARE_ID, &Data );
printf("\n\nV785 Firmware Revision: %lx", Data);
//Get V785 serial Number
ret=VME_read_16(udev, 0x9, V785_BA+V785_SERIAL_LSB, &Data );
printf("\nV785 Serial Number: %li", (Data & 0xFFF));
//Set IRQ Level 1
VME_write_16(udev, 0x9, V785_BA+V785_IRQ_LEVEL, 0x2);
//Set IRQ Vector 0XAB
VME_write_16(udev, 0x9, V785_BA+V785_IRQ_VECTOR, 0xAB);
//Set Event trigger to 8 events
VME_write_16(udev, 0x9, V785_BA+V785_EVENT_TRIGGER, 0x8);
VME_register_write(udev, 0x28, 0x22AB);
// Write Stack to VM_USb
xxusb_stack_write(udev, 0x10, Stack);
// Read Stack back from VM_USB and Display
printf("\n\n\nStack Read from Module\n");
xxusb_stack_read(udev,0x10, Stack_read);
for(j=0;j<6;j++)
{
printf("%lx\n", Stack_read[j]);
}
printf("\n\n");
VME_register_read(udev, 0x4, &Data);
//Data = Data & 0xFFFFFF00;
Data = Data | 0x01;
VME_register_write(udev, 0x4, Data);
int k=0;
int l=0;
int* Data_Array=malloc(1000);
xxusb_register_write(udev,1,0x1); // Start DAQ mode
//poll Fifo 10 times
while(k <10)
{
ret=xxusb_usbfifo_read(udev, Data_Array,8192,30);
if(ret>0)
{
for(l=0;l<8192;l++)
fprintf(DataFile, "%x\n",Data_Array[l]);
} else {
printf("no data: %i\n", ret);
}
k++;
}
xxusb_register_write(udev,1,0x0); // stop acquistion
// read from fifo until Time out error and discard all data
ret = xxusb_usbfifo_read(udev, Data_Array, 8192, 30);
while(ret >0)
{
ret = xxusb_usbfifo_read(udev, Data_Array, 8192, 30);
//printf("drain Buffer\n");
}
printf("Buffer Empty\n");
// Close the Device
xxusb_device_close(udev);
printf("\n\n\n");
return 0;
}
/* Simple VM_USB program
*
* Copyright (C) 2005-2009 WIENER, Plein & Baus, Ltd (thoagland@wiener-us.com)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, version 2.
*
*
*
* This file will show the basic principles of using the xx_usb
* Library. It is offerered as a simple version idea of how to:
* Open the Device
* Set up the LEDs
* Set up a DGG
* Close the Device
* In order for it to work be sure to change the serial number
* To that of your VM_USB.
*
include <libxxusb.h>
#include <stdio.h>
*/
#include <libxxusb.h>
#include <stdio.h>
#include <time.h>
#include <math.h>
#define BA 0x8800
int main (int argc, char *argv[])
{
int ret, j;
//int *Data_Array=malloc(1000);
long Data=0;
xxusb_device_type devices[100];
struct usb_device *dev;
usb_dev_handle *udev; // Device Handle
long Stack[8];
Stack[0] = 0x0007;
Stack[1] = 0;
Stack[2] = 0x0029;
Stack[3] = 0x00;
Stack[4] = 0x8820;
Stack[5] = 0x0000;
Stack[6] = 0x0002;
Stack[7] = 0x0000;
long Stack_read [10];
//setup output file
FILE * DataFile;
DataFile = fopen("VHQ_Info.txt","w");
//Find XX_USB devices and open the first one found
xxusb_devices_find(devices);
dev = devices[0].usbdev;
udev = xxusb_device_open(dev);
// Make sure VM_USB opened OK
if(!udev)
{
printf ("\n\nFailedto Open VM_USB \n\n");
return 0;
}
VME_read_16(udev, 0x29, BA, &Data);
printf("\n\nStatus Register = 0x%lx", Data);
VME_write_16(udev, 0x29, BA+0x10, 0x2BB);
// Write Stack to VM_USb
xxusb_stack_write(udev, 0x2, Stack);
// Read Stack back from VM_USB and Display
printf("\n\n\nStack Read from Module\n");
xxusb_stack_read(udev,0x02, Stack_read);
for(j=0;j<8;j++)
{
printf("%lx\n", Stack_read[j]);
}
printf("\n\n");
VME_register_read(udev, 0x4, &Data);
//Data = Data & 0xFFFFFF00;
Data = Data | 0x01;
VME_register_write(udev, 0x4, Data);
//int* Data_Array=malloc(1000);
VME_register_write(udev, 0x28, 0x02BB);
xxusb_register_write(udev,1,0x1); // Start DAQ mode
char key;
/*
//poll Fifo 10 times
while(key !="q")
{
ret=xxusb_usbfifo_read(udev, Data_Array,8192,30);
if(ret>0)
{
for(l=0;l<8192;l++)
fprintf(DataFile, "%x\n",Data_Array[l]);
} else {
printf("no data: %i\n", ret);
}
printf(" %c ", key);
key=getchar();
}
printf("\n\nExited Loop\n");
*/
key= getchar();
printf("\nstopping DAQ");
xxusb_register_write(udev,1,0x0); // stop acquistion
/*
// read from fifo until Time out error and discard all data
ret = xxusb_usbfifo_read(udev, Data_Array, 8192, 30);
while(ret >0)
{
ret = xxusb_usbfifo_read(udev, Data_Array, 8192, 30);
//printf("drain Buffer\n");
}
printf("Buffer Empty\n");
*/
// Close the Device
xxusb_device_close(udev);
printf("\n\n\n");
return 0;
}
/* Simple VM_USB program
*
* Copyright (C) 2005-2009 WIENER, Plein & Baus, Ltd (thoagland@wiener-us.com)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, version 2.
*
*
*
* This file will show the basic principles of using the xx_usb
* Library. It is offerered as a simple version idea of how to:
* Open the Device
* Set up the LEDs
* Set up a DGG
* Close the Device
* In order for it to work be sure to change the serial number
* To that of your VM_USB.
*
include <libxxusb.h>
#include <stdio.h>
*/
#include <libxxusb.h>
#include <stdio.h>
#include <time.h>
#include <math.h>
#define BA 0x8800
int main (int argc, char *argv[])
{
int ret, j;
//int *Data_Array=malloc(1000);
long Data=0;
xxusb_device_type devices[100];
struct usb_device *dev;
usb_dev_handle *udev; // Device Handle
long IRQ_Stack[8];
IRQ_Stack[0] = 0x0007;
IRQ_Stack[1] = 0;
IRQ_Stack[2] = 0x0029;
IRQ_Stack[3] = 0x00;
IRQ_Stack[4] = 0x8820;
IRQ_Stack[5] = 0x0000;
IRQ_Stack[6] = 0x0002;
IRQ_Stack[7] = 0x0000;
long Trigger_Stack[12];
Trigger_Stack[0] = 0x000B;
Trigger_Stack[1] = 32;
Trigger_Stack[2] = 0x0029;
Trigger_Stack[3] = 0x00;
Trigger_Stack[4] = 0x8820;
Trigger_Stack[5] = 0x0000;
Trigger_Stack[6] = 0x0001;
Trigger_Stack[7] = 0x0000;
Trigger_Stack[8] = 0x0129;
Trigger_Stack[9] = 0x0000;
Trigger_Stack[10] = 0x8830;
Trigger_Stack[11] = 0x0000;
long Stack_read [12];
//setup output file
FILE * DataFile;
DataFile = fopen("VHQ_Info.txt","w");
//Find XX_USB devices and open the first one found
xxusb_devices_find(devices);
dev = devices[0].usbdev;
udev = xxusb_device_open(dev);
// Make sure VM_USB opened OK
if(!udev)
{
printf ("\n\nFailedto Open VM_USB \n\n");
return 0;
}
VME_register_read(udev, 0x0, &Data);
printf("\n\nFirmware_revision = %lx", (Data & 0xFFFF));
VME_read_16(udev, 0x29, BA, &Data);
printf("\n\nStatus Register = 0x%lx", Data);
VME_write_16(udev, 0x29, BA+0x10, 0x1BB);
// Set Red LED to light with NIM1
VME_LED_settings(udev, 1,1,0,0);
// Write IRQ Stack to VM_USB
xxusb_stack_write(udev, 18, IRQ_Stack);
VME_register_write(udev, 0x28, 0x21BB);
// Write trigger Stack to VM_USB
xxusb_stack_write(udev, 0x2, Trigger_Stack);
VME_register_write(udev, 0x2C, 0x000);
// Read Stack back from VM_USB and Display
printf("\n\n\nStack Read from Module\n");
xxusb_stack_read(udev,18, Stack_read);
for(j=0;j<8;j++)
{
printf("%lx\n", Stack_read[j]);
}
printf("\n\n");
// Read Stack back from VM_USB and Display
printf("\n\n\nStack Read from Module\n");
xxusb_stack_read(udev,0x2, Stack_read);
for(j=0;j<12;j++)
{
printf("%lx\n", Stack_read[j]);
}
printf("\n\n");
VME_register_read(udev, 0x4, &Data);
//Data = Data & 0xFFFFFF00;
Data = Data | VME_register_read(udev, 0x4, &Data);0x01;
VME_register_write(udev, 0x4, Data);
int* Data_Array=malloc(1000);
xxusb_register_write(udev,1,0x1); // Start DAQ mode
int key =0;
//poll Fifo 10 times
while(key <1000000)
{
ret=xxusb_usbfifo_read(udev, Data_Array,8192,30);
key++;
}
printf("\n\nExited Loop\n");
xxusb_register_write(udev,1,0x0); // stop acquistion
// read from fifo until Time out error and discard all data
ret = xxusb_usbfifo_read(udev, Data_Array, 8192, 30);
while(ret >0)
{
ret = xxusb_usbfifo_read(udev, Data_Array, 8192, 30);
//printf("drain Buffer\n");
}
printf("Buffer Empty\n");
// Close the Device
xxusb_device_close(udev);
printf("\n\n\n");
return 0;
}
/* Simple program to demonstrate VM_USB in multiple stack mode
*
* Copyright (C) 2005-2009 WIENER, Plein & Baus, Ltd (thoagland@wiener-us.com)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, version 2.
*
*
*
* This program file is an example of how to write two seperate stacks
* to the VM_USB and execute them on different triggers. To do this the
* WIENER VDIS module is used.
*
*/
#include <libxxusb.h>
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <cstdlib>
// Base address of VDIS
#define BA 0x8800
int main (int argc, char *argv[])
{
int ret, j;
long Data=0;
xxusb_device_type devices[100];
struct usb_device *dev;
usb_dev_handle *udev; // Device Handle
//This is the stack that executes on IRQ. It simply clear the interupt.
long IRQ_Stack[8];
IRQ_Stack[0] = 0x0007;
IRQ_Stack[1] = 0;
IRQ_Stack[2] = 0x0029;
IRQ_Stack[3] = 0x00;
IRQ_Stack[4] = 0x8820;
IRQ_Stack[5] = 0x0000;
IRQ_Stack[6] = 0x0002;
IRQ_Stack[7] = 0x0000;
//This is the stack that executes on I1. It simply sets the interupt.
long Trigger_Stack[8];
Trigger_Stack[0] = 0x000B;
Trigger_Stack[1] = 32;
Trigger_Stack[2] = 0x0029;
Trigger_Stack[3] = 0x00;
Trigger_Stack[4] = 0x8820;
Trigger_Stack[5] = 0x0000;
Trigger_Stack[6] = 0x0001;
Trigger_Stack[7] = 0x0000;
//This array stores the Stack values read back from the VM_USB
long Stack_read [12];
//Find XX_USB devices and open the first one found
xxusb_devices_find(devices);
dev = devices[0].usbdev;
udev = xxusb_device_open(dev);
// Make sure VM_USB opened OK
if(!udev)
{
printf ("\n\nFailedto Open VM_USB \n\n");
return 0;
}
//Read VM_USB Firmware Register
VME_register_read(udev, 0x0, &Data);
printf("\n\nFirmware_revision = %lx", (Data & 0xFFFF));
//Read the status/control register of the VDIS
VME_read_16(udev, 0x29, BA, &Data);
printf("\nStatus Register = 0x%lx", Data);
//Set the interupt vectot and interupt level information for the VDIS
VME_write_16(udev, 0x29, BA+0x10, 0x1BB);
// Set Red LED to light with NIM1
VME_LED_settings(udev, 1,1,0,0);
// Write IRQ Stack to VM_USB
xxusb_stack_write(udev, 18, IRQ_Stack);
VME_register_write(udev, 0x28, 0x21BB);
// Write trigger Stack to VM_USB
xxusb_stack_write(udev, 0x2, Trigger_Stack);
VME_register_write(udev, 0x2C, 0x000);
// Read IRQ Stack back from VM_USB and Display
printf("\n\n\nStack Read from Module\n");
xxusb_stack_read(udev,18, Stack_read);
for(j=0;j<8;j++)
{
printf("%lx\n", Stack_read[j]);
}
printf("\n\n");
// Read trigger Stack back from VM_USB and Display
printf("\n\n\nStack Read from Module\n");
xxusb_stack_read(udev,0x2, Stack_read);
for(j=0;j<8;j++)
{
printf("%lx\n", Stack_read[j]);
}
printf("\n\n");
//Set Buffer information for the VM_USB readout buffer
VME_register_read(udev, 0x4, &Data);
Data = Data | VME_register_read(udev, 0x4, &Data);
VME_register_write(udev, 0x4, Data);
//Data Array for the VM_USB data to be stored in
int* Data_Array=new int[1000];
// Start DAQ mode
xxusb_register_write(udev,1,0x1);
// poll the fifo 100000 times, Data will be sent to buffer even though
// we don't read anything out. Every time a stack executes a header
// and EOB word is written to the buffer. We simply empty the buffer.
int key =0;
while(key <1000000)
{
ret=xxusb_usbfifo_read(udev, Data_Array,8192,30);
key++;
}
printf("\n\nExited Loop\n");
// stop acquistion
xxusb_register_write(udev,1,0x0);
// read from fifo until Time out error and discard all data
ret = xxusb_usbfifo_read(udev, Data_Array, 8192, 30);
while(ret >0)
ret = xxusb_usbfifo_read(udev, Data_Array, 8192, 30);
// Close the Device
xxusb_device_close(udev);
printf("\n\n\n");
return 0;
}
# basic makefile
here=$(shell pwd)
.LIBPATTERNS ="'lib%.so lib%.a' "
CXX = gcc
FC = g77
F90 = f90
RM = rm -f
CC = g++
LD = gcc
LDFLAGS = -O
SOFLAGS = -shared
CXXLIBDIRS = -L./../../lib/
CXXLIBS = -lxx_usb -lm -lusb -Wl,"-rpath=$(here)/../../lib"
INCLUDEDIRS = -I./../../include/
CXXFLAGS = -O -Wall -fPIC -g $(INCLUDEDIRS)
CFLAGS += $(INCLUDEDIRS) $(SOFLAG)
CFLAGS += $(CXXLIBDIRS) $(CXXLIBS)
LDFLAGS = $(CXXFLAGS)
OBJ = ./vmereset
main:
$(CXX) $(CXXFLAGS) VM-USB_reset.c \
$(CXXLIBS) $(CXXLIBDIRS) -o $(OBJ)
@echo "Done"
clean:
$(RM) $(OBJ)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment