Multiple devices - how to manage them coming and going

Do I have to close and deconstruct the handle for a device when I recognize it is no longer attached. I will have a configuration where devices will be powered on and off and I am trying to find the proper sequence to find the one that dropped and to properly cleanup after it and reestablish an interface when a device (may be the same, may be a new one) comes online. Using 6010.

Hi Debbie,

There are a few ways to do this. If you are using C++, the FrontPanel Manager class is designed to generate notifications when a device is opened or closed and includes pure virtual methods that you can fill with your own procedure for setup and cleanup.

If you’re not using FrontPanel Manager, you can create an array or other list of okCFrontPanel objects and periodically check the array for changes. The okCFrontPanel class also allows you to list the devices, set ID numbers, and gather information such as serial numbers that you can use to check on each of your devices. Whether or not you need to deconstruct the handle will depend on the language you are using and how your application handles the device connections and objects.


Thanks…doing this in C++…and I have an array of objects. Logic is for my app constructor to construct a generic handle so can do GetDeviceCount, then construct a handle for each device and use that for GetDeviceListSerial. I now have serial numbers to use on the open. Then in a periodic function I GetDeviceCount. If !IsOpen AND serial number not null (was getting ‘cannot claim interface’ if given OpenBySerial a null serial number) do OpenBySerial. This works for first time opens but once I have opened a device it seems I cannot just GetDeviceSerial and repeat. I’m getting duplicate serial numbers for the device that goes away and comes back. Now I’m thinking the handle needs a cleanup. Just closing it was not sufficient. The test I am doing for ‘go away then return’ is done by disconnecting USB not powering down device. This is a possible way the device can go away (along with staying connected by USB but power removed from device - not sure if this will give me a different response but that’s another test to tackle).

What does IsOpen return is device was successfully opened but then disconnected and reconnected to USB? My assumption was IsOpen would be FALSE and I would do OpenBySerial again.


I would recommend switching to using GetDeviceInfo to populate an okTDeviceInfo struct, rather than calling GetDeviceSerial. GetDeviceSerial, along with a few similar methods, are now deprecated and will be removed in a future FrontPanel distribution. The advantage to using GetDeviceInfo is that every time you call it on your device handle, it will repopulate the okTDeviceInfo struct directly from the connected device, removing any need to do cleanup on the handle in this case. You can then access the serialNumber member of the info struct.

The way OpenBySerial works, if there is a device available it should succeed. If the device is already open, it closes the device and reopens it as long as it is not “owned” by another device handle. IsOpen simply performs a check to see if the device is valid. If the device is invalid when IsOpen() is called, it closes the device and returns FALSE. I suppose it is possible that the timing in your program is such that it misses the point at which the device was invalid, but repopulating the okTDeviceInfo struct by calling GetDeviceInfo after attempting to reopen the device should get you the new serial number.


HI Alex…
I thought the device had to be opened before I could get info using GetDeviceInfo. That’s why I was going with GetDeviceSerial. To get the serial number so I could OpenBySerial then do GetDeviceInfo. I thought GetDeviceInfo would return ‘device not open’ if done prior to open… Do I have a misunderstanding? What steps do you recommend to open a device if I do not know the serial number a priori?


The idea behind my suggestion is that you retrieve the serial number after you open the device. You are correct in your assumption that GetDeviceInfo will return “Device not open” if called on an okCFrontPanel instance that is not attached to an open device, but you can call OpenBySerial with NULL input in C++ (use an empty string for other languages) and it will simply open the first FrontPanel-enabled device it finds that is not already open.

To sum up, if you have an array of FrontPanel-enabled devices that you want to monitor, you can:
-Check to see if the device is still open by calling IsOpen() on it
-If the device is not open, verify there is a device to open by checking GetDeviceCount()
-If there is a device to open, open it using OpenBySerial() with no parameters (empty string for languages other than C++)
-Get the serial number by populating the okTDeviceInfo struct

This process should get you where you need to go. For further information about the FrontPanel methods, refer to the API reference pages at