C# サンプルプログラム使用ガイド

現在ご覧いただいているのは最新版の内容です(V2.2.0)。異なるバージョンを参照する場合は、画面右上のボタンから切り替えが可能です。

■ ご利用中のバージョンが分からない場合や、サポートが必要な場合はお気軽にサポート窓口までご連絡ください。

以下では、Windows 環境における Mech-Vision SDK の C# サンプルプログラムの設定および実行方法について説明します。

使用前提

  • SDK の環境設定 が完了していること。

  • Visual Studio 2017 以降がインストールされていること。

  • .NET Framework 4.7.2 以降がインストールされていること。

  • Mech-Vision がインストールされ、正常に動作すること。

サンプルプログラム概要

C# サンプルプログラムは development/csharp/examples/ ディレクトリに格納されており、以下のサンプルが含まれています。

サンプル一覧 説明

solution_basic

ソリューションの開く/閉じる/保存/名前変更、およびソリューション情報とプロジェクト情報一覧の取得

project_basic

プロジェクト状態変更コールバックおよび画像取得完了コールバックを登録し、プロジェクトを実行して出力データ(把持点)を取得

project_data_storage

プロジェクトのデータ保存機能を操作し、保存データの読み取りおよび書き込みを実行

project_param_recipe

パラメータレシピ一覧の取得および現在のパラメータレシピの切り替え

solution_comm_config

ソリューションの通信設定(TCP/IP、Modbus など)の取得および変更

solution_device_status

ソリューション内のカメラの接続状態、温度、転送速度などのデバイス状態情報を取得

solution_global_variable

ソリューション内のグローバル変数(整数、浮動小数点数、文字列、キューなど)の読み取りおよび書き込み

step_basic

ステップ情報の取得、ステップ出力ポートの固定、およびプロジェクト実行後のステップ出力データ(位置姿勢など)の取得

step_props

JSON 形式でステップパラメータを読み取りおよび設定(多階層パラメータへのアクセス方法を含む)

production_interface

オペレーターインターフェイスの操作

production_interface_com

COM コンポーネントを使用してオペレーターインターフェイスを表示

サンプルプログラムの設定とビルド

  1. Visual Studio でサンプルディレクトリ内の .sln ソリューションファイルを開きます。

  2. プロジェクトを右クリックし、参照の追加 を選択して、development/csharp/lib ディレクトリ内の以下の DLL を参照として追加します。

    • MMind.Vision.dll

    • その他の依存 DLL(存在する場合)

  3. コード内のソリューションパスを変更し(下記サンプル参照)、ソリューションをビルドします(F6)。

サンプルプログラムの実行

  1. Mech-Vision が起動していることを確認します。

  2. サンプルコード内のソリューションパスを変更します。

    string path = "D:/path/to/your/solution";
  3. F5 キーを押して実行するか、bin/Release/ ディレクトリに生成された実行ファイルを直接実行します。

コード例

ソリューションを開き、プロジェクト情報を取得(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();
    }
}

プロジェクトを実行し、出力データを取得(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;
    }
}

ステップパラメータの読み取りと設定(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());
    }
}

この情報は役に立ちましたか?

ご意見・ご要望がございましたら、以下よりお寄せください:

Mech-Mindは、お客様のプライバシーを重視しています

このサイトでは最高の体験を提供するために Cookie を使用しています。サイトの閲覧を続ける場合、Cookie の使用に同意したことになります。「拒否する」を選択すると、このサイトを訪れた際に追跡や記憶が行われないように単独の Cookie が使用されます。