Exemplo n.º 1
0
/*----------------------------------------------------------------------------*/
AIODeviceInfo *AIODeviceInfoGet( unsigned long DeviceIndex )
{
    AIORESULT result = AIOUSB_SUCCESS;

    AIODeviceInfo *tmp = NewAIODeviceInfo();
    if ( !tmp ) {
        aio_errno = -AIOUSB_ERROR_NOT_ENOUGH_MEMORY;
        return NULL;
    }
    memset(tmp,0,sizeof(AIODeviceInfo));

    AIOUSBDevice *deviceDesc = AIODeviceTableGetDeviceAtIndex( DeviceIndex, &result );
    if ( result != AIOUSB_SUCCESS ) {
        free(tmp);
        return NULL;
    }

    tmp->PID       = deviceDesc->ProductID;
    tmp->DIOBytes  = deviceDesc->DIOBytes;
    tmp->Counters  = deviceDesc->Counters;

    const char *deviceName = ProductIDToName( tmp->PID );
    if ( deviceName ) {
        tmp->Name = strdup( deviceName );
    }

    return tmp;

}
Exemplo n.º 2
0
/**
 * @brief AIOUSB_GetDeviceProperties() returns a richer amount of information 
 * than QueryDeviceInfo()
 */
unsigned long AIOUSB_GetDeviceProperties(unsigned long DeviceIndex, DeviceProperties *properties ) 
{
    AIORESULT result = AIOUSB_SUCCESS;
    AIOUSBDevice *deviceDesc = AIODeviceTableGetDeviceAtIndex( DeviceIndex, &result );

    if(properties == 0)
        return AIOUSB_ERROR_INVALID_PARAMETER;
    
    properties->Name = deviceDesc->cachedName; /* if NULL, name will be requested from device */
    properties->SerialNumber = deviceDesc->cachedSerialNumber; /* if 0, serial number will be requested from device */
    properties->ProductID = deviceDesc->ProductID;
    properties->DIOPorts = deviceDesc->DIOBytes;
    properties->Counters = deviceDesc->Counters;
    properties->Tristates = deviceDesc->Tristates;
    properties->RootClock = deviceDesc->RootClock;
    properties->DACChannels = deviceDesc->ImmDACs;
    properties->ADCChannels = deviceDesc->ADCChannels;
    properties->ADCMUXChannels = deviceDesc->ADCMUXChannels;
    properties->ADCChannelsPerGroup = deviceDesc->ADCChannelsPerGroup;

    if(properties->Name == NULL)
        properties->Name = GetSafeDeviceName(DeviceIndex);
    if(properties->SerialNumber == 0)
        result = GetDeviceSerialNumber(DeviceIndex, &properties->SerialNumber);

    return result;
}
Exemplo n.º 3
0
/**
 * @brief 
 * @param DeviceIndex 
 * @param pSerialNumber 
 * @return 0 if successful, otherwise
 */
AIORESULT GetDeviceSerialNumber(unsigned long DeviceIndex, uint64_t *pSerialNumber ) 
{
    if( !pSerialNumber )
        return AIOUSB_ERROR_INVALID_PARAMETER;

    unsigned long bytes_read = sizeof(uint64_t);
    uint64_t buffer_data = -1;
    AIORESULT result = AIOUSB_SUCCESS;

    AIODeviceTableGetDeviceAtIndex( DeviceIndex, &result );
    result = GenericVendorRead( DeviceIndex, AUR_EEPROM_READ , EEPROM_SERIAL_NUMBER_ADDRESS, 0 , &buffer_data, &bytes_read );

    if( result != AIOUSB_SUCCESS )
        goto out_GetDeviceSerialNumber;

    *pSerialNumber = buffer_data;

out_GetDeviceSerialNumber:

    return result;
}
Exemplo n.º 4
0
int main( int argc, char **argv ) 
{
    struct opts options = AIO_OPTIONS;
    AIORET_TYPE result = AIOUSB_SUCCESS;
    int *indices;
    int num_devices;
    ADCConfigBlock *config;
    AIOUSBDevice *dev;
    USBDevice *usb;
    double *volts;
    process_aio_cmd_line( &options, argc, argv );

    result = AIOUSB_Init();
    if ( result != AIOUSB_SUCCESS ) {
        fprintf(stderr,"Error calling AIOUSB_Init(): %d\n", (int)result );
        exit(result );
    }

    AIOUSB_ListDevices();

    process_aio_cmd_line( &options, argc, argv );

    AIOUSB_FindDevices( &indices, &num_devices, find_ai_board );
    
    if( (result = aio_list_devices( &options, indices, num_devices ) != AIOUSB_SUCCESS )) 
        exit(result);

    if ( (config = NewADCConfigBlockFromJSON( options.adcconfig_json )) == NULL )
        exit(AIOUSB_ERROR_INVALID_ADCCONFIG);

    if ( (result = aio_override_adcconfig_settings( config, &options )) != AIOUSB_SUCCESS )
        exit(result);


    /* Save the config for the device index  in question */
    dev = AIODeviceTableGetDeviceAtIndex( options.index , (AIORESULT*)&result );
    if ( result != AIOUSB_SUCCESS ) {
        fprintf(stderr,"Error getting device at index %d\n", options.index );
        exit(result);
    }

    usb = AIOUSBDeviceGetUSBHandle( dev );

    /* Copy the modified config settings back to the 
     * device ave config to the device 
     */
    result = ADCConfigBlockCopy( AIOUSBDeviceGetADCConfigBlock( dev ), config );
    result = USBDevicePutADCConfigBlock( usb, config );
    /* or do this     
     * ADC_SetConfig( options.index, config->registers, &config->size ); */

    volts = (double*)malloc((ADCConfigBlockGetEndChannel( config )-ADCConfigBlockGetStartChannel( config )+1)*sizeof(double));
    
    for ( int i = 0, channel = 0; i < options.num_scans; i ++ , channel = 0) {
        if ( options.counts ) { /* --counts will write out the raw values */
            ADC_GetScan( options.index, (unsigned short*)volts );
            unsigned short *counts = (unsigned short *)volts;
            for ( int j = ADCConfigBlockGetStartChannel( config ); j < ADCConfigBlockGetEndChannel( config ) ; j ++ , channel ++) {
                printf("%u,", counts[channel] );
            }
            printf("%u\n", counts[channel] );


        } else {
            ADC_GetScanV( options.index, volts );
            for ( int j = ADCConfigBlockGetStartChannel( config ); j < ADCConfigBlockGetEndChannel( config ) ; j ++ , channel ++) {
                printf("%.3f,", volts[channel] );
            }
            printf("%f\n", volts[channel] );
        }

    }

    return 0;
}
Exemplo n.º 5
0
int main( int argc, char **argv ) 
{
    struct opts options = AIO_OPTIONS;
    AIORET_TYPE result = AIOUSB_SUCCESS;
    int *indices;
    int num_devices;
    ADCConfigBlock *config;
    AIOUSBDevice *dev;

    process_aio_cmd_line( &options, argc, argv );

    result = AIOUSB_Init();
    if ( result != AIOUSB_SUCCESS ) {
        fprintf(stderr,"Error calling AIOUSB_Init(): %d\n", (int)result );
        exit(result );
    }

    AIOUSB_ListDevices();

    process_aio_cmd_line( &options, argc, argv );

    AIOUSB_FindDevices( &indices, &num_devices, find_ai_board );
    
    if( (result = aio_list_devices( &options, indices, num_devices ) != AIOUSB_SUCCESS )) 
        exit(result);

    if ( (config = NewADCConfigBlockFromJSON( options.adcconfig_json )) == NULL )
        exit(AIOUSB_ERROR_INVALID_ADCCONFIG);

    if ( (result = aio_override_adcconfig_settings( config, &options )) != AIOUSB_SUCCESS )
        exit(result);


    /* Save the config for the device index  in question */
    dev = AIODeviceTableGetDeviceAtIndex( options.index , (AIORESULT*)&result );
    if ( result != AIOUSB_SUCCESS ) {
        fprintf(stderr,"Error getting device at index %d\n", options.index );
        exit(result);
    }

    unsigned short tmp = 0;
    unsigned short mask = 0xffff; 
    
    /**
     * @brief Make all ports outputs and 0 value as the initial tristate
     */

    printf("Configuring all ports for output\n" );
    result = DIO_Configure( options.index, AIOUSB_FALSE, &mask, &tmp );

    result = DIO_ReadAll( options.index, &tmp );     /* Verify that all the values are initially 0 */
    if ( result != AIOUSB_SUCCESS ) {
        fprintf(stderr,"Error performing DIO_ReadAll(): %d\n", result );
        exit(1);
    }
    if ( tmp != 0 )  {
        fprintf(stderr, "Error, by default all ports should have value 0, and not %u\n", tmp );
    } else {
        printf("DIO_ReadAll() gave value %u == %u(expected)\n", tmp, 0 );
    }

    for ( int i = 0 ; i < dev->DIOBytes*8 ; i ++ ) { 
        result = DIO_Write1(options.index,i, (i % 2 == 0 ? AIOUSB_FALSE : AIOUSB_TRUE ));
        if ( result != AIOUSB_SUCCESS ) {
            fprintf(stderr,"Error running on index %d , retval=%d\n", i, result );
            exit(1);
        }
    }
    printf("Successfully performed DIO_Write1()\n");
    tmp = 0;

    result = DIO_ReadAll( options.index, &tmp );
    if ( result != AIOUSB_SUCCESS ) {
        fprintf(stderr,"Error performing DIO_ReadAll(): %d\n", result );
    } else if ( tmp != 0xaaaa ) {
        fprintf(stderr,"Values expected from DIO_ReadAll() %#x != %#x\n", 0xaaaa, tmp );
    } else {
        printf("DIO_ReadAll() gave value %#x == %#x(expected)\n", tmp, 0xaaaa );
    }

    return result;
}