Exemplo n.º 1
0
 public Variable(Util.TypeVar type, int size, bool onlyread)
 {
     this.type     = type;
     this.onlyread = onlyread;
     this.size     = size;
     this.value    = Util.DefaultValue(type, size);
 }
Exemplo n.º 2
0
        public static void appendVariable(string name, string description, Util.TypeVar type, int size)
        {
            Variable var = new Variable(type, size);

            var.conVariable = Server.Count;
            Context con = new Context(name, description, Util.TypeContext.Variables, var);

            Server.appendContext(con);
            Server.appendChaild(Server.PointVariables);
        }
Exemplo n.º 3
0
        public static void appendVariable(string name, string description, Util.TypeVar type, object value)
        {
            Variable var = new Variable(type);

            var.conVariable = Server.Count;
            var.Device      = 0;
            var.setConstant(value);
            var.ReadOnly = true;
            Context con = new Context(name, description, Util.TypeContext.Variables, var);

            Server.appendContext(con);
            Server.appendChaild(Server.PointConstants);
        }
Exemplo n.º 4
0
        public static void appendVariable(string name, string description, Util.TypeVar type, int size, object value)
        {
            Variable var = new Variable(type, size);

            var.Device = 0;
            if (size == 1)
            {
                var.setConstant(value);
            }
            var.conVariable = Server.Count;
            Context con = new Context(name, description, Util.TypeContext.Variables, var);

            Server.appendContext(con);
            Server.appendChaild(Server.PointModels);
        }
Exemplo n.º 5
0
 public Variable()
 {
     this.type  = Util.TypeVar.Boolean;
     this.value = Util.DefaultValue(type);
 }
Exemplo n.º 6
0
 public Variable(Util.TypeVar type, int size)
 {
     this.type  = type;
     this.size  = size;
     this.value = Util.DefaultValue(type, size);
 }
Exemplo n.º 7
0
 public Variable(Util.TypeVar type)
 {
     this.type  = type;
     this.value = Util.DefaultValue(type);
 }
Exemplo n.º 8
0
        private static void LoadRegistersModBus(string namefile, int icondev, Device dev, Util.TypeDriver drvtype, string Pref) //  функция загрузки регистров Modbus
        {
            XmlDocument regxml = new XmlDocument();

            regxml.Load(namefile);
            DriverModBus driver = (DriverModBus)dev.driver;

            foreach (XmlNode n in regxml.SelectNodes("table/records/record")) // Считывание регистров из указанной подсекции конфигурационного файла
            {
                string name = "", description = "", address = "0", ssize = "1", type = "0", format = "2", unitId = "1";
                foreach (XmlNode m in n.ChildNodes)
                {
                    string attr = XmlExt.GetAttrValue(m, "name"), attr_txt = m.InnerText;

                    switch (attr) //  В зависимости от типа аттрибута, присваивается значение переменной
                    {
                    case "name":
                        name = Pref + attr_txt;
                        break;

                    case "description":
                        description = attr_txt;
                        break;

                    case "address":
                        address = attr_txt;
                        break;

                    case "size":
                        ssize = attr_txt;
                        break;

                    case "type":
                        type = attr_txt;
                        break;

                    case "format":
                        format = attr_txt;
                        break;

                    case "unitId":
                        unitId = attr_txt;
                        break;
                    }
                }
                ushort       size     = ushort.Parse(ssize);
                ushort       iaddress = ushort.Parse(address);
                int          typereg  = int.Parse(type);
                int          iformat  = int.Parse(format);
                Util.TypeVar vtype    = Util.TypeVar.Error;
                if (typereg == 0 || typereg == 1)
                {
                    vtype = Util.TypeVar.Boolean;
                }
                else
                {
                    if (iformat > 0 && iformat <= 7)
                    {
                        vtype = Util.TypeVar.Integer;
                    }
                    if (iformat > 7 && iformat < 11)
                    {
                        vtype = Util.TypeVar.Float;
                    }
                    if (iformat > 10 && iformat < 14)
                    {
                        vtype = Util.TypeVar.Long;
                    }
                    if (iformat > 13 && iformat < 16)
                    {
                        vtype = Util.TypeVar.Double;
                    }
                    if (iformat > 17 && iformat < 20)
                    {
                        vtype = Util.TypeVar.String;
                    }
                }
                /* создаем переменную*/
                Variable.appendVariable(name, description, vtype, size);
                int      ipv = Server.Count - 1;
                Context  con = Server.getContext(ipv);
                Variable var = (Variable)con.defContext;
                if ((typereg == 1 || typereg == 2) && dev.master)
                {
                    var.ReadOnly = true;
                }
                else
                {
                    var.ReadOnly = false;
                }
                var.Device = icondev;
                regModBus regs = new regModBus();
                regs.varcontext = ipv;
                regs.address    = iaddress;
                regs.len        = size;
                regs.regtype    = typereg;
                regs.type       = iformat;
                regs.unitId     = byte.Parse(unitId);
                driver.registers.Add(regs);
                dev.listVariables.Add(ipv);
                Server.setContext(ipv, con);
            }
        }