Exemplo n.º 1
0
        /// <summary>
        /// Очистить канал от старой привязки
        /// </summary>
        private void ResetChannel()
        {
            int propertyNumber = (int)Eplan.EplApi.DataModel.Properties
                                 .Article.ARTICLE_TYPENR;
            string name       = GetSelectedIOModuleArticleProperty(propertyNumber);
            var    moduleInfo = new IOModuleInfo();

            moduleInfo = moduleInfo.GetIOModuleInfo(name, out _);

            Dictionary <string, string> devicesComments =
                EplanDeviceManager.GetAssigment(SelectedClampFunction,
                                                moduleInfo, ResetDevicesChannel);

            foreach (KeyValuePair <string, string> pair in devicesComments)
            {
                var deviceName    = pair.Key;
                var deviceComment = pair.Value;

                var device = DeviceManager.GetInstance().GetDevice(deviceName);

                string channelName = EplanDeviceManager.GetInstance().
                                     GetChannelNameForIOLinkModuleFromString(deviceComment);

                device.ClearChannel(moduleInfo.AddressSpaceType,
                                    deviceComment, channelName);
            }
        }
Exemplo n.º 2
0
        public void TestGetModuleInfo(string expectedModuleInfoName,
                                      string actualModuleInfoName)
        {
            const int countOfModulesInfoForTest = 5;

            FillRandomModulesInfo(countOfModulesInfoForTest);
            if (!string.IsNullOrEmpty(actualModuleInfoName))
            {
                GetModuleInfoForTest(actualModuleInfoName);
            }

            var moduleInfo = IOModuleInfo
                             .GetModuleInfo(actualModuleInfoName, out bool isStub);

            if (moduleInfo != IOModuleInfo.Stub)
            {
                Assert.Multiple(() =>
                {
                    Assert.AreEqual(expectedModuleInfoName, moduleInfo.Name);
                    Assert.IsFalse(isStub);
                });
            }
            else
            {
                Assert.Multiple(() =>
                {
                    Assert.AreEqual(IOModuleInfo.Stub.Name, moduleInfo.Name);
                    Assert.IsTrue(isStub);
                });
            }
        }
Exemplo n.º 3
0
        public void TestClone()
        {
            IOModuleInfo actualModuleInfo = GetModuleInfoForTest();
            var          cloned           = (IOModuleInfo)actualModuleInfo.Clone();

            bool isEqual =
                actualModuleInfo.AddressSpaceType == cloned.AddressSpaceType &&
                actualModuleInfo.AICount == cloned.AICount &&
                actualModuleInfo.AOCount == cloned.AOCount &&
                actualModuleInfo.DICount == cloned.DICount &&
                actualModuleInfo.DOCount == cloned.DOCount &&
                actualModuleInfo.ChannelAddressesIn
                .SequenceEqual(cloned.ChannelAddressesIn) &&
                actualModuleInfo.ChannelAddressesOut
                .SequenceEqual(cloned.ChannelAddressesOut) &&
                actualModuleInfo.ChannelClamps
                .SequenceEqual(cloned.ChannelClamps) &&
                actualModuleInfo.Description == cloned.Description &&
                actualModuleInfo.GroupName == cloned.GroupName &&
                actualModuleInfo.ModuleColor == actualModuleInfo.ModuleColor &&
                actualModuleInfo.Name == cloned.Name &&
                actualModuleInfo.Number == cloned.Number &&
                actualModuleInfo.TypeName == cloned.TypeName;

            Assert.IsTrue(isEqual);
        }
Exemplo n.º 4
0
        public void TestSetGetModuleColor(string expected, string actual)
        {
            IOModuleInfo testModule = GetModuleInfoForTest();

            testModule.ModuleColor = Color.FromName(actual);
            Assert.AreEqual(Color.FromName(expected), testModule.ModuleColor);
        }
Exemplo n.º 5
0
        public void TestSetGetGroupName(string expected, string actual)
        {
            IOModuleInfo testModule = GetModuleInfoForTest();

            testModule.GroupName = actual;
            Assert.AreEqual(expected, testModule.GroupName);
        }
Exemplo n.º 6
0
        public void TestSetGetChannelAddressesIn(int[] expected, int[] actual)
        {
            IOModuleInfo testModule = GetModuleInfoForTest();

            testModule.ChannelAddressesIn = actual;
            Assert.AreEqual(expected, testModule.ChannelAddressesIn);
        }
Exemplo n.º 7
0
        public void TestSetGetDOCount(int expected, int actual)
        {
            IOModuleInfo testModule = GetModuleInfoForTest();

            testModule.DOCount = actual;
            Assert.AreEqual(expected, testModule.DOCount);
        }
Exemplo n.º 8
0
        public void TestSetGetChannelClamps(int[] expected, int[] actual)
        {
            IOModuleInfo testModule = GetModuleInfoForTest();

            testModule.ChannelClamps = actual;
            Assert.AreEqual(expected, testModule.ChannelClamps);
        }
Exemplo n.º 9
0
        public void TestSetGetDescription(string expected, string actual)
        {
            IOModuleInfo testModule = GetModuleInfoForTest();

            testModule.Description = actual;
            Assert.AreEqual(expected, testModule.Description);
        }
Exemplo n.º 10
0
        public void TestSetGetNumber(int expected, int actual)
        {
            IOModuleInfo testModule = GetModuleInfoForTest();

            testModule.Number = actual;
            Assert.AreEqual(expected, testModule.Number);
        }
Exemplo n.º 11
0
        public void TestSetGetAddressSpaceType(
            IOModuleInfo.ADDRESS_SPACE_TYPE expected,
            IOModuleInfo.ADDRESS_SPACE_TYPE actual)
        {
            IOModuleInfo testModule = GetModuleInfoForTest();

            testModule.AddressSpaceType = actual;
            Assert.AreEqual(expected, testModule.AddressSpaceType);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Привязать канал
        /// </summary>
        private void BindChannel()
        {
            if (SelectedIOModuleFunction == null)
            {
                return;
            }

            var regex = new Regex(IOModuleNamePattern);
            var match = regex.Match(SelectedIOModuleFunction.VisibleName);

            if (match.Success == false)
            {
                return;
            }

            int propertyNumber = (int)Eplan.EplApi.DataModel
                                 .Properties.Article.ARTICLE_TYPENR;
            string name = GetSelectedIOModuleArticleProperty(propertyNumber);

            var deviceNumber = Convert.ToInt32(match.Groups["n"].Value);
            var moduleNumber = deviceNumber % 100;
            int nodeNumber;
            var clampNumber = SelectedClampFunction.Properties
                              .FUNC_ADDITIONALIDENTIFYINGNAMEPART.ToInt();

            // Есть ли PXC A1 в проекте
            if (IOManager.GetInstance().IONodes[0].Type ==
                IONode.TYPES.T_PHOENIX_CONTACT_MAIN)
            {
                // Если есть "A1", то учитываем, что он первый
                nodeNumber = deviceNumber / 100;
            }
            else
            {
                // Если нету, оставляем как было
                nodeNumber = deviceNumber / 100 - 1;
            }

            var moduleInfo = new IOModuleInfo();

            moduleInfo = moduleInfo.GetIOModuleInfo(name, out _);
            var logicalPort = Array.IndexOf(moduleInfo.ChannelClamps,
                                            clampNumber) + 1;
            var moduleOffset = IOManager.GetInstance()
                               .IONodes[nodeNumber].
                               IOModules[moduleNumber - 1].InOffset;

            SelectedChannel.SetChannel(nodeNumber, moduleNumber,
                                       clampNumber, deviceNumber, logicalPort, moduleOffset);
        }
Exemplo n.º 13
0
        private static IOModuleInfo GetModuleInfoForTest(
            string expectedName = null)
        {
            const int    IntStub   = 0;
            const string StrStub   = "";
            const string ColorStub = "White";

            string name = expectedName ?? string.Empty;

            IOModuleInfo.AddModuleInfo(IntStub, name, StrStub, IntStub,
                                       StrStub, StrStub, new int[0], new int[0], new int[0], IntStub,
                                       IntStub, IntStub, IntStub, ColorStub);

            return(IOModuleInfo.GetModuleInfo(name, out _));
        }
Exemplo n.º 14
0
        private static void FillRandomModulesInfo(int count,
                                                  int repeatableCount = 0)
        {
            int currentCount           = count;
            int currentRepeatableCount = repeatableCount;
            int enumSize = Enum
                           .GetValues(typeof(IOModuleInfo.ADDRESS_SPACE_TYPE)).Length;
            List <KnownColor> colors = Enum.GetValues(typeof(KnownColor))
                                       .Cast <KnownColor>()
                                       .ToList();

            while (currentCount > 0)
            {
                int    n                   = GetRandomIntNumber();
                string name                = GetRandomString(5);
                string description         = GetRandomString(10);
                int    addressSpaceTypeNum = new Random().Next(0, enumSize);
                string typeName            = GetRandomString(10);
                string groupName           = GetRandomString(7);
                int[]  channelClamps       = GetRandomIntArr();
                int[]  channelAddressesIn  = GetRandomIntArr();
                int[]  channelAddressesOut = GetRandomIntArr();
                int    DOCount             = GetRandomIntNumber();
                int    DICount             = GetRandomIntNumber();
                int    AOCount             = GetRandomIntNumber();
                int    AICount             = GetRandomIntNumber();
                string color               = colors[new Random().Next(0, colors.Count - 1)]
                                             .ToString();

                while (currentRepeatableCount > 1)
                {
                    IOModuleInfo.AddModuleInfo(n, name, description,
                                               addressSpaceTypeNum, typeName, groupName,
                                               channelClamps, channelAddressesIn, channelAddressesOut,
                                               DOCount, DICount, AOCount, AICount, color);

                    currentRepeatableCount--;
                    currentCount--;
                }

                IOModuleInfo.AddModuleInfo(n, name, description,
                                           addressSpaceTypeNum, typeName, groupName,
                                           channelClamps, channelAddressesIn, channelAddressesOut,
                                           DOCount, DICount, AOCount, AICount, color);

                currentCount--;
            }
        }
Exemplo n.º 15
0
        public void TestSetGetName(string expected, string actual)
        {
            IOModuleInfo testModule = GetModuleInfoForTest(actual);

            Assert.AreEqual(expected, testModule.Name);
        }