private void btnFindId_Click(object sender, EventArgs e) { try { btnFindId.Enabled = false; string er = string.Empty; cmbPSoC.Items.Clear(); if (comMon != null) { comMon.OnConed -= new CPSoC4.EventOnConHander(OnCConArgs); comMon = null; } comMon = new CPSoC4(0, cmbICType.Text, para.DllFile); if (!comMon.FindPSocId(out er)) { btnFindId.BackColor = Color.Transparent; comMon = null; ShowStatus(er, true); return; } foreach (string key in comMon.PortName.Keys) { cmbPSoC.Items.Add(key); } cmbPSoC.SelectedIndex = 0; ShowStatus("成功初始化烧录器端口", false); btnFindId.BackColor = Color.Lime; } catch (Exception ex) { ShowStatus(ex.ToString(), true); comMon = null; } finally { btnFindId.Enabled = true; } }
/// <summary> /// 重启端口连接 /// </summary> private void ResetCom() { try { string er = string.Empty; if (!comMon.FindPSocId(out er)) { btnFindId.BackColor = Color.Transparent; comMon.OnConed -= new CPSoC4.EventOnConHander(OnCConArgs); comMon = null; btnCon.Text = "Open"; ShowStatus(er, true); return; } if (!comMon.OpenPSoc(cmbPSoC.Text, out er)) { ShowStatus(er, true); btnCon.Text = "Open"; return; } if (!comMon.InitialPSoc(para, out er)) { ShowStatus(er, true); btnCon.Text = "Open"; return; } } catch (Exception ex) { runLog.Log(ex.ToString(), udcRunLog.ELog.Err); } }