Getting Started

Thomas Dideriksen

Getting Started

Once you have downloaded the Nikon SDK C# Wrapper library and added the DLL to your project references, make sure to include the Nikon namespace.

using Nikon;

Now you're ready to get started. First you need to create a NikonManager object.

NikonManager manager = new NikonManager("Type0003.md3");

Make sure to replace "Type0003.md3" with the appropriate MD3 file for your Nikon DSLR model (You can get MD3 files from Nikons SDK website).

The NikonManager keeps track of arrival and removal of cameras on your system. Your application can get this information by hooking up to events on the NikonManager.

manager.DeviceAdded += new DeviceAddedDelegate(manager_DeviceAdded);

The handler delegate function have the following signature.

void manager_DeviceAdded(NikonManager sender, NikonDevice device)

When DeviceAdded fires, your handler will receive a NikonDevice object representing a single Nikon DSLR camera.
The NikonDevice object can be used to interact with the camera - more on that later.

Before your application terminates, make sure to call the Shutdown function on the NikonManager object to perform proper resource cleanup.


It's very important to call Shutdown before your application terminates. If you forget, internal threads will be left running and the driver may get into a bad state.

Using The NikonDevice

The NikonDevice object represents a physical Nikon DSLR camera. You use this object to interact with and control your device.

Let's say you want to get the camera battery-level. This can be achieved in the following way.

    int batteryLevel = device.GetInteger(eNkMAIDCapability.kNkMAIDCapability_BatteryLevel);
catch (NikonException ex)

The "battery-level capability" is just one of many capabilities that your camera may support. The exact list of capabilities depends on your camera model as well as the state of your camera. Physical buttons and dials on your device also influence the list of available capabilities.

At any time, you can query the NikonDevice object to get a list of available capabilities.

NkMAIDCapInfo[] capInfo = device.GetCapabilityInfo();

This will return an array of "capability info" structures that your device supports. Each structure contains metadata on a specific capability.

  • Data type (int, uint, string, etc.)
  • Supported operations (read, write, execute, etc.)
  • A human-readable describtion
  • Etc.

One of the core capabilities of your camera is (ofcourse) to capture photos. The "capture capability" is an example of an executable capability. You can execute it in the following way.


Because this is such a common operation, the NikonDevice object provides provides a convenience function that executes the exact same code.


Before you capture a photo, make sure to hook up the appropriate events so you can receive the captured images. There are a few to choose between, but the one you're probably most interested in is the ImageReady event.

device.ImageReady += new ImageReadyDelegate(device_ImageReady);

This event will fire when the captured image is ready.

void device_ImageReady(NikonDevice sender, NikonImage image)

The NikonImage object has a memory buffer that contains the captured image. Note that if your DSLR is configured to shoot Raw+Jpeg, the ImageReady event will fire twice per capture.

Capability Changes

Several capabilities can change at any time, depending on the physical state of your DSLR. Examples includes "Exposure Status" that changes depending on the lighting conditions of the scene that your camera is observing. Another example is "Camera Inclination" that changes as you rotate the camera device.

Your application can learn about these changes by hooking up to the CapabilityValueChanged event.

device.CapabilityValueChanged += new CapabilityChangedDelegate(device_CapabilityValueChanged);

Every time a capability value change, your handler will be called.

void device_CapabilityValueChanged(NikonDevice sender, NkMAIDCapability capability)

Sometimes it's not only the capability value that changes - in some situations the capability metadata changes too. A good example of this is the "Auto Focus" capability. It's usually an executable capability, but if you disable auto focus using a physical switch on your DSLR, the "Auto Focus" capability will no longer be executable.

Your application can learn about those types of changes by hooking up to the CapabilityChanged event.

device.CapabilityChanged += new CapabilityChangedDelegate(device_CapabilityChanged);

Just like the CapabilityValueChanged event, the handler will indicate exactly what capability changed.

void device_CapabilityChanged(NikonDevice sender, NkMAIDCapability capability)

A typical response to the CapabilityChanged event would be to call the GetCapabilityInfo function again, to make sure your application has up-to-date information on capability metadata.

Sample Code

Note that the source code for the Nikon SDK C# Wrapper includes several demonstration projects that shows how to use the library. There are both WPF, WinForms and command line examples available.


Discussion: Reacting to a Nikon MAID EVENT - change in camera capability (VB .NET)
Wiki: Home