/// <summary> /// Connects to the OPC server. /// </summary> private async Task <bool> ConnectToOpcServer() { try { OpcUaHelper helper = new OpcUaHelper(appDirs, kpNum, OpcUaHelper.RuntimeKind.View) { CertificateValidation = CertificateValidator_CertificateValidation }; if (await helper.ConnectAsync(deviceConfig.ConnectionOptions)) { opcSession = helper.OpcSession; return(true); } else { opcSession = null; return(false); } } catch (Exception ex) { ScadaUiUtils.ShowError(KpPhrases.ConnectServerError + ":" + Environment.NewLine + ex.Message); return(false); } finally { SetConnButtonsEnabled(); } }
/// <summary> /// Connects to the OPC server. /// </summary> private void ConnectToOpcServer() { try { OpcUaHelper helper = new OpcUaHelper(AppDirs, Number, OpcUaHelper.RuntimeKind.Logic) { CertificateValidation = CertificateValidator_CertificateValidation, WriteToLog = WriteToLog }; connected = helper.ConnectAsync(deviceConfig.ConnectionOptions, ReqParams.Timeout).Result; autoAccept = autoAccept || helper.AutoAccept; opcSession = helper.OpcSession; opcSession.KeepAlive += OpcSession_KeepAlive; opcSession.Notification += OpcSession_Notification; } catch (Exception ex) { connected = false; WriteToLog((Localization.UseRussian ? "Ошибка при соединении с OPC-сервером: " : "Error connecting OPC server: ") + ex); } }