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);
            }
        }
        public bool AddNewS7Connection(string connectionName, int oct1, int oct2,
                                       int oct3, int oct4, int rack, int slot, S7CpuTypeEnum cpuType, bool connectionActivated)
        {
            _logger.Info($"Method for creating new S7 connection fired.");

            return(AddNewS7ConnectionDefinitionToDB(connectionName, oct1, oct2, oct3, oct4,
                                                    rack, slot, cpuType, connectionActivated));
        }
        public static string ConvertToString(S7CpuTypeEnum type)
        {
            switch (type)
            {
            case S7CpuTypeEnum.S7300: return("S7-300");

            case S7CpuTypeEnum.S7400: return("S7-400");

            case S7CpuTypeEnum.S71200: return("S7-1200");

            case S7CpuTypeEnum.S71500: return("S7-1500");

            default: return("Unknown");
            }
        }
Beispiel #4
0
        public int GetS7CpuTypeInt(S7CpuTypeEnum type)
        {
            switch (type)
            {
            case S7CpuTypeEnum.S7300: return(10);

            case S7CpuTypeEnum.S7400: return(20);

            case S7CpuTypeEnum.S71200: return(30);

            case S7CpuTypeEnum.S71500: return(40);

            default: return(0);
            }
        }
        private int ConvertS7CpuTypeToInt(S7CpuTypeEnum type)
        {
            S7CpuTypeConverter converter = new S7CpuTypeConverter();

            return(converter.GetS7CpuTypeInt(type));
        }
        private bool AddNewS7ConnectionDefinitionToDB(string connectionName, int oct1, int oct2,
                                                      int oct3, int oct4, int rack, int slot, S7CpuTypeEnum cpuType, bool connectionActivated)
        {
            _logger.Info($"Method for writing new S7 PLC connection to DB fired. Connection name: {connectionName}.");

            try
            {
                _realm.Write(() =>
                {
                    _realm.Add(new S7PlcConnectionDefinition()
                    {
                        Identity            = GetNewIdentity(new S7PlcConnectionDefinition()),
                        PLCconnectionID     = GetConnectionIDNewIdentity(),
                        ConnectionName      = connectionName,
                        FirstOctet          = oct1,
                        SecondOctet         = oct2,
                        ThirdOctet          = oct3,
                        FourthOctet         = oct4,
                        Rack                = rack,
                        Slot                = slot,
                        CPUtype             = ConvertS7CpuTypeToInt(cpuType),
                        ConnectionActivated = connectionActivated,
                    });
                });

                _logger.Info($"Adding new S7 PLC connection to DB successfull.");

                return(true);
            }
            catch (Exception ex)
            {
                _logger.Error($"Error while trying to add new S7 connection definition to BD: {ex.Message}.");
                return(false);
            }
        }