Skip to main content

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/

2. Install workloads for Visual Studio

To install a workload, or check what is installed, open Visual Studio and go to 'Tools > Get Tools and Features...'

Install the following workloads:

  • .NET desktop development

  • Desktop development with C++, with the default installation components PLUS the following:

    • C++/CLI support for v143 build tools

Use install or modify as required.

image.png

3. Creating the project 

Start the new project wizard (File > New > Project). Choose one of the following, then proceed to create your project as normal.

  • CLR Empty Project (.NET Framework)

  • CLR Console App(.NET Framework) 

A screenshot of a computer program

Description automatically generated

4. Referencing the API DLL file

The API DLL file needs to be referenced in your project. To do this go to:

  • Solution Explorer
  • Right click on the project, Add > Reference… 
  • Choose ‘browse’ and select the DLL file you downloaded previously (example below shows SMD3 API)

Finally, click OK and the DLL will be added as a reference to your project.

A screenshot of a computer

Description automatically generated 

5. Using the API

Example code (main.cpp), demonstrating connecting and moving the motor.

#include <windows.h>
#include <iostream>
#include <msclr/marshal_cppstd.h> // Include for string conversion

// Include CLR headers
#include <vcclr.h>
#pragma comment(lib, "mscoree.lib")

// Import the mscorlib library
#import "C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\mscorlib.tlb" raw_interfaces_only \
    high_property_prefixes("_get","_put","_putref") \
    rename("ReportEvent", "InteropServices_ReportEvent")

using namespace System;
using namespace msclr::interop; // Namespace for string conversion


// Main function to use the DLL in a native C++ application
int main() {
    try {
        // Create a instance of the class SMD3 from SMD3API namespace in the dll
        auto smd3 = gcnew SMD3API::SMD3();
        
        // Connect the SMD3 on COM3
        smd3->Connect("COM3 TEXT");

        // Move a short distance and stop
        smd3->MoveVelocity("+");
        smd3->Stop();

        // Wait for user input before exiting
        std::cout << "Press Enter to exit" << std::endl;
        std::cin.get(); 
    }
    catch (Exception^ ex) {
        // Convert System::String^ to std::string
        std::string errorMessage = marshal_as<std::string>(ex->Message);
        std::cerr << "Exception: " << errorMessage << std::endl;
    }
    return 0;
}