<div dir="ltr">Hi all,<div><br></div><div>I'm trying to interface with a <a href="http://www.baslerweb.com/en/products/">Basler USB3 camera</a> from a Haskell application, but I'm experiencing some difficulty. The camera comes with a C++ library that makes it fairly straight forward. The following code can be used to acquire a camera source:</div><div><br></div><div><br></div><div><div><font face="monospace"> PylonAutoInitTerm pylon;</font></div><div><font face="monospace"> CInstantCamera camera( CTlFactory::GetInstance().CreateFirstDevice());</font></div><div><font face="monospace"> camera.RegisterConfiguration( (CConfigurationEventHandler*) NULL, RegistrationMode_ReplaceAll, Cleanup_None);</font></div><div><font face="monospace"> cout << "Using device " << camera.GetDeviceInfo().GetModelName() << endl;</font></div></div><div><br></div><div><br></div><div>Using the inline-c and inline-c-cpp libraries, I am trying to perform this same call from a Haskell executable. I have the following:</div><div><br></div><div><br></div><div><div><font face="monospace">{-# LANGUAGE QuasiQuotes, TemplateHaskell #-}</font></div><div><font face="monospace"><br></font></div><div><font face="monospace">import qualified Language.C.Inline as C</font></div><div><font face="monospace">import qualified Language.C.Inline.Cpp as C</font></div><div><font face="monospace"><br></font></div><div><font face="monospace">C.context C.cppCtx</font></div><div><font face="monospace"><br></font></div><div><font face="monospace">C.include "pylon/PylonIncludes.h"</font></div><div><font face="monospace">C.include "iostream"</font></div><div><font face="monospace"><br></font></div><div><font face="monospace">C.using "namespace Pylon";</font></div><div><font face="monospace">C.using "namespace std";</font></div><div><font face="monospace"><br></font></div><div><font face="monospace">main :: IO ()</font></div><div><font face="monospace">main =</font></div><div><font face="monospace"> [C.block| void {</font></div><div><font face="monospace"> PylonAutoInitTerm pylon;</font></div><div><font face="monospace"><br></font></div><div><font face="monospace"> CInstantCamera camera( CTlFactory::GetInstance().CreateFirstDevice());</font></div><div><font face="monospace"> camera.RegisterConfiguration( (CConfigurationEventHandler*) NULL, RegistrationMode_ReplaceAll, Cleanup_None);</font></div><div><font face="monospace"> cout << "Using device " << camera.GetDeviceInfo().GetModelName() << endl;</font></div><div><font face="monospace"> }|]</font></div></div><div><br></div><div><br></div><div>However, when the resulting executable is ran, it hangs - failing to print "Using device".</div><div><br></div><div><br></div><div><font face="monospace">inline-c</font> generates a <font face="monospace">Test.cpp</font> file, which contains</div><div><div><br></div><div><br></div><div><font face="monospace">#include "pylon/PylonIncludes.h"</font></div><div><font face="monospace"><br></font></div><div><font face="monospace">#include "iostream"</font></div><div><font face="monospace"><br></font></div><div><font face="monospace">using namespace Pylon;</font></div><div><font face="monospace"><br></font></div><div><font face="monospace">using namespace std;</font></div><div><font face="monospace"><br></font></div><div><font face="monospace">extern "C" {</font></div><div><font face="monospace">void inline_c_Main_0_e23f0c6a0bc10367be76252744bf4e6c74493314() {</font></div><div><font face="monospace"><br></font></div><div><font face="monospace"> PylonAutoInitTerm pylon;</font></div><div><font face="monospace"><br></font></div><div><font face="monospace"> CInstantCamera camera( CTlFactory::GetInstance().CreateFirstDevice());</font></div><div><font face="monospace"> camera.RegisterConfiguration( (CConfigurationEventHandler*) NULL, RegistrationMode_ReplaceAll, Cleanup_None);</font></div><div><font face="monospace"> cout << "Using device " << camera.GetDeviceInfo().GetModelName() << endl;</font></div><div><font face="monospace"> </font></div><div><font face="monospace">}</font></div><div><font face="monospace"><br></font></div><div><font face="monospace">}</font></div></div><div><br></div><div><br></div><div>If I modify this exact file, I can turn it into something that can be run, by simply adding:</div><div><br></div><div><br></div><div><div><font face="monospace">int main() {</font></div><div><font face="monospace"> inline_c_Main_0_e23f0c6a0bc10367be76252744bf4e6c74493314();</font></div><div><font face="monospace">}</font></div></div><div><br></div><div><br></div><div>At this point, I can now compile that very C++ code with G++ and run it:</div><div><br></div><div><br></div><div>
<div>
<span style="font-family:monospace"><span style="font-weight:bold;color:rgb(84,255,84)">[nix-shell:~/work/circuithub/receiving-station]$</span> g++ Test.cpp -I/home/ollie/work/circuithub/receiving-station/pylon5/include -L/home/ollie/work/circuithub/receiving-station/pylon5/lib64 -Wl,-E -lpylonbase -lpylonu<br>tility -lGenApi_gcc_v3_0_Basler_pylon_v5_0 -lGCBase_gcc_v3_0_Basler_pylon_v5_0 -Wl,--enable-new-dtags -Wl,-rpath,/home/ollie/work/circuithub/receiving-station/pylon5/lib64
<br>
<br><span style="font-weight:bold;color:rgb(84,255,84)">[nix-shell:~/work/circuithub/receiving-station]$</span> ./a.out <br>GetDeviceDiscoveryInfo: bFunctionClass = 14, bFunctionSubClass = 3, bFunctionProtocol = 0. Device is not an U3V device.
<br>GetDeviceDiscoveryInfo: bFunctionClass = 14, bFunctionSubClass = 3, bFunctionProtocol = 0. Device is not an U3V device.
<br>Using device acA3800-14um<br>
<br></span></div></div><div><span style="font-family:monospace"><br></span></div><div>So as we can see, the C++ code is not the problem.</div><div><br></div><div>Does anyone know why I don't see the same behaviour from my Haskell application? I imagine there might be some thread trickery happening behind the scenes, but I don't know what to even begin looking for.</div><div><br></div><div>Thanks, let me know if you need any more information.</div><div><br></div><div>- Ollie</div></div>