Exemple #1
0
 protected DataTemplateComponent(string name, object reference, DataTemplateComponentType type, CommunicationInterfaceComponent component)
 {
     Name = name;
     Reference = reference;
     _type = type;
     Component = component;
 }
 public static CommunicationInterfaceVariable CreateVariable(string name, int pos, int posBit,
     CommunicationInterfaceComponent.VariableType type, int length)
 {
     switch (type)
     {
         case CommunicationInterfaceComponent.VariableType.Bit:
             return new CiBit(name, pos, posBit, type, false);
         case CommunicationInterfaceComponent.VariableType.Byte:
             return new CiByte(name, pos, type, 0);
         case CommunicationInterfaceComponent.VariableType.Char:
             return new CiChar(name, pos, type, ' ');
         case CommunicationInterfaceComponent.VariableType.Word:
             return new CiWord(name, pos, type, new BitArray(2));
         case CommunicationInterfaceComponent.VariableType.DoubleWord:
             var bitArrays = new BitArray[2];
             bitArrays[0] = new BitArray(2);
             bitArrays[1] = new BitArray(2);
             return new CiDoubleWord(name, pos, type, bitArrays);
         case CommunicationInterfaceComponent.VariableType.Integer:
             return new CiInteger(name, pos, type, 0);
         case CommunicationInterfaceComponent.VariableType.DoubleInteger:
             return new CiDoubleInteger(name, pos, type, 0);
         case CommunicationInterfaceComponent.VariableType.Real:
             return new CiReal(name, pos, type, 0.0f);
         case CommunicationInterfaceComponent.VariableType.String:
             return new CiString(name, pos, type, "", length);
         default:
             throw new FactoryException("Cannot create a variable");
     }
 }
Exemple #3
0
 public void Add(uint id, string name, CommunicationInterfaceComponent.VariableType type, InterfaceAssignment.Direction direction, string[] assignment)
 {
     Children.Add(new InterfaceAssignment
     {
         Id = id,
         VariableDirection = direction,
         Name = name,
         Type = type,
         Assignment = assignment[id]
     });
 }
        public static DataTemplateComponent ComunicationInterfaceToTemplate(
            CommunicationInterfaceComponent communicationInterfaceComponent)
        {
            var lastName = communicationInterfaceComponent.LastName.Replace('[', '_');
            lastName = lastName.Replace(']', '_');

            DataTemplateComponent newComposite = new DataTemplateComposite(lastName, null, null);

            if (communicationInterfaceComponent.GetType() == typeof (CommunicationInterfaceComposite))
            {
                foreach (var component in ((CommunicationInterfaceComposite)communicationInterfaceComponent).Cast<CommunicationInterfaceComponent>())
                {
                    newComposite.Add(ComunicationInterfaceToTemplate(component));
                }
            }
            else
            {
                newComposite = new DataTemplateLeaf(lastName, null, DataTemplateComponent.DataTemplateComponentType.Assignment, communicationInterfaceComponent);
            }

            return newComposite;
        }
 public override void Remove(CommunicationInterfaceComponent c)
 {
     throw new CompositeException("Error: Cannot remove from a single variable");
 }
 public override void Add(CommunicationInterfaceComponent c)
 {
     throw new CompositeException("Error: Cannot add to a single variable");
 }
 public override void Remove(CommunicationInterfaceComponent component)
 {
     _children.Remove(component);
 }
 public override void Add(CommunicationInterfaceComponent component)
 {
     component.Parent = this;
     component.TypeOfInterface = TypeOfInterface;
     _children.Add(component);
 }
 public abstract void Remove(CommunicationInterfaceComponent c);
 public abstract void Add(CommunicationInterfaceComponent c);
Exemple #11
0
 public DataTemplateComposite(string name, object reference, CommunicationInterfaceComponent component)
     : base(name, reference, DataTemplateComponentType.Composite, component)
 {
 }
 private static VariableType GetType(CommunicationInterfaceComponent communicationInterfaceVariable)
 {
     switch (communicationInterfaceVariable.TypeOfVariable)
     {
         case CommunicationInterfaceComponent.VariableType.Bit:
             return VariableType.Bit;
         case CommunicationInterfaceComponent.VariableType.Byte:
             return VariableType.Byte;
         case CommunicationInterfaceComponent.VariableType.Integer:
             return VariableType.Integer;
         case CommunicationInterfaceComponent.VariableType.DoubleInteger:
             return VariableType.DoubleInteger;
         case CommunicationInterfaceComponent.VariableType.Real:
             return VariableType.Real;
         default:
             throw new Exception("This type of CommunicationInterfaceVariable is not handled");
     }
 }
        public CommunicationInterfaceComposite InitializeInterface(uint id, CommunicationInterfaceComponent.InterfaceType type, CommunicationInterfacePath pathFile, object sender)
        {
            var readAreaFound = false;
            var writeAreaFound = false;

            var readAddress = new Address { ByteAddress = 0, BitAddress = 0, };
            var writeAddress = new Address { ByteAddress = 0, BitAddress = 0, };

            var readByteOverloaded = false;
            var writeByteOverloaded = false;

            var interfaceComposite = new CommunicationInterfaceComposite(type.ToString()) { Owner = sender, TypeOfInterface = type };
            var reader = new StreamReader(pathFile.Path[id]);

            var previousReadType = "";
            var previousWriteType = "";

            string line;
            string[] words;

            switch (type)
            {
                case CommunicationInterfaceComponent.InterfaceType.ReadInterface:
                    while (true)
                    {
                        line = reader.ReadLine();
                        if (line == null) break;
                        words = line.Split(';');
                        if (readAreaFound && words[0] == "#END") break;
                        if (readAreaFound)
                        {
                            var readByteOverloadedAux = readByteOverloaded;
                            readAddress = CheckRules(previousReadType, words[1], readByteOverloadedAux, readAddress,
                                out readByteOverloaded);

                            AddToInterface(interfaceComposite, CommunicationInterfaceFactory.CreateVariable(words[0],
                                readAddress.ByteAddress, readAddress.BitAddress, StringToVariableType(words[1]),
                                GetLength(words[1])));

                            readAddress = CreateNewAddress(readAddress, words[1]);
                            previousReadType = words[1];
                        }
                        if (words[0] == "#READ") readAreaFound = true;
                    }
                    if (!readAreaFound)
                    {
                        throw new Exception("Read Area not found");
                    }
                    break;
                case CommunicationInterfaceComponent.InterfaceType.WriteInterface:
                    while (true)
                    {
                        line = reader.ReadLine();
                        if (line == null) break;
                        words = line.Split(';');
                        if (writeAreaFound && words[0] == "#END") break;
                        if (writeAreaFound)
                        {
                            var writeByteOverloadedAux = writeByteOverloaded;
                            writeAddress = CheckRules(previousWriteType, words[1], writeByteOverloadedAux, writeAddress,
                                out writeByteOverloaded);

                            AddToInterface(interfaceComposite, CommunicationInterfaceFactory.CreateVariable(words[0],
                                writeAddress.ByteAddress, writeAddress.BitAddress, StringToVariableType(words[1]),
                                GetLength(words[1])));

                            writeAddress = CreateNewAddress(writeAddress, words[1]);
                            previousWriteType = words[1];
                        }
                        if (words[0] == "#WRITE") writeAreaFound = true;
                    }
                    if (!writeAreaFound)
                    {
                        throw new Exception("Write Area not found");
                    }
                    break;
                default:
                    throw new Exception("Error: Wrong interface type.");
            }
            return interfaceComposite;
        }