简体   繁体   中英

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.

If the license is not valid then the halcon operators will not work. Try using something like this:

try
{
    // this will throw an exception when the license is not valid
    HOperatorSet.CountSeconds(out HTuple s);
}
catch (Exception ex)
{
    // license is not valid
}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM