简体   繁体   English

HalconDotNet:无法在没有许可证的情况下检查许可证的有效性?

[英]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.在启动 HalconDotNet 功能之前,我想在我的应用程序的某处执行 Halcon 许可证检查。 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.但是,以下代码会生成一个异常,因为没有有效的许可证来使用用于检查许可证有效性的 function GetSystem()。

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.如果许可证无效,那么 halcon 操作员将无法工作。 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.是的,检查 Halcon 许可证的正确方法是使用 try catch。 This is a code excerpt in C++ from Programmer's Guide (Chapter 3.4 Handling Licensing Errors):这是程序员指南(第 3.4 章处理许可错误)中 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.
    }
}

In C#, just define HalconException in catch and see if you get the error code for missing license.在 C# 中,只需在 catch 中定义 HalconException 并查看是否收到缺少许可证的错误代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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