Prosilica PvAPI: can't

2011/5/27 <eberlid [..] ...>

> Do you see any issues in the code?
>
> Header file:
> &#10;&gt; #ifndef OROCOS_CAMERA_PROSILICA_COMPONENT_HPP&#10;&gt; #define OROCOS_CAMERA_PROSILICA_COMPONENT_HPP&#10;&gt;&#10;&gt; #include &lt;rtt/RTT.hpp&gt;&#10;&gt; #include &lt;iostream&gt;&#10;&gt;&#10;&gt; #define _LINUX&#10;&gt; #define _x64&#10;&gt;&#10;&gt; #include &quot;PvApi.h&quot;&#10;&gt;&#10;&gt; class Camera_prosilica&#10;&gt;    : public RTT::TaskContext&#10;&gt; {&#10;&gt;  public:&#10;&gt;    Camera_prosilica(string const&amp; name);&#10;&gt;&#10;&gt;    bool configureHook();&#10;&gt;    bool startHook();&#10;&gt;    void updateHook();&#10;&gt;    void stopHook();&#10;&gt;    void cleanupHook();&#10;&gt;&#10;&gt;  private:&#10;&gt; };&#10;&gt;&#10;&gt; #endif&#10;&gt;
>
> source file:
> &#10;&gt; #include &quot;camera_prosilica-component.hpp&quot;&#10;&gt; #include &lt;rtt/Component.hpp&gt;&#10;&gt;&#10;&gt; #include &lt;stdio.h&gt;&#10;&gt; #include &lt;stdlib.h&gt;&#10;&gt; #include &lt;string.h&gt;&#10;&gt;&#10;&gt; #include &lt;unistd.h&gt;&#10;&gt; #include &lt;time.h&gt;&#10;&gt; #include &lt;signal.h&gt;&#10;&gt;&#10;&gt; #include &quot;arpa/inet.h&quot;&#10;&gt;&#10;&gt; /*&#10;&gt;  * Using this macro, only one component may live&#10;&gt;  * in one library *and* you may *not* link this library&#10;&gt;  * with another component library. Use&#10;&gt;  * O_CREATE_COMPONENT_TYPE()&#10;&gt;  * ORO_LIST_COMPONENT_TYPE(Camera_prosilica)&#10;&gt;  * In case you want to link with another library that&#10;&gt;  * already contains components.&#10;&gt;  *&#10;&gt;  * If you have put your component class&#10;&gt;  * in a namespace, don&#039;t forget to add it here too:&#10;&gt;  */&#10;&gt;&#10;&gt;&#10;&gt; void Sleep(unsigned int time)&#10;&gt; {&#10;&gt;    struct timespec t,r;&#10;&gt;&#10;&gt;    t.tv_sec    = time / 1000;&#10;&gt;    t.tv_nsec   = (time % 1000) * 1000000;&#10;&gt;&#10;&gt;    while(nanosleep(&amp;t,&amp;r)==-1)&#10;&gt;        t = r;&#10;&gt; }&#10;&gt;&#10;&gt;&#10;&gt; Camera_prosilica::Camera_prosilica(string const&amp; name)&#10;&gt;        : TaskContext(name, PreOperational) {&#10;&gt;        std::cout &lt;&lt; &quot;Camera_prosilica constructed !&quot; &lt;&lt;std::endl;&#10;&gt; }&#10;&gt;&#10;&gt;&#10;&gt; bool Camera_prosilica::configureHook() {&#10;&gt;        tPvHandle camera;&#10;&gt;        tPvAccessFlags flags = ePvAccessMaster;&#10;&gt;        tPvErr err;&#10;&gt;        unsigned long inetAddr = inet_addr(&quot;192.168.0.101&quot;);&#10;&gt;&#10;&gt;&#10;&gt;        if(PvInitialize() != ePvErrSuccess) {&#10;&gt;                fprintf(stderr, &quot;\n-- Failed to initialize API!\n&quot;);&#10;&gt;                return false;&#10;&gt;        }&#10;&gt;        else {&#10;&gt;                fprintf(stdout, &quot;\n-- Successfully initialized API!\n&quot;);&#10;&gt;        }&#10;&gt;&#10;&gt;        Sleep(2000);&#10;&gt;&#10;&gt;        err = PvCameraOpenByAddr(inetAddr,flags,&amp;camera);&#10;&gt;        if(err != ePvErrSuccess) {&#10;&gt;                fprintf(stderr, &quot;-- Error opening camera by address: %d\n&quot;,&#10;&gt; static_cast&lt;int&gt;(err));&#10;&gt;                return false;&#10;&gt;        }&#10;&gt;        else&#10;&gt;                fprintf(stdout, &quot;-- Successfully opened camera by&#10;&gt; address!\n&quot;);&#10;&gt;&#10;&gt;        Sleep(500);&#10;&gt;&#10;&gt;        err = PvCaptureAdjustPacketSize(camera,1500);&#10;&gt;        if(err != ePvErrSuccess) {&#10;&gt;                fprintf(stderr, &quot;-- Error adjusting packet size: %d\n&quot;,&#10;&gt; static_cast&lt;int&gt;(err));&#10;&gt;                return false;&#10;&gt;        }&#10;&gt;        else&#10;&gt;                fprintf(stdout, &quot;-- Successfully set packet size!\n&quot;);&#10;&gt;&#10;&gt;        Sleep(500);&#10;&gt;&#10;&gt;        err = PvCaptureStart(camera);&#10;&gt;        if(err != ePvErrSuccess) {&#10;&gt;                fprintf(stderr, &quot;-- Error capture start: %d\n&quot;,&#10;&gt; static_cast&lt;int&gt;(err));&#10;&gt;                return false;&#10;&gt;        }&#10;&gt;        else&#10;&gt;                fprintf(stdout, &quot;-- Successfully started capture!\n&quot;);&#10;&gt;&#10;&gt;        Sleep(500);&#10;&gt;&#10;&gt;        unsigned long FrameSize = 0;&#10;&gt;        err = PvAttrUint32Get(camera,&quot;TotalBytesPerFrame&quot;,&amp;FrameSize);&#10;&gt;        if(err != ePvErrSuccess) {&#10;&gt;                fprintf(stderr, &quot;-- Error getting TotalBytesPerFrame: %d\n&quot;,&#10;&gt; static_cast&lt;int&gt;(err));&#10;&gt;                return false;&#10;&gt;        }&#10;&gt;        else&#10;&gt;                fprintf(stdout, &quot;-- Successfully got&#10;&gt; TotalBytesPerFrame!\n&quot;);&#10;&gt;&#10;&gt;        Sleep(500);&#10;&gt;&#10;&gt;        PvCaptureEnd(camera);&#10;&gt;        PvCameraClose(camera);&#10;&gt;        PvUnInitialize();&#10;&gt;&#10;&gt;        return true;&#10;&gt; }&#10;&gt;&#10;&gt; bool Camera_prosilica::startHook() {&#10;&gt;&#10;&gt;        return true;&#10;&gt; }&#10;&gt;&#10;&gt; void Camera_prosilica::updateHook() {&#10;&gt;&#10;&gt; }&#10;&gt;&#10;&gt; void Camera_prosilica::stopHook() {&#10;&gt;&#10;&gt;    std::cout &lt;&lt; &quot;Camera_prosilica executes stopping !&quot; &lt;&lt;std::endl;&#10;&gt; }&#10;&gt;&#10;&gt; void Camera_prosilica::cleanupHook() {&#10;&gt;&#10;&gt;        //PvUnInitialize();&#10;&gt;&#10;&gt;    std::cout &lt;&lt; &quot;Camera_prosilica cleaning up !&quot; &lt;&lt;std::endl;&#10;&gt; }&#10;&gt;&#10;&gt;&#10;&gt; ORO_CREATE_COMPONENT(Camera_prosilica)&#10;&gt;
>
> Since it just opens and closes the camera in the config-hook it is clear
> that camera is closed after configuration. The goal is to get the
> TotalBytesPerFrame successfully. I tried to get/set other attributes without
> success...
>
> It returns each time with
> &#10;&gt; -- Successfully initialized API!&#10;&gt; -- Successfully opened camera by address!&#10;&gt; -- Successfully set packet size!&#10;&gt; -- Successfully started capture!&#10;&gt; -- Error getting TotalBytesPerFrame: 6&#10;&gt;
>
> Can you compare my code with your code?
>

I look at my code and the problematic line is almost the same for me:

&#10;PvAttrUint32Get(mCameraHandle,&quot;TotalBytesPerFrame&quot;,&amp;frameSize)&#10;

I have no idea, sorry.

Philippe