Malinko
Malinko

Reputation: 106

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.

Upvotes: 0

Views: 1106

Answers (3)

Jos Ke 79
Jos Ke 79

Reputation: 11

Instead of GetSystem, use GetSystemInfo. GetSystemInfo gets the current value of system information without requiring a license.

HOperatorSet.GetSystemInfo("is_license_valid", out var info);
Console.WriteLine("License check returns: " + info.S);

Upvotes: 1

Vladimir Perković
Vladimir Perković

Reputation: 1433

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.

Upvotes: 2

Kroepniek
Kroepniek

Reputation: 394

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
}

Upvotes: 1

Related Questions