private void ReadData(S7PlcConnectionDefinition connection)
        {
            AlarmTagsReader reader = new AlarmTagsReader($"{connection.FirstOctet}.{connection.SecondOctet}.{connection.ThirdOctet}.{connection.FourthOctet}",
                                                         connection.Rack, connection.Slot, _alarmsData[connection.PLCconnectionID], _currentAlarmsList[connection.PLCconnectionID]);

            _alarmsData[connection.PLCconnectionID] = reader.CheckAlarms(_alarmsData[connection.PLCconnectionID]);
        }
Beispiel #2
0
        private void SetHeadingProperties()
        {
            if (SelectedShortPLCconnection != null)
            {
                int manufacturer = SelectedShortPLCconnection.CPUmanufacturer;
                if (manufacturer == 1)
                {
                    S7PlcConnectionDefinition definition = _originalListOfS7connections.Single(x => x.PLCconnectionID == SelectedShortPLCconnection.PLCconnectionID);
                    CurrentConnectionIP = $"{definition.FirstOctet}.{definition.SecondOctet}.{definition.ThirdOctet}.{definition.FourthOctet}";
                    ConnectionActivated = definition.ConnectionActivated;
                    S7CpuTypeConverter converter = new S7CpuTypeConverter();
                    CpuType = converter.GetS7TypeEnum(definition.CPUtype).ToString();

                    GetAlarmsForS7Connection(definition.PLCconnectionID);
                }

                MultipleAlarmsDeletionButtonEnabled = _canModifyAlarm;
                AddingNewAlarmsEnabled = _canModifyAlarm;
                EnableFiltering        = true;
            }
            else
            {
                CurrentConnectionIP = "_._._._";
                ConnectionActivated = false;
                CpuType             = "-----";

                AddingNewAlarmsEnabled = false;
                MultipleAlarmsDeletionButtonEnabled = false;
                EnableFiltering = false;

                AlarmsForSelectedS7Connection.Clear();
            }
        }
        public bool ModifyS7Connection(int identity, int connectionID, int firstOctet, int secondOctet, int rhirdOctet,
                                       int fourthOctet, int rack, int slot, S7CpuTypeEnum cpuType, bool connectionActivated)
        {
            _logger.Info($"Method for modifying S7 connection fired. Identity = {identity}, connection ID = {connectionID}.");

            try
            {
                S7PlcConnectionDefinition definition = _realm.All <S7PlcConnectionDefinition>().
                                                       Where(x => x.Identity == identity && x.PLCconnectionID == connectionID).ToList().First();

                using (var trans = _realm.BeginWrite())
                {
                    definition.FirstOctet          = firstOctet;
                    definition.SecondOctet         = secondOctet;
                    definition.ThirdOctet          = rhirdOctet;
                    definition.FourthOctet         = fourthOctet;
                    definition.Rack                = rack;
                    definition.Slot                = slot;
                    definition.CPUtype             = ConvertS7CpuTypeToInt(cpuType);
                    definition.ConnectionActivated = connectionActivated;
                    trans.Commit();
                }

                _logger.Info($"Modification of S7 PLC connection successfull.");

                return(true);
            }
            catch (Exception ex)
            {
                _logger.Error($"Error while trying to modify S7 PLC connection: {ex.Message}.");
                return(false);
            }
        }
Beispiel #4
0
        public void ModifyS7Connection(int identity)
        {
            S7PlcConnectionDefinition definition = _originalList.Where(x => x.Identity == identity).ToList().First();

            _logger.Info($"User pressed button for opening window for modifying existing S7 PLC connections. Connection Identity: {definition.Identity}, connection ID: {definition.PLCconnectionID}.");

            if (definition != null)
            {
                _logger.Info($"Opening window for modifying existing S7 PLC connection.");

                S7ConnectionCreatorViewModel s7ccvm = new S7ConnectionCreatorViewModel(true, definition, _realmProvider);
                _manager.ShowDialog(s7ccvm);
                ReadSavedS7Connections();
            }
        }
Beispiel #5
0
        private void AssignDataAtModification(S7PlcConnectionDefinition connection)
        {
            S7CpuTypeConverter converter = new S7CpuTypeConverter();

            SelectedCPUtype = CpuTypes.Single(x => x.CPUtype == converter.GetS7TypeEnum(connection.CPUtype));

            ConnectionName      = connection.ConnectionName;
            FirstOctet          = connection.FirstOctet.ToString();
            SecondOctet         = connection.SecondOctet.ToString();
            ThirdOctet          = connection.ThirdOctet.ToString();
            FourthOctet         = connection.FourthOctet.ToString();
            Rack                = connection.Rack.ToString();
            Slot                = connection.Slot.ToString();
            ConnectionActivated = connection.ConnectionActivated;

            _logger.Info($"Data for modifying existing S7 connection assigned. Connection Name: {connection.ConnectionName}, connection ID: {connection.PLCconnectionID}.");
        }
Beispiel #6
0
        public AlarmExportManagerViewModel(IWindowManager manager, IRealmProvider realmProvider)
        {
            _realmProvider = realmProvider;
            _logger        = NLog.LogManager.GetCurrentClassLogger();
            _manager       = manager;

            _originalListOfS7connections = new List <S7PlcConnectionDefinition>();
            _currentS7PLCconnection      = new S7PlcConnectionDefinition();
            _alarmProfilesList           = new List <AlarmProfileDefinition>();
            _smsRecipientsGroupsList     = new List <SMSrecipientsGroupDefinition>();
            ExportButtonsEnabled         = false;

            //default filepath
            _filePath = $"{Environment.GetFolderPath(Environment.SpecialFolder.Desktop)}\\Export";

            ReadAllConnectionsAlgorithm();

            _logger.Info($"Alarm export manager window created.");
        }
        public bool DeleteExistingS7connection(int identity, int connectionID)
        {
            _logger.Info($"Method for deleting S7 PLC connection from DB fired. Identity = {identity}, connectionID = {connectionID}.");

            try
            {
                S7PlcConnectionDefinition definition = _realm.All <S7PlcConnectionDefinition>().Single(x => x.Identity == identity && x.PLCconnectionID == connectionID);
                using (var trans = _realm.BeginWrite())
                {
                    _realm.Remove(definition);
                    trans.Commit();
                }

                _logger.Info($"Deletion of S7 PLC connection successfull.");

                return(true);
            }
            catch (Exception ex)
            {
                _logger.Error($"Error while trying to delete existing S7 connection: {ex.Message}.");
                return(false);
            }
        }
Beispiel #8
0
        /// <summary>
        /// Constructor: you can create new connection, or modify eisting one (S7 connection)
        /// </summary>
        /// <param name="modify">If new connection, pass false, if modify, pass true</param>
        /// <param name="connection">Only if modifying connection, pass existing one here</param>
        public S7ConnectionCreatorViewModel(bool modify, S7PlcConnectionDefinition connection, IRealmProvider realmProvider)
        {
            _realmProvider = realmProvider;
            _logger        = NLog.LogManager.GetCurrentClassLogger();
            CreateListOfCPUtypes();

            if (!modify) //new connection
            {
                AddingNew      = true;
                Modification   = false;
                ConnectionName = "";

                _logger.Info($"S7 connection creator window in mode for new connection created.");
            }
            else //modification
            {
                AddingNew           = false;
                Modification        = true;
                _modifiedConnection = connection;
                AssignDataAtModification(connection);

                _logger.Info($"S7 connection creator window in mode for editing existing connection created.");
            }
        }
Beispiel #9
0
 private void AssignCurrentS7PLCconnection()
 {
     _currentS7PLCconnection = _originalListOfS7connections.Where(x => x.Identity == SelectedShortPLCconnection.Identity &&
                                                                  x.PLCconnectionID == SelectedShortPLCconnection.PLCconnectionID).First();
 }