Esempio n. 1
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            this.resultTextBox.ForeColor = System.Drawing.Color.Red;
            selectCameraVersion.Items.Add("全景");
            selectCameraVersion.Items.Add("其他");
            signal.printControl   = true;
            signal.InputParameter = false;
            staticForm            = this;
            this.groupBox2.Hide();
            mycallback = new CallBack(CallBackProc);
            handle     = this.Handle;

            HOperatorSet.GenEmptyObj(out m_Image);
            HOperatorSet.GenEmptyObj(out m_objDisp);
            m_hWindowHandle = hWindowControl1.HalconID;
            m_AcqHandle     = Vision.CamParam.m_AcqHandle;
            HOperatorSet.SetDraw(m_hWindowHandle, "margin");
            HOperatorSet.SetColored(m_hWindowHandle, 12);
            HOperatorSet.SetColor(m_hWindowHandle, "red");
            //设置halcon内部处理的图像的宽度和高度
            HOperatorSet.SetSystem("tsp_width", 3000);
            HOperatorSet.SetSystem("tsp_height", 3000);
            try
            {
                DataBaseOperate.OpenConnection();  //打开数据库
                DataBaseOperate.CloseConnection(); //关闭数据库
            }
            catch
            {
                MessageBox.Show("数据库连接失败。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                System.Windows.Forms.Application.Exit();
            }

            Control.CheckForIllegalCrossThreadCalls = false;
            #region      对plc连接信号赋值
            //读CIO1100.00位的数据命令********摄像头检测开始
            plcCameraTestBegin[0]  = 0x80;
            plcCameraTestBegin[1]  = 0x00;
            plcCameraTestBegin[2]  = 0x02;
            plcCameraTestBegin[3]  = 0x00;
            plcCameraTestBegin[4]  = 0x01;
            plcCameraTestBegin[5]  = 0x00;
            plcCameraTestBegin[6]  = 0x00;
            plcCameraTestBegin[7]  = 0x0A;
            plcCameraTestBegin[8]  = 0x00;
            plcCameraTestBegin[9]  = 0x00;
            plcCameraTestBegin[10] = 0x01;
            plcCameraTestBegin[11] = 0x01;
            plcCameraTestBegin[12] = 0x30;
            plcCameraTestBegin[13] = 0x04;
            plcCameraTestBegin[14] = 0x4C;
            plcCameraTestBegin[15] = 0x00;
            plcCameraTestBegin[16] = 0x00;
            plcCameraTestBegin[17] = 0x01;
            //写CIO1100.00位的数据命令********复位摄像头检测开始位
            plcCameraTestReset[0]  = 0x80;
            plcCameraTestReset[1]  = 0x00;
            plcCameraTestReset[2]  = 0x02;
            plcCameraTestReset[3]  = 0x00;
            plcCameraTestReset[4]  = 0x01;
            plcCameraTestReset[5]  = 0x00;
            plcCameraTestReset[6]  = 0x00;
            plcCameraTestReset[7]  = 0x0A;
            plcCameraTestReset[8]  = 0x00;
            plcCameraTestReset[9]  = 0x00;
            plcCameraTestReset[10] = 0x01;
            plcCameraTestReset[11] = 0x02;
            plcCameraTestReset[12] = 0x30;
            plcCameraTestReset[13] = 0x04;
            plcCameraTestReset[14] = 0x4C;
            plcCameraTestReset[15] = 0x00;
            plcCameraTestReset[16] = 0x00;
            plcCameraTestReset[17] = 0x01;
            plcCameraTestReset[18] = 0x00;

            //读CIO1102.00位的数据命令********条码打印开始
            plcPrinterBegin[0]  = 0x80;
            plcPrinterBegin[1]  = 0x00;
            plcPrinterBegin[2]  = 0x02;
            plcPrinterBegin[3]  = 0x00;
            plcPrinterBegin[4]  = 0x01;
            plcPrinterBegin[5]  = 0x00;
            plcPrinterBegin[6]  = 0x00;
            plcPrinterBegin[7]  = 0x0A;
            plcPrinterBegin[8]  = 0x00;
            plcPrinterBegin[9]  = 0x00;
            plcPrinterBegin[10] = 0x01;
            plcPrinterBegin[11] = 0x01;
            plcPrinterBegin[12] = 0x30;
            plcPrinterBegin[13] = 0x04;
            plcPrinterBegin[14] = 0x4E;
            plcPrinterBegin[15] = 0x00;
            plcPrinterBegin[16] = 0x00;
            plcPrinterBegin[17] = 0x01;

            //写CIO1102.00位的数据命令********复位条码打印开始位
            plcPrinterReset[0]  = 0x80;
            plcPrinterReset[1]  = 0x00;
            plcPrinterReset[2]  = 0x02;
            plcPrinterReset[3]  = 0x00;
            plcPrinterReset[4]  = 0x01;
            plcPrinterReset[5]  = 0x00;
            plcPrinterReset[6]  = 0x00;
            plcPrinterReset[7]  = 0x0A;
            plcPrinterReset[8]  = 0x00;
            plcPrinterReset[9]  = 0x00;
            plcPrinterReset[10] = 0x01;
            plcPrinterReset[11] = 0x02;
            plcPrinterReset[12] = 0x30;
            plcPrinterReset[13] = 0x04;
            plcPrinterReset[14] = 0x4E;
            plcPrinterReset[15] = 0x00;
            plcPrinterReset[16] = 0x00;
            plcPrinterReset[17] = 0x01;
            plcPrinterReset[18] = 0x00;

            //写CIO1101.00位的数据命令********摄像头OK信号
            plcCameraTestOK[0]  = 0x80;
            plcCameraTestOK[1]  = 0x00;
            plcCameraTestOK[2]  = 0x02;
            plcCameraTestOK[3]  = 0x00;
            plcCameraTestOK[4]  = 0x01;
            plcCameraTestOK[5]  = 0x00;
            plcCameraTestOK[6]  = 0x00;
            plcCameraTestOK[7]  = 0x0A;
            plcCameraTestOK[8]  = 0x00;
            plcCameraTestOK[9]  = 0x00;
            plcCameraTestOK[10] = 0x01;
            plcCameraTestOK[11] = 0x02;
            plcCameraTestOK[12] = 0x30;
            plcCameraTestOK[13] = 0x04;
            plcCameraTestOK[14] = 0x4D;
            plcCameraTestOK[15] = 0x00;
            plcCameraTestOK[16] = 0x00;
            plcCameraTestOK[17] = 0x01;
            plcCameraTestOK[18] = 0x01;


            #endregion
            //创建(实例化)线程,将需要执行的函数(方法-过程)传入线程中
            this.threadInBack = new Thread(new ThreadStart(PLCConnection));   //3
            //设置线程为后台线程(随着主线程(窗体线程)的退出而退出)
            this.threadInBack.IsBackground = true;
            this.threadInBack.Start();
            comboBox_color.SelectedIndex     = 3;
            comboBox_port.SelectedIndex      = 1;
            comboBox_format.SelectedIndex    = 0;
            comboBox_channel.SelectedIndex   = 0;
            comboBox_interrupt.SelectedIndex = 1;
            step       = 1;
            step_print = 1;

            for (ushort i = 0; i < MaxPort; i++)//initialize each port
            {
                if (Angelo.AngeloRTV_Initial(i) != 0)
                {
                    MessageBox.Show("Total No. of AngeloRTV Port = " + i.ToString());
                    break;
                }
            }
        }