C#与halcon混合编程(3)

相机类

**    1、 camera类文件未找到

**    a、创建相机类,通过实例化并加入 list 进行遍历访问 ;

       b、设定相机曝光时间 ;设定增益参数 ;设定单个像素等效尺寸 ;设置相机打开( Basler 相机) ;修改SDK,通过相机本身提供的Dll实现相机的打开与图片的提取 ;相机参数初始化,模式初始化等 ;

       c、相机打开:通过相机名称是否与配置名称相等来判断 ;标定通过标定类型(设置标志位)进行选择——标定板标定 OR 量规标定 ,标定后生成相对应 tiff 文件;

       d、内触发采集:设定相应参数后进行连续采集 ;

       e、外触发采集:设定相应参数及模式后进行采集 ;

       f、 关闭相机  ;整型、浮点型、模式类型参数设置 ;

       g、相机掉线相应函数 ;抓图错误相应函数 ;单张采集函数 ;

       h、ImageProcess 函数 :从队列中复制出图像进行处理,SDK 队列中的图像便可自由释放 ;图片处理分三种模式:内触发(相机连续采集)、外触发预采集(用户做配置时先采集一些图)、检测模式(实际检测时要先判断校正类型) ;调用图像工具进行检测,将图像进行拷贝可区别于原来不经处理的图像,体现区别 ;判断是否合格,显示检测后是否合格的图像 ;

配置加载新窗口

**    a、 安装  DevExpressComponentsBundleSetup-22.2.5  ;

**    b、 使用  DevExpress.Universal.Patch.v2.5.0.4  破解,相对于2.5.0.3 不会出现找不到Community文件夹的问题,且之后不出现试用的窗口 ;

**    c、 汉化执行后似乎没有效果 ;

**    注:   解决“错误为Lc.exe已退出,代码为-1”

                  项目中使用了商业组件的测试版,而在发布的时候使用的是哪个商业组件的破解版。大部分的商业组件经过破解的时候,强名称签名就会消失,所以破解的组件与原来的测试版组件的引用信息是完全不同的。故每次编译的时候,VS自动调用语言编译器之前会调用lc(许可编译器),就会出现-1错误。

                   解决方法:

                          1、  就是把Properties文件下的license.licx给删除,重新编译。
                          2、  如果还出现这个问题的话,必须将你的破解版的哪个组件使用lidism给翻译成il语言,然后用ilasm重新编译成dll,在编译的时候加入   /key=[你的强名称文件].snk   参数,自己加入强名称签名,然后使用VS重新编译,就可以成功了。

**    注:    由于缺少调试目标——————,Visual Studio 无法开始调试。请生成项目并重试,或者相应地设置 OutputPath 和 AssemblyName 属性,使其指向目标程序集的正确位置。

                    解决方法:  解决方案右键/清理解决方案/右键/重新生成解决方案

**    1、  创建检测运行时显示用户数据的窗体 mainform(winform主窗体类) ;创建用户登录配置加载界面 loadconfig(devexpress form类),devexpress控件库相对于winform拥有更多属性及外观选择 ;

**    2、  创建 label 提示用户选择配置 ;创建 comboBoxEdit 下拉选项框用于选取配置 ;创建确认、取消和新建 simplebutton ; 创建文本输入 textedit ;可以去窗口边框,更改窗口颜色,启动位置居中等 ;

// Program.cs    主程序

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace vision
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]  // [STAThread] ( []表示attribute ):指示应用程序的 COM 线程模型是单线程单元。对应的多线程单元则是 [MTAThread] (多线程单元线程);
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new loadconfig());   //加载登录界面而非主窗体
        }
    }
}
//  loadconfig.cs    加载配置界面

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.IO;


namespace vision
{
    public partial class loadconfig : DevExpress.XtraEditors.XtraForm
    {
        public loadconfig()
        {
            InitializeComponent();
            //扫描读取可选配置
            pathtool.initial();
            pathtool.GetFiles();
            if (pathtool.productNames != null)
            {
                //添加配置文件到下拉列表
                this.comboBoxEdit1.Properties.Items.AddRange(pathtool.productNames);
            }
        }
        private void simpleButton1_Click(object sender, EventArgs e)
        {
            //进行加载
            if (comboBoxEdit1.SelectedIndex != -1)
            {
                //有选项被选择时
                string s = comboBoxEdit1.SelectedItem.ToString();//获取消息框中的字符串
                pathtool.currentProduct = s;//字符串转换为当前工具名
                pathtool.currentProductPath = pathtool.pathDic[s];//转换为路径

                this.Visible = false;//不显示该控件
                mainform formm = new mainform();//实例化一个新的窗口
                this.Dispose();//销毁对象
            }
            else
            {
            }
        }
        private void simpleButton2_Click(object sender, EventArgs e)
        {
            //退出程序
            this.Close();
        }
        private void simpleButton3_Click(object sender, EventArgs e)
        {
            //首先检查名称有没有填写,如果填写,再检查是否已经存在,如果存在,提示是否覆盖
            if (textEdit1.Text.Trim() == String.Empty)
            {
                MessageBox.Show("请填写新产品名称!");
            }
            else
            {
                //获取路径
                string path = Application.StartupPath + "\\Data\\Product\\";
                string spath = path + textEdit1.Text;
                if (Directory.Exists(spath))
                {
                    //spath目录下存在文件
                    if (MessageBox.Show("已存在,是否覆盖?", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK)
                    {
                        //执行覆盖操作
                        Directory.Delete(spath, true);//删除原有
                        Directory.CreateDirectory(spath);
                        Directory.CreateDirectory(spath + "\\CCD1");
                        Directory.CreateDirectory(spath + "\\CCD2");
                        Directory.CreateDirectory(spath + "\\CCD3");
                        Directory.CreateDirectory(spath + "\\CCD4");
                        Directory.CreateDirectory(spath + "\\CCD5");

                        pathtool.currentProduct = textEdit1.Text;
                        pathtool.currentProductPath = pathtool.pathDic[textEdit1.Text];

                        this.Visible = false;//隐藏当前窗体
                        mainform formm = new mainform();//实例化新的主窗体并在桌面中央显示
                        this.Dispose();//释放资源
                    }
                    else
                    {
                    }
                }
                else
                {
                    Directory.CreateDirectory(spath);
                    pathtool.currentProduct = textEdit1.Text;
                    pathtool.currentProductPath = spath;
                    Directory.CreateDirectory(spath + "\\CCD1");
                    Directory.CreateDirectory(spath + "\\CCD2");
                    Directory.CreateDirectory(spath + "\\CCD3");
                    Directory.CreateDirectory(spath + "\\CCD4");
                    Directory.CreateDirectory(spath + "\\CCD5");

                    this.Visible = false;
                    mainform formm = new mainform();
                    this.Dispose();
                }
            }
        }
    }
}
//  pathtool.cs    路径处理文件

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace vision
{   //用于处理文件路径,不用每次都对路径进行填写等;
    class pathtool
    {
        public static string exepath;//EXE路径
        public static string productPath;//产品路径
        public static string configPath;//配置路径
        public static string currentProduct;//当前产品
        public static string currentProductPath;//当前产品工具
        public static Dictionary<string, string> pathDic;//路径键值对
        public static List<string> productNames;//产品名称列表
        public static void initial()
        {
            //获取相应路径
            exepath = Application.StartupPath;
            configPath = exepath + @"\Data";
            productPath = configPath + @"\Product";
        }
        public static void GetFiles()
        {
            //获取文件
            initial();
            //创建新字典
            pathDic = new Dictionary<string, string>();
            DirectoryInfo di = new DirectoryInfo(productPath);//通过目录创建、移动、枚举的实例方法;
            DirectoryInfo[] Dis = di.GetDirectories();//获取子文件夹列表
            if (Dis.Length > 0)
            {
                //子目录不为空时,将子目录添加至产品名称列表和路径键值对中;
                productNames = new List<string>();
                foreach (DirectoryInfo d in Dis)
                {
                    pathDic.Add(d.Name, d.FullName);
                    productNames.Add(d.Name);
                }
            }
        }
        public static void CreateNewProduct(string ProductName)
        {
            //创建新文件
            initial();
            DirectoryInfo di = new DirectoryInfo(productPath);
            DirectoryInfo[] Dis = di.GetDirectories();
            for (int i = 0; i < Dis.Length; i++)
            {
                //判断是否有重复配置文件
                if (Dis[i].Name == ProductName)
                {
                    MessageBox.Show("产品已存在");
                    return;
                }
            }
            Directory.CreateDirectory(productPath + @"\" + ProductName);
        }
    }
}
//  mainform.cs    配置界面调用的主窗口界面,只有显示,没有具体功能

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace vision
{
    public partial class mainform : Form
    {
        public mainform()
        {
            InitializeComponent();
            this.ShowDialog();//打开mainform后将其展示在最前端;
        }
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值