private void Main_Load(object sender, EventArgs e) { try { #region 读取配置文件 var opcConfig = ConfigurationManagerExtend.SectionsCast <OpcAddressConfiguration>("Address").FirstOrDefault().Value; var tagConfig = ConfigurationManagerExtend.SectionsCast <TagConfiguration>("Tag").FirstOrDefault().Value; groupTriggerUpdateRate = tagConfig.TriggerUpdateRate; groupDataUpdateRate = tagConfig.DataUpdateRate; reconnectEnable = opcConfig.ReconnectEnable; reConnectInterval = opcConfig.ReconnectInterval; #endregion #region OpcClient初始化 if (opcConfig.OpcProtocolByEnum == OpcProtocol.DA) { client = new DaOpc(); } else if (opcConfig.OpcProtocolByEnum == OpcProtocol.UA) { client = new UaOpc(); } client.Init(opcConfig); //断开服务通知 client.OpcStatusChangeHandle += this.OpcServerDisConnected; ConnectOpc(client); #endregion } catch (Exception ex) { //记日志 return; } }
private void Main_Load(object sender, EventArgs e) { try { //增加CLR搜索的路径 CLRPrivatePathInit(); #region 读取配置文件 var opcConfig = ConfigurationManagerExtend.SectionsCast <OpcAddressConfiguration>("Address").FirstOrDefault().Value; var tagConfig = ConfigurationManagerExtend.SectionsCast <TagConfiguration>("Tag").FirstOrDefault().Value; groupTriggerUpdateRate = tagConfig.TriggerUpdateRate; groupDataUpdateRate = tagConfig.DataUpdateRate; tagsQueueNum = tagConfig.TagsQueueNum; reconnectEnable = opcConfig.ReconnectEnable; reConnectInterval = opcConfig.ReconnectInterval; #endregion #region OpcClient初始化 client = OpcFinder(opcConfig.OpcTypeName); client.Init(opcConfig); //断开服务通知 client.OpcStatusChangeHandle += this.OpcServerDisConnected; ConnectOpc(client); #endregion #region 连接远程服务器 ServicesInit(); ConnectServer(); #endregion } catch (Exception ex) { //消息通知 LogHelper.Info("通讯服务器校验结果:" + ex.ToString()); AddMsgToList("通讯服务器校验结果:" + ex.ToString()); return; } }
public UAIniSetting() { InitializeComponent(); //设置默认选择项 opcConfig = ConfigurationManagerExtend.SectionsCast <OpcAddressConfiguration>("Address").FirstOrDefault().Value; tagConfig = ConfigurationManagerExtend.SectionsCast <TagConfiguration>("Tag").FirstOrDefault().Value; this.cmbOpcProtocol.Items.AddRange(new object[] { OpcProtocol.DA, OpcProtocol.UA }); this.cmbUseSecurity.Items.AddRange(new object[] { true, false }); this.cmbReconnectEnable.Items.AddRange(new object[] { true, false }); this.cmbOpcProtocol.SelectedIndexChanged += new System.EventHandler(this.cmbOpcProtocol_SelectedIndexChanged); this.cmbUseSecurity.SelectedIndexChanged += new System.EventHandler(this.cmbUseSecurity_SelectedIndexChanged); this.cmbOpcProtocol.SelectedItem = opcConfig.OpcProtocolByEnum; this.txtIP.Text = opcConfig.DaAddress.Ip; this.cmbServerName.Items.Add(opcConfig.DaAddress.ServerName); this.cmbServerName.SelectedIndex = 0; this.txtUri.Text = opcConfig.UaAddress.Uri; this.txtUserName.Text = opcConfig.UaAddress.UserName; this.txtPassword.Text = opcConfig.UaAddress.Password; this.cmbUseSecurity.SelectedItem = opcConfig.UaAddress.UseSecurity; this.cmbReconnectEnable.SelectedItem = opcConfig.ReconnectEnable; this.cmbReconnectInterval.SelectedItem = opcConfig.ReconnectInterval.ToString(); this.cmbTagsQueueNum.SelectedItem = tagConfig.TagsQueueNum.ToString(); LayoutInit(); }
/// <summary> /// IP设置 /// </summary> private void iniSetting() { UAIniSetting iniS = new UAIniSetting(); if (iniS.ShowDialog() == DialogResult.OK) { var config = ConfigurationManagerExtend.SectionsCast <OpcAddressConfiguration>("Address").FirstOrDefault().Value; MessageBox.Show("重启后配置生效~"); } }
/// <summary> /// 读取配置文件 /// </summary> private void ConfigInit() { opcConfig = ConfigurationManagerExtend.SectionsCast <OpcAddressConfiguration>("Address").FirstOrDefault().Value; if (opcConfig.OpcProtocolByEnum == OpcProtocol.Else) { UAIniSetting iniS = new UAIniSetting(); if (iniS.ShowDialog() == DialogResult.OK) { opcConfig = ConfigurationManagerExtend.SectionsCast <OpcAddressConfiguration>("Address").FirstOrDefault().Value; } else { this.Close(); } } }