//This file was written by Jay Dolan at ACCES and it can be freely distributed. //The only request made by ACCES is that any resulting application interact //with ACCES hardware in some way // if you have any questions, bug reports or fixes please email // jdolan AT accesio.com or tech AT accesio.com #include #include "/usr/include/usb.h" #define ACCES_VENDOR_ID 0x1605 #define USB_DIO_32_ID_DEV 0x8001 #define USB_DA12_8A_REVA_DEV 0xC001 #define USB_DA12_8A_DEV 0xC002 #define USB_IIRO_16_DEV 0x8010 #define USB_CTR_15_DEV 0x8020 #define USB_IIRO4_2SM_DEV 0x8030 #define MAX_USB_DEVICES 32 //This struct is used for the device_array. hdev and pdev are used //internally by the library and should not be accessed directly by //user programs. // product_id, dio_bytes, and ctr_blocks are also used internally // but reading their values may be useful typedef struct { usb_dev_handle *hdev; __u16 product_id; struct usb_device *pdev; int dio_bytes, ctr_blocks; }acces_usb_descriptor, *pacces_usb_descriptor; static acces_usb_descriptor device_array[MAX_USB_DEVICES]; //This closes the device at the specified index. After this is called any other //attempts to use the device index in other functions should cause an error value //to be returned void aiousb_close_device(int device_index); //This will load and mode the specified count. if read_value is not null it will be filled with the //read value int aiousb_ctr_read_mode_load(int device_index, int block_index, int ctr_index, int mode, int load_value, __u16 *read_value); int aiousb_ctr_read(int device_index, int block_index, int ctr_index, __u16 *read_value); //This will set the mode of the specified counter int aiousb_ctr_mode(int device_index, int block_index, int ctr_index, int mode); //For the dio functions *data needs to point to a value at least 4 bytes long //if it does not a seg fault will probably occur //This amount may go up later if ACCES builds a card that does more than 4 bytes dio in a single //transaction //These functions are also used with the IIRO boards, but dio_configure will have no effect int aiousb_dio_read(int device_index, void *data); int aiousb_dio_write(int device_index, void *data); int aiousb_dio_configure(int device_index, int tristate, unsigned char config_byte, void *data); //finds any programmed ACCES USB devices and fills the entries //in the device_array for the ones that were found // returns the number of devices found int aiousb_get_devices(); //this will attempt to open the specified devices and claim the interface. //if it fails to claim the interface it will immedietely close the device. // valid values for device_index are the 0 to the return value of aiousb_get_devices() - 1 //return values: 0 for success // -1 for could not open device // -3 for invalid device index int aiousb_open_device(int device_index); // for dio_bytes and counter_blocks when they are not NULL are filled with the appropriate value int aiousb_query_device_info (int device_index, int *dio_bytes, int *counter_blocks);