Integrate HDevelop code into a C# application using the Library Project Export


Hello and welcome. In this tutorial, I’ll show you how to integrate
HDevelop code into your C# projects, using the Library Project
Export. In this video, I’ll mainly highlight the differences
compared to the corresponding C++ tutorial. If you haven’t already, we recommend watching
that tutorial first to learn more about features like the HDevEngine. We start with the same HDevelop program, reading
this image. Again, this procedure does the actual machine
vision; it segments the electrical contacts. Our goal is to integrate this procedure into
a Visual Studio Solution. At the end of the program, there is some visualization
for HDevelop. In the Library Project Export dialog,
we now choose C# as the target language. To better understand what is happening later
on, we append PN to the Project Name and NS to
the namespace. Then, we click Export. Let’s have a quick look at the generated files. As with C++, we get a CMake file that can
be used to, for example, create a Visual Studio Solution. Additionally, the export once again copied
the used HDevelop program. Lastly, in source, we find a single C# file
which contains wrapper functions with all the required HDevEngine API code. Let’s integrate this into our application. Here, I prepared an empty C# program. Now, to be able to use HALCON code and the
HDevEngine, we need to add references to HALCON/.NET and
the HDevEngine. Therefore, we right-click on References in
the Solution Explorer and choose “Add Reference”. Here, the DLLs are available from previous
projects. To locate them for the first time, click Browse,
navigate to %HALCONROOT%, bin, dotnet35, and add the halconddotnet.dll and the hdevenginedotnet.dll. Now, let’s write some HALCON code. First, we declare two variables: The input
image, and the resulting region. Then, we read the same image we read in HDevelop
a moment ago. Next, we add the C# wrapper code we generated
with HDevelop. Then, we can use the code as follows: First, the namespace we chose, then the project
name, and then the functionality. As with C++, it’s necessary to define the
ResourcePath, the location of the HDevelop script. Relative to the binary, it’s three levels
up. To simplify this path, you can copy the HDevelop
script to the bin directory. This could be done automatically while building
the project if you prefer. Then, we can call the procedure we saw previously
in HDevelop. And that’s all the code we need. Now, we can add a breakpoint, and run the
application. In the HALCON Variable Inspect, we can see
the variables: The image we read, and the region as a result
of the procedure call. As we have seen in the C++ tutorial,
you could now simply edit the HDevelop procedure, and as long as the signature does not change,
you don’t need to recompile the application. This concludes this short introduction. You should now be able to use the HDevelop
Library Project Export to integrate HALCON code into your C# application. Thank you for watching.

Leave a Reply

Your email address will not be published. Required fields are marked *