FrmCodeLearn.cs 4.3 KB
 
using URSoldering.Common;
using URSoldering.DeviceLibrary; 
using System; 
using System.IO; 
using System.Threading.Tasks;
using System.Windows.Forms; 

namespace URSoldering.Client
{
    public partial class FrmCodeLearn : FrmBase
    {
        private static  string appPath = Application.StartupPath;
        private static string path = appPath + ConfigAppSettings.GetValue(Setting_Init.CodeParamPath);
        public FrmCodeLearn()
        {
            InitializeComponent();
        } 
        private void btnOpen_Click(object sender, EventArgs e)
        {
            string filePath = FormUtil.getValue(txtParamPath);
            if (File.Exists(filePath))
            {

            }
            else
            {
                try
                {
                    File.Create(filePath);
                }
                catch (Exception ex)
                {
                    LogUtil.error("创建文件:" + filePath + " 失败");
                    MessageBox.Show("创建文件失败!");
                    txtParamPath.SelectAll();
                    txtParamPath.Focus();
                    return;
                }
            }

            //File.Delete(filePath);
            
            string cameraName = cmbCameraList.Text;
            string codeType = this.cmbCodeType.Text;
            int count = cmbCount.SelectedIndex + 1;
            Task.Factory.StartNew(delegate ()
            {
                HDevelopCodeLearn.RunHalcon(this.hWindowControl1.HalconWindow, cameraName, codeType, filePath, count);
            });
               
            FormStatus(true);
        }
        private void FormStatus(bool open)
        {
            btnOpen.Enabled = !open;
            btnStop.Enabled = open; 
            //timer1.Enabled = open;
            //cmbCount.Enabled = !open;
            //cmbCodeType.Enabled = !open;
            //cmbCameraList.Enabled = !open;

        } 
        private void btnStop_Click(object sender, EventArgs e)
        {
            HDevelopCodeLearn.StopLearn();
            FormStatus(false);
        }

        private void FrmCamera_Load(object sender, EventArgs e)
        {
            LogUtil.logBox = this.richTextBox2;
            HDevelopExport.LoadConfig(ConfigAppSettings.GetValue(Setting_Init.CameraName),ConfigAppSettings.GetValue(Setting_Init.CodeType));
            FormStatus(false);

           
            cmbCameraList.DataSource = HDevelopExport.cameraNameList;
            if (HDevelopExport.cameraNameList.Count > 0)
            {
                cmbCameraList.SelectedIndex = 0;
            }
            cmbCodeType.DataSource = HDevelopExport.codeTypeList;
            if (HDevelopExport.codeTypeList.Count > 0)
            {

                cmbCodeType.SelectedIndex = 0;
            }
            else
            {
                cmbCodeType.Items.Add("QR Code");
                cmbCodeType.SelectedIndex = 0;
            } 
            string filePath = path + cmbCodeType.Text + ".dcm";
            txtParamPath.Text = filePath;
            cmbCount.SelectedIndex = 0;
            timer1.Start();
        }

        private void FrmCamera_FormClosed(object sender, FormClosedEventArgs e)
        {
            if (btnStop.Enabled.Equals(true))
            {
                btnStop_Click(null, null);
                LogUtil.logBox = null;
                FormStatus(false);
            }
        }
      
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (HDevelopCodeLearn.IsRun)
            {
                if (btnOpen.Enabled)
                {
                    btnOpen.Enabled = false ;
                }
            }
            else
            {
                if (btnOpen.Enabled.Equals(false))
                {
                    btnOpen.Enabled = true;
                }
            }
             
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void cmbCodeType_SelectedIndexChanged(object sender, EventArgs e)
        { 
            if (cmbCodeType.SelectedIndex >= 0)
            {
                string filePath = path + cmbCodeType.Text + ".dcm";
                txtParamPath.Text = filePath;
            }
        }

        private void btnClearLog_Click(object sender, EventArgs e)
        {
            LogUtil.ClearLog();
        }
    }
}