Forum
Please or Register to create posts and topics.

Module initialize, intermittent fail with C++ sdk.

Hi,

I noticed, ret return from AARTSAAPI_EnumDevice() API, not always return 0. Some time it will return 1.
Subsequently, when ret =1, ret= -2147483646 from AARTSAAPI_OpenDevice() API.
This cause me intermittently module initialize fail on my usage.
AARTSAAPI_Device d;
ret = AARTSAAPI_RescanDevices(&h, 2000);
AARTSAAPI_DeviceInfo dinfo = { sizeof(AARTSAAPI_DeviceInfo) };
ret = AARTSAAPI_EnumDevice(&h, L"spectranv6", 0, &dinfo);
ret = AARTSAAPI_OpenDevice(&h, &d, L"spectranv6/raw", dinfo.serialNumber)
May I know why it happen, and how to avoid this?
Best regards,
Ron95

If EnumDevice() returns 1, it means that there were no devices found. This could have any number of reasons (e.g. the device is still in use by another process), but obviously a subsequent call to OpenDevice() will not work in that case.

Please note that the return values of the AARTSAAPI functions are unsigned integers, so the return value you're getting is actually 0x80000002 which means "device not found", which is normal when EnumDevice() could not find any devices, there is no point in calling OpenDevice() in that case.

Some things that might help:

  • Ensure you're calling Shutdown() before exiting your program.
  • Ensure you're calling Close() when you're done with using the device.
  • Check the return value of RescanDevices(). If it is non-zero there were no devices found, so no point in calling EnumDevice().
  • Extend the timeout for RescanDevices().
  • Do not call your program again directly after it terminated.
  • Do not execute multiple instances of your program at the same time.
  • Do not call your program while using the RTSA Suite.