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(); } } }
private void btnEnter_Click(object sender, EventArgs e) { //OPC设置 OpcProtocol iOpcProtocol = (OpcProtocol)cmbOpcProtocol.SelectedItem; opcConfig.OpcProtocol = Convert.ToInt32(iOpcProtocol); opcConfig.OpcTypeName = txtTypeName.Text.ToString(); opcConfig.ReconnectInterval = Convert.ToInt32(cmbReconnectInterval.SelectedItem); opcConfig.ReconnectEnable = (Boolean)cmbReconnectEnable.SelectedItem; if (iOpcProtocol == OpcProtocol.DA) { var iIp = txtIP.Text; var iServerName = cmbServerName.Text; opcConfig.DaAddress.Ip = iIp.ToString(); opcConfig.DaAddress.ServerName = iServerName.ToString(); } else if (iOpcProtocol == OpcProtocol.UA) { var iUri = txtUri.Text; var iUserName = txtUserName.Text; var iPassword = txtPassword.Text; var iUseSecurity = cmbUseSecurity.SelectedItem; opcConfig.UaAddress.Uri = iUri.ToString(); opcConfig.UaAddress.UserName = iUserName.ToString(); opcConfig.UaAddress.Password = iPassword.ToString(); opcConfig.UaAddress.UseSecurity = (Boolean)iUseSecurity; } else { MessageBox.Show("请选择UA DA后重试!"); return; } //Tag设置 tagConfig.TagsQueueNum = Convert.ToInt32(cmbTagsQueueNum.SelectedItem); //保存设置 try { ConfigurationManagerExtend.SectionSave(opcConfig, "default", "Address"); ConfigurationManagerExtend.SectionSave(tagConfig, "default", "Tag"); this.DialogResult = DialogResult.OK; } catch (Exception ee) { MessageBox.Show(string.Format("保存失败!内容:{0}", ee.Message), "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } }