.netlicensinghalcon

HalconDotNet: Unable to check validity of license without license?


I wanted to perform a Halcon license check somewhere in my application before starting HalconDotNet functionalities. However the following code generates an exception for there is no valid license to use the function GetSystem() that is used to check the validity of the license.

static public void check_halcon_license()
{            
    HOperatorSet.GetSystem("is_license_valid", out HTuple info);
    Console.WriteLine("License check returns: " + (bool)info);
}

Am I missing something or am I supposed to just catch the exception and use that to determine its not valid? Seems weird to have a license check behind a license wall.


Solution

  • Yes, proper way to check Halcon license is by using try catch. This is a code excerpt in C++ from Programmer's Guide (Chapter 3.4 Handling Licensing Errors):

    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.
        }
    }
    

    In C#, just define HalconException in catch and see if you get the error code for missing license.