static pwr_tStatus IoRackInit( io_tCtx ctx, io_sAgent *ap, io_sRack *rp) { io_sLocalUSB *local; int status; int i; unsigned int snum; int found; io_sCard *cp; pwr_sClass_MotionControl_USB *op = (pwr_sClass_MotionControl_USB *)rp->op; local = (io_sLocalUSB *) calloc( 1, sizeof(io_sLocalUSB)); rp->Local = local; for ( i = 0; i < (int)sizeof(local->USB_Handle); i++) { status = USBIO_Open( &local->USB_Handle[i]); if ( status) { if ( i == 0) op->Status = status; break; } /* Check is this card is configured */ status = USBIO_GetSerialNr( &local->USB_Handle[i], &snum); if ( !status) { found = 0; for ( cp = rp->cardlist; cp; cp = cp->next) { if ( ((pwr_sClass_MotionControl_USBIO *)cp->op)->Super.Address == snum) { local->snum[i] = snum; found = 1; break; } } if ( !found) { errh_Info( "USBIO Serial number %d not configured", snum); op->Status = USBIO_Close( &local->USB_Handle[i]); i--; continue; } } else errh_Error( "USBIO Serial number error '%s'", rp->Name); } errh_Info( "Init of USBIO rack '%s'", rp->Name); return IO__SUCCESS; }
static int usbio_reconnect( io_tCtx ctx, io_sAgent *ap, io_sRack *rp, io_sCard *cp) { io_sLocal *local = cp->Local; io_sLocalUSB *localUSB = (io_sLocalUSB *)rp->Local; pwr_sClass_MotionControl_USBIO *op = (pwr_sClass_MotionControl_USBIO *)cp->op; pwr_tTime time; pwr_tDeltaTime diff; unsigned int snum; int handle; int i; int status; time_GetTime( &time); time_Adiff( &diff, &time, &local->ConnectRetry); if ( time_DToFloat( 0, &diff) > 1.0) { for ( i = 0; i < (int)sizeof(localUSB->USB_Handle); i++) { status = USBIO_Open( &handle); if ( status) break; status = USBIO_GetSerialNr( &handle, &snum); if ( snum == op->Super.Address) { local->USB_Handle = localUSB->USB_Handle[local->Idx] = handle; op->Status = status; op->Super.ErrorCount = 0; IoCardClose( ctx, ap, rp, cp); IoCardInit( ctx, ap, rp, cp); errh_Info( "USBIO card reconnected '%s'", cp->Name); return 1; } } } return 0; }