C# Sample Usage Guide

You are currently viewing the documentation for a pre-release version (2.2.0). To access documentation for other versions, click the "Switch Version" button located in the upper-right corner of the page.

■ If you're unsure about the version of the product you are using, please contact Mech-Mind Technical Support for assistance.

This section introduces how to configure and run C# samples of Mech-Vision SDK on Windows.

Prerequisites

  • SDK environment setup has been completed.

  • Visual Studio 2017 or later.

  • .NET Framework 4.7.2 or later.

  • Mech-Vision is installed and can run properly.

Sample Overview

The C# samples are located in development/csharp/examples/ and include:

Sample directory Description

solution_basic

Open, close, save, and rename solutions; get solution information and project information lists.

project_basic

Register project running-state and acquisition-finished callbacks, run projects, and get output data (pick point poses).

project_data_storage

Operate project data storage and read/write stored data.

project_param_recipe

Get parameter recipe lists and switch the current parameter recipe.

solution_comm_config

Get and modify communication configurations of a solution (TCP/IP, Modbus, and so on).

solution_device_status

Get camera status information in a solution, such as connection status, temperature, and transfer rate.

solution_global_variable

Read and write global variables in a solution (integer, floating-point, string, queue, and so on).

step_basic

Get Step information, pin Step output ports, and get Step output data (such as point poses) after running a project.

step_props

Read and set Step parameters in JSON format (including access to multi-level parameters).

production_interface

Production Interface operations.

production_interface_com

Production Interface communication operations.

Configure and Build Samples

  1. Open the .sln solution file in the sample directory with Visual Studio.

  2. Right-click the project and select Add Reference. Add the following DLL files in development/csharp/lib as project references:

    • MMind.Vision.dll

    • Other dependency DLL files (if any)

  3. Update the solution path in code (see the example below), then build the solution (F6).

Run Samples

  1. Ensure that Mech-Vision is running.

  2. Update the solution path in sample code:

    string path = "D:/path/to/your/solution";
  3. Press F5 to run, or run the executable file generated in bin/Release/.

Code Examples

Open a Solution and Get Project Information (solution_basic)

using MMind.Vision;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        MmindVision.Initialize();

        // Open a solution
        var solution = new Solution();
        var error = solution.Open("D:/data/vision_sdk_example",
                                  string.Empty, string.Empty);

        // Get solution information
        var solutionInfo = new SolutionInfo();
        error = solution.GetInfo(ref solutionInfo);
        System.Console.WriteLine($"Solution: {solutionInfo.Name}");

        // Get project information list
        var projectInfos = new List<ProjectInfo>();
        error = solution.GetAllProjectInfos(ref projectInfos);
        foreach (var info in projectInfos)
            System.Console.WriteLine($"  Project: {info.Name}");

        // Save and close the solution
        error = solution.Save();
        error = solution.Close();

        MmindVision.Uninitialize();
    }
}

Run a Project and Get Output Data (project_basic)

using MMind.Vision;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;

class Example
{
    static void Run()
    {
        var solution = new Solution();
        solution.Open("D:/data/vision_sdk_example", string.Empty, string.Empty);

        // Get project name
        var projectInfos = new List<ProjectInfo>();
        solution.GetAllProjectInfos(ref projectInfos);
        var project = new Project(projectInfos[0].Name);

        // Register running-state callback
        project.SetRunningChangedCallback((cbData) => {
            System.Console.WriteLine($"Project running: {cbData.IsRunning}");
        });

        // Run the project (wait until it finishes)
        var projectResult = new ProjectResult();
        project.Run(ProjectRunWaitState.Finished, "request_1", ref projectResult);

        // Parse output data
        var joOutput = JObject.Parse(projectResult.OutputJson);
        var jaPickPoints = joOutput["workobject_data"]["pick_points"] as JArray;
    }
}

Read and Set Step Parameters (step_props)

using MMind.Vision;
using Newtonsoft.Json.Linq;

class Example
{
    static void Run()
    {
        var solution = new Solution();
        solution.Open("D:/data/vision_sdk_example", string.Empty, string.Empty);

        var step = new Step("3D Matching_1", "Matching");

        // Read step parameters
        var jaPropNames = new JArray { "confidenceThreshold" };
        string propsJson = string.Empty;
        step.GetPropertiesJson(jaPropNames.ToString(), ref propsJson);

        // Set step parameters
        var joProps = new JObject { { "confidenceThreshold", 0.8 } };
        step.SetPropertiesJson(joProps.ToString());
    }
}

Is this page helpful?

You can give a feedback in any of the following ways:

We Value Your Privacy

We use cookies to provide you with the best possible experience on our website. By continuing to use the site, you acknowledge that you agree to the use of cookies. If you decline, a single cookie will be used to ensure you're not tracked or remembered when you visit this website.