# Using the Control.NET API

## Installing Driver Dependencies

Follow the instructions for [Installing OCT Host](/axsun-knowledge-base/software-tools/oct-host.md#installation) to also install the dependencies for the AxsunOCTControl.NET API.  [OCT Host](/axsun-knowledge-base/software-tools/oct-host.md) is a GUI application based on *AxsunOCTControl.dll*.  For USB communication with Axsun devices, the AxsunOCTControl library also depends on *LibUsbDotNet.dll* and a USB device driver which are also installed with OCT Host.

## Integrating Into Your Application

The AxsunOCTControl.NET API can be called into from source code platforms that support .NET library integration.  The basic syntax for several common languages is shown below:

### C\#

Create an instance of an AxsunOCTControl object using its default constructor, then call member functions as desired:

```csharp
AxsunOCTControl.AxsunOCTControl AOCT;
AOCT = new AxsunOCTControl.AxsunOCTControl();

string ControlVersion = "";
AOCT.GetControlVersion(ref ControlVersion);
```

More extensive sample code is available in the [AxsunOCTControl function reference](https://downloads.axsun.com/public/manuals/AxsunOCTControl_Interface_Specification.pdf).&#x20;

### C/C++

Integrating AxsunOCTControl in a C++ application requires some extra setup involving COM assembly registration.  Refer to the Guide on [Using AxsunOCTControl.dll in C++](/axsun-knowledge-base/how-tos/using-axsunoctcontrol.dll-in-c++.md) for more details.

To use the AxsunOCTControl in a "plain-old" C application, first perform the steps to integrate AxsunOCTControl with a C++ application and then create an `extern "C" {}` wrapper library for the *AxsunOCTControl.dll* methods you wish to call.

{% hint style="info" %}
**NOTE:** It is strongly recommended to use the [AxsunOCTControl\_LW library](/axsun-knowledge-base/api-references/axsunoctcontrol-lightweight.md) instead of AxsunOCTControl.NET if your application is based on a C or C++ codebase.
{% endhint %}

### LabVIEW

Integrating AxsunOCTControl in a LabVIEW application is straightforward using the functions on the *Connectivity -*> *.NET* palette:&#x20;

![The LabVIEW 2016 .NET functions palette.](/files/-LT4JtCVGLBs-CqdPVuI)

* Place a **Constructor Node** function on your block diagram.
* Use the file dialog to navigate to the location of the *AxsunOCTControl.dll* assembly on your disk, open it, and then select "AxsunOCTControl" in the list of available objects:

![Open the AxsunOCTControl.dll assembly and create an AxsunOCTControl object.](/files/-LT4LZcWFMLQKp2AY_9u)

* Place **Invoke Node (.NET)** functions and wire the reference output from the AxsunOCTControl constructor node to the reference input of the invoke node.  Select desired AxsunOCTControl methods to call via each of the invoke nodes, for example `GetControlVersion()`

![Select a method to correspond with each invoke node.](/files/-LT4WSasj6NvK_lrYx1s)

* Add a string indicator and also a **Close Reference** function to explicitly close the AxsunOCTControl object at the end of your program flow.
* Run the VI to display the version of the AxsunOCTControl library in the string indicator:

![](/files/-LT4VF5ienZI1MRaUm-j)

* The **Reg Event Callback** function can be used to register a callback VI to execute when the library detects the connection or disconnection of a hardware device.

![Wire a VI Ref callback to execute on OCTDeviceConnectOrDisconnectEvent.](/files/-LT4XgNtHYvYCJAvbSb1)

### MATLAB

```
% (note your library path may be different)
NET.addAssembly('C:\Program Files\Axsun\Axsun OCT Control\AxsunOCTControl.dll');
AOCT = AxsunOCTControl.AxsunOCTControl;
ControlVersionString = char(AOCT.GetControlVersion());
```

**NOTE**:  A known bug (1759533) in MATLAB version R2018a may generate an "external component" exception.  To avoid this, please downgrade to MATLAB 2017 or upgrade to MATLAB R2018b or newer.

### Python

Install the **pythonnet** library from <https://github.com/pythonnet/pythonnet>

```python
import clr
import string
import sys

# note your library path may be different
dllFile = r'C:\Program Files (x86)\Axsun\OCT Host\AxsunOCTControl'
clr.AddReference(dllFile)

from AxsunOCTControl import AxsunOCTControl
AOCT = AxsunOCTControl()                            # call constructor
ControlVersionString = AOCT.GetControlVersion()     # call library functions
```

## Error Handling and Reporting

The tables below list possible error codes which can occur during the use of the AxsunOCTControl library and an Axsun OCT device such as a Laser Engine, Camera Link DAQ Board, or Ethernet/PCIe DAQ Board. &#x20;

It is rare for errors to result from a device hardware malfunction. Rather, errors that do occur are more likely a result of device-host communication issues or an improper sequence of API calls. If an error or warning occurs that cannot be explained, try the following steps:

1. Reset the AxsunOCTControl library instance and/or the GUI Tool (e.g. [OCT Host](/axsun-knowledge-base/software-tools/oct-host.md), [Hardware Control Tool](/axsun-knowledge-base/software-tools/hardware-control-tool.md), or your custom application) which is built around the AxsunOCTControl library.
2. Restart (power-cycle) the device hardware.
3. Restart the Host PC.

If unexplained errors or warnings continue after following these steps, please [contact Axsun Customer Support](/axsun-knowledge-base/other/getting-help.md).&#x20;

### Firmware Error Codes

Firmware errors are generated by the microcontroller on the OCT device (e.g. laser driver board or DAQ board) and reported to the user via the AxsunOCTControl library API or GUI tools based on this API.&#x20;

| Error Code | Description & Notes    |
| ---------- | ---------------------- |
| 0          | No Error               |
| 1          | USB\_CHECKSUM\_ERROR   |
| 2          | USB\_TIMEOUT\_ERROR    |
| 3          | USB\_READ\_ERROR       |
| 4          | USB\_WRITE\_ERROR      |
| 5          | HIGHEST\_USB\_ERROR    |
| 6          | DAC\_TABLE\_TOO\_LARGE |
| ...        | ...                    |

### Library Error Codes

Library errors are generated by the AxsunOCTControl library running on the host PC.&#x20;

| Error Code | Description & Notes      |
| ---------- | ------------------------ |
| 1000       | ERROR\_READING           |
| 1001       | ERROR\_WRITING\_1        |
| 1002       | NO\_DEVICE\_PRESENT      |
| 1003       | CHECKSUM\_ERROR          |
| 1004       | TOO\_MANY\_PACKET\_TRIES |
| ...        | ...                      |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.axsun.com/axsun-knowledge-base/api-references/axsunoctcontrol.dll/using-the-control-api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
