VisionMaster4.0.0二次开发教 - LD_Dragon - 博客园

目录

author:ld_dragon

date:2021.07

wx:dsflsj745200

环境配置

1 项目属性设置

1.创建winform项目后 点开项目菜单中的属性配置 
    选择框架为4.6.1的
    生成页面 去除首选32位勾选
    修改输出路径为 VisionMaster下的Application文件夹

2 环境变量绑定

1.在App.config下粘贴代码 以绑定环境变量

``` ```xml
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <appSettings>
    <!--启动服务形式(0代表默认系统服务, 1代表exe方式启动)-->
    <add key="StartServerByExe" value="0" />
    <!--远程Server地址,用于连接不同主机中的server-->
    <!--<add key="ServerSetting" value="127.0.0.1:5556" />-->
    <add key="ClientSettingsProvider.ServiceUri" value="" />
  </appSettings>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
  </startup>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <probing privatePath="myLibs;myLibs\Newtonsoft.Json;3rdLib;3rdLib\System;3rdLib\MsgPack;3rdLib\Log4Net;3rdLib\ICSharpCode;3rdLib\OpenCv;GateWay" />
      <dependentAssembly>
        <assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <system.web>
    <membership defaultProvider="ClientAuthenticationMembershipProvider">
      <providers>
        <add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" />
      </providers>
    </membership>
    <roleManager defaultProvider="ClientRoleProvider" enabled="true">
      <providers>
        <add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400" />
      </providers>
    </roleManager>
  </system.web>
</configuration>

3 控件导入

1.首先打开vs工具箱>右键点击所有windows>选择项
2.点击浏览>VisionMaster4.0.0/Application/myLibs> VMControls.Winform.Release.dll>确定

4 动态库引用

1.添加VM SDK相关动态库
    右键引用>添加引用>浏览>Application>myLibs 添加七个文件
2.防止VM动态库混乱 修改七个动态库文件的 复制本地 属性为False

``` ```c#
动态库七个文件:
    Apps.ColorFun.DLL
    VM.Core.dll
    VM.PlatformSDKCS.dll
    VMControls.Interface.dll
    VMControls.RenderInterface.dll
    VMControls.Winform.Release.dll
    VMFBase.dll

方案加载执行结果显示

1.添加2个button按钮为 加载方案 执行方案
2.添加VMRenderControl控件
3.添加ListBox控件显示执行结果信息

1 加载方案Code

// 加载方案buttonCode
// 引用程序集
using VM.Core;
using VM.PlateformSDKCS;

重点:对于方案的所有操作都集中于 VmSolution这个基类中!

private void button2_Click(object sender, EventArgs e)
       {
           string message;
           VmSolution.Import(@"C:\Users\wangp\Desktop\circleFind.sol",""); // 导入方案 属性path为路径 password为密码
           message = "Load Sol Success!";
           listBox1.Items.Add(message); // 添加消息到listbox中
           listBox1.TopIndex = listBox1.Items.Count - 1; // 将消息显示最前面一行
       }

2 控制方案执行Code

private void button1_Click(object sender, EventArgs e)
       {
           // 想要执行方案中的流程,需要定义一个流程对象
           VmProcedure process = (VmProcedure)VmSolution.Instance["流程1"];
           // 定义完成后需要执行一次
           Task.Run(()=> {
               process.Run(); // process 执行一次
           });
       }

``` ```c#
1 流程执行完成后 就需要显示圆查找模块的结果
2 引用添加 VisionMaster/Application/Module(sp)/x64/location/IMVSCircleFindModu

``` ```c#
private void button1_Click(object sender, EventArgs e)
       {
           // 使用模块时候 需要定义对象
           IMVSCircleFindModuCs.IMVSCircleFindModuTool circleFind = (IMVSCircleFindModuCs.IMVSCircleFindModuTool)VmSolution.Instance["流程1.圆查找1"];
           // 显示
           vmRenderControl1.ModuleSource = circleFind;

           // 想要执行方案中的流程,需要定义一个流程对象
           VmProcedure process = (VmProcedure)VmSolution.Instance["流程1"];
           // 定义完成后需要执行一次
           Task.Run(()=> {
               process.Run(); // process 执行一次
           });
           // 流程执行完成后 就需要显示圆查找模块的结果
       }

3 运行结果获取

vm二次开发中获取错误码定位可能出现的问题

private void button2_Click(object sender, EventArgs e)
{
    string message;
    try
    {
        VmSolution.Import(@"C:\Users\wangp\Desktop\circleFind.sol", ""); // 导入方案 属性path为路径 password为密码
        message = "Load Sol Success!";
        listBox1.Items.Add(message); // 添加消息到listbox中
        listBox1.TopIndex = listBox1.Items.Count - 1; // 将消息显示最前面一行
    }
    catch(VmException ex) // 所有错误集中VmException
    {
        message = "load Sol Faile" + Convert.ToString(ex.errorCode,16);  // 将ex.errorCode 改为16进制显示
        listBox1.Items.Add(message); // 添加消息到listbox中
        listBox1.TopIndex = listBox1.Items.Count - 1; // 将消息显示最前面一行
    }   
}
private void button3_Click(object sender, EventArgs e)
       {
           // 使用模块时候 需要定义对象
           IMVSCircleFindModuCs.IMVSCircleFindModuTool circleFind = (IMVSCircleFindModuCs.IMVSCircleFindModuTool)VmSolution.Instance["流程1.圆查找1"];
           if (circleFind == null) {
               return; // 如果圆查找为空 那么返回
           }
           textBox1.Text = circleFind.ModuResult.OutputCircle.CenterPoint.X.ToString("0.00");
           textBox2.Text = circleFind.ModuResult.OutputCircle.CenterPoint.Y.ToString("0.00");
           textBox3.Text = circleFind.ModuResult.OutputCircle.Radius.ToString("0.00");
       }

__EOF__


原网址: 访问
创建于: 2024-06-20 14:07:27
目录: default
标签: 无

请先后发表评论
  • 最新评论
  • 总共0条评论