# Python Wrapper for C# API

Guide on using Python wrappers with the SMD3/SMD4 C# API.

# Background

Most AML products have a C# API available to allow easy integration of the product into your own application, without having to write an API yourself. The C# APIs provide an easy way to access all aspects of configuration and control of the product.

Using these APIs from C# is the easiest option. However, you can use the APIs with other languages such as C++ or Python.

# Instructions

### 1. Download the latest copy of the API DLL for your product

Visit the product page for your product and look for the C# API download. For example, for the SMD4 visit the link below, and look for the downloads tab at the bottom of the page. [https://arunmicro.com/products/smd4-stepper-motor-drive/](https://arunmicro.com/products/smd4-stepper-motor-drive/)

### 2. Download the pythonnet library

Pythonnet is a python library that allows developers to integrate .NET code within python. More information about pythonnet can be found here. <a>htttps://pypi.org/project/pythonnet/</a>

To install pythonnet via pip use the following command:

```bash
pip install pythonnet
```

### 3. Importing the API 

Add a reference to the required dll, for example:

```python
import clr
clr.AddReference(r"C:\source\SMD3API.dll")
from SMD3API import SMD3
```

### 4. Using the API 

Example code for the SMD3, demonstrating connecting to the drive and moving the motor.

```python
import clr 
import time
clr.AddReference(r"C:\source\SMD3API.dll")
from SMD3API import SMD3

# Create an instance of the SMD3
smd3=SMD3()

# Auto connect to the first SMD3 device found
smd3.Connect("COM")

# Choose a temperature sensor
smd3.SensorSelect = Tsel.Thermocouple

# Move 100 steps in the positive direction
smd3.MoveRelative(100)
```

Example code for the SMD4, demonstrating connecting to the drive and moving the motor.

```python
import clr
import time
clr.AddReference(r"C:\source\SMD4API.dll")
from Aml.Equipment.SMD4Api import *

# Create an instance of the SMD4
smd4=SMD4()

# Auto connect to the first SMD4 
smd4.Connect()

# Move motor in clockwise direction
smd4.MoveClockwise()

# Wait 5 seconds
time.sleep(5)

# Stop motor
smd4.Stop()
```