When running HALCON with a runtime license and a dongle, HALCON checks regularly whether the dongle is still available. This check has no measurable impact on the performance of HALCON.
In order to be notified if the dongle was removed and a license error is imminent, applications can register a callback function with HALCON that will be called when HALCON detects that the dongle is no longer available. HALCON operators will fail with licensing errors after about two to four minutes after this callback fires. If the dongle is reinserted before this time, HALCON will continue to operate normally.
Please note that if you do not register a callback and the dongle becomes unavailable during runtime, HALCON operators will fail with a license error and will therefore not provide meaningful output parameters. Depending on your application, this might even lead to crashes. It is highly suggested to handle errors from operators correctly or register the callback to notify the user and/or shut down the application in a controlled way.
To register your own callback function, use the following code in your application:
void __stdcall MyLicenseRecheckFailedCallback(void *context, Herror error) { <Add your application-specific callback code here.> }
Somewhere in your application startup code, add the following:
HSetLicenseRecheckFailedCallback(MyLicenseRecheckFailedCallback, &MyLicenseRecheckFailedContext);
MyLicenseRecheckFailedContext is a user-defined structure that you can use to pass extra information to your callback. If you do not need this, you can pass a NULL pointer instead.
To unregister a callback, simply call HSetLicenseRecheckFailedCallback with a NULL pointer as argument.
Note that callbacks are not chained – registering a callback will overwrite any previously registered callback.
For example, in your application, you might implement a proper licensing error handling like this:
Herror error; Htuple param, value; create_tuple_s(¶m, "version"); set_check("~give_error"); error = T_get_system(param, &value); destroy_tuple(value); destroy_tuple(param); if ((error >= H_ERR_LIC_NO_LICENSE) && (error <= H_ERR_LAST_LIC_ERROR)) { /* Handle licensing error here. */ }
Figure 3.2: Check for licensing errors in C.
try { HalconCpp::HTuple value = HalconCpp::HSystem::GetSystem("version"); } catch (HalconCpp::HException &exception) { if ( (exception.ErrorCode() >= H_ERR_LIC_NO_LICENSE) && (exception.ErrorCode() <= H_ERR_LAST_LIC_ERROR)) { // Handle licensing error here. } }
Figure 3.3: Check for licensing errors in C++.
To check whether a license is available at all, you can use any operator at the beginning of your application and check the result.