1

I need to make a function for live view image in canon camera, but when I try to use the example code provided from canon I got some errors in variables. So I modified the code so that it could work. But the function EDSDK.EdsGetPropertyData returns the error code 98 (in hex 62) which represents the error EDS_ERR_INVALID_POINTER. I would like to know what is wrong in my code, and how can I proceed it.

IntPtr outData;
    public void startLiveview(IntPtr camera)
    {
       
        uint err = EDSDK.EDS_ERR_OK;
        EDSDK.EdsDataType device = new EDSDK.EdsDataType();
        int size;
        EDSDK.EdsOpenSession(camera);
        // Get the output device for the live view image EdsUInt32 device; err = EdsGetPropertyData(camera, kEdsPropID_Evf_OutputDevice,  0 ,  , sizeof(device), &device ); 

        // PC live view starts by setting the PC as the output device for the live view image. if(err == EDS_ERR_OK) {  device |= kEdsEvfOutputDevice_PC; 
        err = EDSDK.EdsGetPropertySize(camera, EDSDK.PropID_Evf_OutputDevice, 0,out device, out size);
        MessageBox.Show("Error result:"+err.ToString());
        MessageBox.Show(device.ToString());
        MessageBox.Show(size.ToString());
        err = EDSDK.EdsGetPropertyData(camera, EDSDK.PropID_Evf_OutputDevice, 0, size, outData);
        MessageBox.Show(outData.ToString());
        if (err == EDSDK.EDS_ERR_OK)
        {
            //type2.GetType();
            //device |= EDSDK.PropID_Evf_OutputDevice;

            // err = EDSDK.EdsSetPropertyData(camera, EDSDK.PropID_Evf_OutputDevice, 0, sizeof(device), &device);
        }
        else
        {
            MessageBox.Show("Error result:" + err.ToString());
        }

        EDSDK.EdsCloseSession(camera);
    }
Jason Aller
  • 3,541
  • 28
  • 38
  • 38

1 Answers1

0

EdsGetPropertyData expects the outData pointer to have a value but you are passing a zero pointer.

You need to allocate memory first and then call EdsGetPropertyData, i.e. something like this:

outData = System.Runtime.InteropServices.Marshal.AllocHGlobal(size);
err = EDSDK.EdsGetPropertyData(camera, EDSDK.PropID_Evf_OutputDevice, 0, size, outData);

Once you are done, you must release that allocated memory or you'll have a memory leak:

System.Runtime.InteropServices.Marshal.FreeHGlobal(outData);

In the C# examples of the Canon SDK (since version 13.x, I believe) you should find methods that already implement EdsGetPropertyData methods for several data types. Why not use those instead of writing it yourself?

Johannes Bildstein
  • 1,069
  • 2
  • 8
  • 20
  • Hi men, thanks for help I'll try this solution. And I am writing the code for myself because im this version of SDK the example provided doesen't contains the code for live view, but I'll try download some older version of SDK. thanks! – Jhonny Andreatta Mar 29 '20 at 02:23
  • @JhonnyAndreatta I'm not talking about live view code but implementations for `EdsGetPropertyData`. Also, SDK version series 13.x is the latest, not something old. – Johannes Bildstein Mar 29 '20 at 11:33
  • Yeah but I'am already using the lastest version of SDK, I forgot to mention that, my bad! And was an misunderstanding on my part about the sample code, now I get it, I'll try to find some sample of EdsGetPropertyData on canon sample code. Thanks – Jhonny Andreatta Mar 29 '20 at 16:02
  • @JhonnyAndreatta no problem, it happens. The `EdsGetPropertyData` methods are in the EDSDK.cs file – Johannes Bildstein Mar 29 '20 at 16:45
  • Hi men, I added the value for outData in the EdsGetPropertyData with the memory allocation value, but when I run the GetProperty the code returns the error EDS_ERR_DEVICE_BUSY. I released the memory allocation, do you know how to solve this? `outData = System.Runtime.InteropServices.Marshal.AllocHGlobal(size); System.Runtime.InteropServices.Marshal.FreeHGlobal(outData); err = EDSDK.EdsSetPropertyData(camera, EDSDK.PropID_Evf_OutputDevice, 0, size, outData);` – Jhonny Andreatta Mar 30 '20 at 16:40
  • @JhonnyAndreatta you are releasing the allocated memory before using it, you should never ever do that! The cause of the SDK error is different though: when you allocate memory it contains random values which you use directly to set the property. The camera can't understand that random value and returns the error (the error code is not very intuitive though). – Johannes Bildstein Mar 31 '20 at 13:05
  • @JhonnyAndreatta to actually fix it, you should look at the samples again. You don't have to allocate memory to set a value, just pass the value directly. In case of the property `PropID_Evf_OutputDevice` you just do something like this: `EDSDK.EdsSetPropertyData(camera, EDSDK.PropID_Evf_OutputDevice, 0, size, EDSDK.EvfOutputDevice_TFT)`. The value of `EvfOutputDevice_TFT` is just a normal `uint` – Johannes Bildstein Mar 31 '20 at 13:09
  • Hi man thanks a lot, I wasn't understanding how the command works, now I get it, thanks for the pacient to explains! Now I'm working with the download of the image, I found an example on internet in C, I translated to C# and put on my code, but I got some errors in EdsDownloadEvfImage, could you help me? – Jhonny Andreatta Mar 31 '20 at 15:13