コード例 #1
0
        private void axSerialPort1_event_DataReceived(string strRecv)
        {
            int nIdxQuestion = strRecv.IndexOf("?");
            int nIdxAnswer   = strRecv.IndexOf("!");

            //下位机主发
            if (nIdxQuestion >= 0)
            {
                switch (strRecv.Substring(nIdxQuestion + 1, 1).ToUpper())
                {
                case "B":
                    CommonFunc.SendMessage(GlobalVar.gl_IntPtr_MainWindow, GlobalVar.WM_StartScan, (IntPtr)0, (IntPtr)0);     //开始扫条码
                    break;

                case "W":
                    CommonFunc.SendMessage(GlobalVar.gl_IntPtr_MainWindow, GlobalVar.WM_ReadyForTest, (IntPtr)0, (IntPtr)0);     //开始拍照
                    break;
                }
            }
            //下位机回复
            else if (nIdxAnswer >= 0)
            {
                switch (strRecv.Substring(nIdxAnswer + 1, 1))
                {
                case "R":          //读取下位机步进脉冲
                    string str_pos = strRecv.Substring(nIdxAnswer + 2, strRecv.IndexOf("#") - 2);
                    IntPtr ptr     = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(str_pos);
                    string str1    = str_pos.Substring(2);
                    this.Invoke(new Action(() => {
                        _step1Pulse = Convert.ToDouble(str1) / PluseMM;
                    }));
                    break;

                case "V":         //读取电机速度
                    string strV  = strRecv.Substring(nIdxAnswer + 2, strRecv.IndexOf("#") - 2);
                    IntPtr ptrV  = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(strV);
                    string _strA = strV.Substring(0, 2);
                    string _strV = strV.Substring(2, 2);
                    string _strD = strV.Substring(4, 2);
                    this.Invoke(new Action(() => {
                        _ACCS = Convert.ToInt32(_strA);
                        _VELS = Convert.ToInt32(_strV);
                        _DCLS = Convert.ToInt32(_strD);
                    }));
                    break;

                case "E":      //允许作业
                    GlobalVar.gl_bAllowWork = true;
                    break;
                }
            }
        }
コード例 #2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="str"></param>
 /// <param name="bIsHostSend">是否PC主发</param>
 /// <param name="bNeedReply">是否需要下位机回复</param>
 public void Send(string str, bool bIsHostSend, bool bNeedReply)
 {
     if (GlobalVar.m_bManualStart)
     {
         return;
     }
     try
     {
         axSerialPort1.Send(str, bIsHostSend, bNeedReply);
     }
     catch (Exception ex)
     {
         CommonFunc.writeLog("发送失败:" + ex.ToString());
     }
 }
コード例 #3
0
        private void WriteINI()
        {
            //制品Mark点面积区间
            string str = AreaProduct[0] + "," + AreaProduct[1];

            CommonFunc.Write(m_CCDName, ini_key_ProductArea, str, m_fileINI);
            //校准片Mark点面积区间
            str = AreaMark[0] + "," + AreaMark[1];
            CommonFunc.Write(m_CCDName, ini_key_MarkArea, str, m_fileINI);
            //校准片小Mark点面积区间
            str = AreaPoint[0] + "," + AreaPoint[1];
            CommonFunc.Write(m_CCDName, ini_key_PointArea, str, m_fileINI);
            //相机曝光值-制品
            CommonFunc.Write(m_CCDName, ini_key_ExposureP, m_ExposureProduct.ToString(), m_fileINI);
            //相机曝光值-校准片
            CommonFunc.Write(m_CCDName, ini_key_ExposureM, m_ExposureModel.ToString(), m_fileINI);
            //像素点尺寸
            CommonFunc.Write(m_CCDName, ini_key_UmPixel, m_UmPixel.ToString(), m_fileINI);
            //ROI
            halconCCD1.WriteRoiIni();
            halconCCD1.InitRoiConfig();
            //AVT相机编号
            CommonFunc.Write(m_CCDName, ini_key_AVTDevice, m_AVTName, m_fileINI);
        }
コード例 #4
0
        public void StartHanle(HImage himage)
        {
            //m_bInHandleImage = true; //2018.05.25 改为多线程,在拍照前置为True
            m_MarkCenter = new PointH();
            m_MarkAxis   = new PointH();
            try
            {
                HImage handleImage = himage;

                //if (GlobalVar.gl_strProductModel.ToUpper().IndexOf("A85IFLEX") >= 0)
                if (!GlobalVar.m_bUseXLD)
                {
                    m_MarkCenter = halconHelp.GetMarkCenter(handleImage);
                }
                else
                {
                    m_MarkCenter = halconHelp.GetMarkCenterXLD(handleImage);
                }
                if (m_MarkCenter.X == 0.0 || m_MarkCenter.Y == 0.0)
                {
                    m_MarkAxis = new PointH();
                }
                else
                {
                    m_MarkAxis = halconHelp.GetMarkAxis(m_MarkCenter);
                }
                if (m_bIn9Point)
                {
                    #region 九点标定处理
                    m_bHomMat2DOK = false;
                    try
                    {
                        if (m_MarkCenter.X == 0.0 || m_MarkCenter.Y == 0.0)
                        {
                            m_bHomMat2DOK = false;
                            return;
                        }
                        HTuple hv_Row, hv_Column, hv_AxisX, hv_AxisY, hv_Height, hv_Width, hv_newRow, hv_newColumn;
                        halconHelp.Get9Points(handleImage, out hv_Row, out hv_Column, out hv_Height, out hv_Width);
                        GetAxisData(hv_Row, hv_Column, hv_Height, hv_Width, out hv_newRow, out hv_newColumn, out hv_AxisY, out hv_AxisX);
                        //int length = hv_newRow.Length;
                        //hv_newRow[length] = m_MarkCenter.Y;
                        //hv_newColumn[length] = m_MarkCenter.X;
                        //hv_AxisY[length] = cadCenterData.Y;
                        //hv_AxisX[length] = cadCenterData.X;
                        for (int i = 0; i < hv_newRow.Length; i++)
                        {
                            halconHelp.disp_message(hv_DispWindown, (i + 1), "image", hv_newRow[i].D, hv_newColumn[i].D, "red", "true");
                        }
                        int countMY = hv_newRow.Length, countMX = hv_newColumn.Length, countAY = hv_AxisY.Length, countAX = hv_AxisX.Length;
                        if (countMY < 9 || countMX < 9 || countAY < 9 || countAX < 9 || countAX != countAY || countAX != countMX || countMX != countMY)
                        {
                            m_bHomMat2DOK = false;
                            halconCCD1_event_StatusText("标定相机异常: 标定点过少或个数不匹配", true);
                            GlobalVar.m_bNeedReCalc    = true; //需要重新标定相机
                            GlobalVar.m_timeLast9Point = GlobalVar.m_timeLast9Point.AddHours((GlobalVar.m_CalibSpace + 12) * -1);
                            string strfile = Application.StartupPath + "\\CONFIG\\Config.ini";
                            CommonFunc.Write(ini_Section_TestInfo, ini_Key_Last9Point, GlobalVar.m_timeLast9Point.ToString("yyyy-MM-dd HH:mm:ss.fff"), strfile);
                            return;
                        }
                        HOperatorSet.WriteTuple(hv_newRow, m_pathConfigTup + "\\" + CCDName + "MarkY.tup");
                        HOperatorSet.WriteTuple(hv_newColumn, m_pathConfigTup + "\\" + CCDName + "MarkX.tup");
                        HOperatorSet.WriteTuple(hv_AxisY, m_pathConfigTup + "\\" + CCDName + "AxisY.tup");
                        HOperatorSet.WriteTuple(hv_AxisX, m_pathConfigTup + "\\" + CCDName + "AxisX.tup");
                        GetHomMat2D();
                    }
                    catch (Exception ex)
                    {
                        m_bHomMat2DOK = false;
                        halconCCD1_event_StatusText("标定相机异常: " + ex.ToString(), true);
                        ShowStatusForm("标定相机异常", Color.Red);
                    }
                    #endregion
                }
            }
            catch (Exception ex)
            {
                halconCCD1_event_StatusText("图片处理异常: " + ex.ToString(), true);
            }
            finally
            {
                m_bInHandleImage = false;
                DispCenterPoint();
            }
        }
コード例 #5
0
        public void ReadINI()
        {
            m_fileINI = m_pathConfig + "\\" + "Config.ini";
            string str = "";

            //相机曝光值-制品
            str = CommonFunc.Read(m_CCDName, ini_key_ExposureP, "10000", m_fileINI);
            m_ExposureProduct = Convert.ToInt32(str);
            //相机曝光值-校准片
            str             = CommonFunc.Read(m_CCDName, ini_key_ExposureM, "10000", m_fileINI);
            m_ExposureModel = Convert.ToInt32(str);
            //制品Mark点面积区间
            str = CommonFunc.Read(m_CCDName, ini_key_ProductArea, "100,100", m_fileINI);
            string[] _strPro = str.Split(',');
            if (_strPro.Length == 2)
            {
                AreaProduct[0] = Convert.ToInt32(_strPro[0]);
                AreaProduct[1] = Convert.ToInt32(_strPro[1]);
            }
            else
            {
                AreaProduct = new int[2] {
                    100, 100
                };
            }
            halconHelp.SetMarkArea(AreaProduct); //默认制品Mark点
            //菲林片大Mark点面积区间
            str = CommonFunc.Read(m_CCDName, ini_key_MarkArea, "100,100", m_fileINI);
            string[] _strM = str.Split(',');
            if (_strM.Length == 2)
            {
                AreaMark[0] = Convert.ToInt32(_strM[0]);
                AreaMark[1] = Convert.ToInt32(_strM[1]);
            }
            else
            {
                AreaMark = new int[2] {
                    100, 100
                };
            }
            //菲林片小Mark点面积区间
            str = CommonFunc.Read(m_CCDName, ini_key_PointArea, "100,100", m_fileINI);
            string[] _strP = str.Split(',');
            if (_strP.Length == 2)
            {
                AreaPoint[0] = Convert.ToInt32(_strP[0]);
                AreaPoint[1] = Convert.ToInt32(_strP[1]);
            }
            else
            {
                AreaPoint = new int[2] {
                    100, 100
                };
            }
            halconHelp.SetPointArea(AreaPoint);
            //像素点尺寸
            str       = CommonFunc.Read(m_CCDName, ini_key_UmPixel, "2.224", m_fileINI);
            m_UmPixel = Convert.ToDouble(str);
            //位置
            str       = CommonFunc.Read(m_CCDName, ini_key_Location, "0,0", m_fileINI);
            Location1 = new Point(Convert.ToInt32(str.Split(',')[0]), Convert.ToInt32(str.Split(',')[1]));
            //AVT相机编号
            AVTName = CommonFunc.Read(m_CCDName, ini_key_AVTDevice, "", m_fileINI);
        }