0

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.

Malinko
  • 124
  • 11
  • perhaps ask the company for a statement. – Christoph Rackwitz Sep 07 '22 at 10:30
  • 1
    Have you ever tried to contact MVTec? :) In my experience they make an actual effort to never have any contact with customers. – Malinko Sep 07 '22 at 11:19
  • 1
    great to hear! so my vague plans to "white-room reimplement" their techniques from publicly accessible API documentation _into OpenCV_ may gain some popularity after all... if any mvtec people read this: hire me :D – Christoph Rackwitz Sep 07 '22 at 13:54

2 Answers2

1

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
}
Kroepniek
  • 301
  • 1
  • 7
  • Thank you for your suggestion, but as stated in my question I was already aware of this workaround. Or is there an advantage in using `CountSeconds()` instead of `GetSystem()`, as far as I know they both just give you an exception. (I cant check for I have no license at this moment :) – Malinko Sep 07 '22 at 09:56
  • 1
    Mostly I am amazed by the uselessness of the `GetSystem("is_license_valid")` functionality and assumed I made a mistake or otherwise the only possible output of that query is `true` as `false` can never be an output. – Malinko Sep 07 '22 at 10:06
1

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.

Vladimir Perković
  • 1,351
  • 3
  • 12
  • 30
  • 1
    Marked as answer for actually confirming with source my question: "Am I missing something or...". Accidentally also confirmed that `GetSystem("is_license_valid")` has BUT ONE POSSIBLE OUTPUT! :D – Malinko Sep 08 '22 at 09:19