Camera Control Using C# SDK

Ask software engineering and SDK questions for developers working on Mac OS X, Windows or Linux.
  • Author
  • Message
Offline

jgoakley

  • Posts: 2
  • Joined: Sun Sep 12, 2021 6:18 pm
  • Real Name: Jeff Oakley

Camera Control Using C# SDK

PostThu Sep 23, 2021 7:12 pm

Hi, First time posting on this forum!

I have a custom made motorized Pan/Tilt mount and I am working on a project to get the Pan/Tilt status of the Joystick on an ATEM 1 M/E Advanced Panel. I'm using windows and the firmware version of the panel is 8.5.3 and I'm using the 8.5.3 version of the SDK.

I started with the CameraFocus example which is written in C++. If I make no changes to the example I am able to connect to the switcher and it will issue the first SetFloats() without error but then fails on subsequent calls. The same is true if I call GetFloats(), it will show S_OK on the first call then all subsequent calls return with E_FAIL.

Then I saw there was a C# example (A language I'm much more familiar with). Using that I am able to to successfully call GetFloats() multiple times. Then (with the code below) I am able to sucessfully get the current Pan value (left and right) of the joystick but not the Tilt value. In the C++ library the GetFloats function has an output parameter that returns a pointer to an array instead of a just a single double value like the C# library.

I was not able to find any documentation on the C# library so I figured I would see if anyone here had any thoughts on what I can do to get either the C++ version working or what I may be doing incorrectly to get the Tilt value as well in the C# library.

Thanks so much for any help!

Code: Select all
static void Main(string[] args)
{
    // Create switcher discovery object
    IBMDSwitcherDiscovery discovery = new CBMDSwitcherDiscovery();

    // Connect to switcher
    IBMDSwitcher switcher;
    _BMDSwitcherConnectToFailure failureReason;
    discovery.ConnectTo("192.168.10.240", out switcher, out failureReason);
    Console.WriteLine("Connected to switcher");

    IntPtr cameraControlIntPtr;
    IBMDSwitcherCameraControl cameraControl;
    Guid cameraControlGuid = typeof(IBMDSwitcherCameraControl).GUID;

    IntPtr pSwitcher = Marshal.GetIUnknownForObject(switcher);

    int queryInterfaceResult = Marshal.QueryInterface(pSwitcher, ref cameraControlGuid, out cameraControlIntPtr);

    cameraControl = Marshal.GetObjectForIUnknown(cameraControlIntPtr) as IBMDSwitcherCameraControl;

    uint count = 2;
    double outputValues;

    while (true)
    {
        cameraControl.GetFloats(1, 11, 0, ref count, out outputValues);
        Console.WriteLine(outputValues);
        System.Threading.Thread.Sleep(100);
    }
}
Offline

jgoakley

  • Posts: 2
  • Joined: Sun Sep 12, 2021 6:18 pm
  • Real Name: Jeff Oakley

Re: Camera Control Using C# SDK

PostSun Sep 26, 2021 4:20 pm

Update: The issue I was running into with the C++ example project is gone. I must have messed something up with the Visual Studio project because I grabbed a new copy of the example and it started working without issue. I added the GetFloats() call (like the code I posted originally) and I was able to successfully get the Pan and Tilt values from the board.

The C# issue still applies since I am not able to get more than the Pan values when using the C# library.
Offline

Cameron Nichols

Blackmagic Design

  • Posts: 367
  • Joined: Mon Sep 04, 2017 4:05 am

Re: Camera Control Using C# SDK

PostMon Sep 27, 2021 5:10 am

Hi Jeff and welcome to the Blackmagic Software Developer forum,

The IBMDSwitcherCameraControl methods GetFloat, SetFloat, GetInt16s, etc use a pointer to native unmanaged buffer. To access the values in C# you need to copy the unmanaged array into the CLR managed array.

The following code would provide this function:
Code: Select all
double[] outputValues = new double[2];
IntPtr outputValuesPtr = Marshal.AllocHGlobal(Marshal.SizeOf(outputValues[0]) * outputValues.Length);

try
{
   unsafe
   {
      double* outputValuesDeref = (double*)outputValuesPtr.ToPointer();
      cameraControl.GetFloats(
         1,                           // Camera number
         11,                          // PTZ Control
         0,                           // Pan/Tilt Velocity
         (uint)outputValues.Length,   // Array size
         out *outputValuesDeref       // Unmanaged array
         );
   }
   Marshal.Copy(outputValuesPtr , outputValues, 0, outputValues.Length);
}
finally
{
   Marshal.FreeHGlobal(outputValuesPtr);
}
Console.WriteLine("Pan = {0:F}, Tilt = {1:F}", outputValues[0], outputValues[1]);
Ensure that you enable unsafe code in your C# project settings to use unmanaged arrays.

Regards
Cameron

Return to Software Developers

Who is online

Users browsing this forum: No registered users and 2 guests