首页 > 其他分享 >工业互联网-基于OPC 的简单数采系统设计之二

工业互联网-基于OPC 的简单数采系统设计之二

时间:2023-10-02 21:00:48浏览次数:34  
标签:AssyL2OP20CUP 之二 station stp 数采 OPC ent op20Cup TagType

1、客户端结构

客户端主界面Load方法从配置文件中获取产线编号,使用LineBuilder类静态方法Build创建单例引擎,初始化引擎,

引擎中创建客户端到服务端连接,包含mesService 和opcService,其中opcService是双向通讯。

LineBuilder类接着便初始化产线站点,站点属性,站点脚本。

工业互联网-基于OPC 的简单数采系统设计之二_引擎


LineBuilder类

public static class LineBuilder
    {
        //1)创建产线
        //2)创建各个站点
        //3)创建站点属性
        //4)创建站点脚本
        //5)创建站点脚本规则
        //6)装配好产线、站点、属性、脚本

        public static Engine engine;
        //private static List<Property> properties = new List<Property>();
        //private static List<Station> allStations = new List<Station>();

        public static Line Build(int line_id)
        {
            DateTime now = DateTime.Now;
            engine = Engine.CreateInstance();
            engine.Init();
            mes_ent_info ent = engine.conmetMesService.GetEntInfoByIdName(line_id, null,  null);
            Line line2 = new Line(Guid.NewGuid().ToString(), ent.ent_name, ent.ent_description);
            line2.LineId = ent.ent_id;
            line2.Continer = engine;
            
            engine.Line = line2;

            buildAllStation(line2);
            
            //var op20Cup = buildStation("192.168.1.20", Guid.NewGuid().ToString(), "AssyL2OP20CUP", "OP20CUP", line2);
            //buildProperty("stp_partNum1", "AssyL2OP20CUP.AssyL2OP20CUP.stp_partNum1", op20Cup, TagType.Trigger, DataType.String);
            //var op20Cup_stp_partSerial1Prop = buildProperty("stp_partSerial1", "AssyL2OP20CUP.AssyL2OP20CUP.stp_partSerial1", op20Cup, TagType.Trigger, DataType.String);
            //var op20Cup_PartStatus1Prop = buildProperty("stp_partStatus1", "AssyL2OP20CUP.AssyL2OP20CUP.stp_partStatus1", op20Cup, TagType.Trigger, DataType.Int);
            //buildProperty("stp_prod1Arrive", "AssyL2OP20CUP.AssyL2OP20CUP.stp_prod1Arrive", op20Cup, TagType.Trigger, DataType.Bool);
            //buildProperty("stp_prod1Start", "AssyL2OP20CUP.AssyL2OP20CUP.stp_prod1Start", op20Cup, TagType.Trigger, DataType.Bool);
            //buildProperty("stp_prod1Finish", "AssyL2OP20CUP.AssyL2OP20CUP.stp_prod1Finish", op20Cup, TagType.Trigger, DataType.Bool);
            //buildProperty("stp_prod1Leave", "AssyL2OP20CUP.AssyL2OP20CUP.stp_prod1Start", op20Cup, TagType.Trigger, DataType.Bool);
            //buildProperty("stp_workOrder1", "AssyL2OP20CUP.AssyL2OP20CUP.stp_workOrder1", op20Cup, TagType.Trigger, DataType.String);

            //buildProperty("stp_upFinalPre", "AssyL2OP20CUP.AssyL2OP20CUP.stp_upFinalPre", op20Cup, TagType.Normal, DataType.Float);
            //buildProperty("rec_downPreHeadDwelltime", "AssyL2OP20CUP.AssyL2OP20CUP.rec_downPreHeadDwelltime", op20Cup, TagType.Normal, DataType.Float);
            //buildProperty("rec_downPreHeadPre", "AssyL2OP20CUP.AssyL2OP20CUP.rec_downPreHeadPre", op20Cup, TagType.Normal, DataType.Float);
            //buildProperty("rec_downPreHeadPreHiLimit", "AssyL2OP20CUP.AssyL2OP20CUP.rec_downPreHeadPreHiLimit", op20Cup, TagType.Normal, DataType.Float);
            //buildProperty("rec_downPreHeadPreLoLimit", "AssyL2OP20CUP.AssyL2OP20CUP.rec_downPreHeadPreLoLimit", op20Cup, TagType.Normal, DataType.Float);
            //buildProperty("rec_upPreHeadPre", "AssyL2OP20CUP.AssyL2OP20CUP.rec_upPreHeadPre", op20Cup, TagType.Normal, DataType.Float);
            //buildProperty("rec_upPreHeadPreHiLimit", "AssyL2OP20CUP.AssyL2OP20CUP.rec_upPreHeadPreHiLimit", op20Cup, TagType.Normal, DataType.Float);
            //buildProperty("rec_upPreHeadPreLoLimit", "AssyL2OP20CUP.AssyL2OP20CUP.rec_upPreHeadPreLoLimit", op20Cup, TagType.Normal, DataType.Float);
            //buildProperty("stp_downFinalPre", "AssyL2OP20CUP.AssyL2OP20CUP.stp_downFinalPre", op20Cup, TagType.Normal, DataType.Float);


            //Script_partSerialChange op20partSerialChange = new Script_partSerialChange(op20Cup);
            //Script_stp_partStatus1Change op20partStatus1Change = new Script_stp_partStatus1Change(op20Cup);
            //Script_onTrueTest op20OnTrueTest = new Script_onTrueTest(op20Cup);
            //Script_WhileTrueTest op20WhileTrueTest = new Script_WhileTrueTest(op20Cup);
            //op20Cup.Scripts.AddRange(new List<Script>() { op20partSerialChange, op20partStatus1Change, op20OnTrueTest, op20WhileTrueTest });

            //line2.Stations.AddRange(new List<Station>() { op20Cup });

            return null;
        }

        private static Station buildStation(string ip, string sid, string name, string des, Line line)
        {
            var station = new Station(sid, name, des);
            station.Adress = ip;
            station.Continer = line;
            station.CurrState = State.Idle;
            station.Enable = true;
            return station;
        }

        
        private static void buildAllStation(Line line)
        {
            List<mes_ent_info> entList = engine.conmetMesService.GetEntInfoByParentId(line.LineId);
            
            foreach (var ent in entList)
            {
                var station = buildStation("", ent.ent_id.ToString(), ent.ent_name, ent.ent_description, line);
                //allStations.Add(station);
                line.Stations.Add(station);
                buildAllPropertys(station);
                
            }
            if (System.IO.File.Exists("Conmet.MES.Scripts.dll") == false)
            {
                engine.messageQueue.Enqueue($"Error:Class:LineBuilder,Method:buildAllStation-buildAllScript,Param:[{line.Name}],Msg:Not Find 'Conmet.MES.Scripts.dll'");
                return;
            }
            Assembly asm = Assembly.Load("Conmet.MES.Scripts");//.GetExecutingAssembly();
            foreach (var station in line.Stations)
            {
                buildAllScript(asm, station);
            }
        }

        public static void buildAllScript(Assembly asm, Station station)
        {
            var ent_scripts = engine.conmetMesService.GetEntScriptByEntId(int.Parse(station.SID), null, 1, null, 1);
            foreach(var script in ent_scripts)
            {
                //engine.messageQueue.Enqueue($"Info:Class:LineBuilder,Method:buildAllScript,NeedAdd:{ script.class_path}");
                object[] parameters = new object[1];
                parameters[0] = station;
                Object obj = asm.CreateInstance(script.class_path, true, BindingFlags.Default, null, parameters, null, null);
                if(obj is Script)
                {
                    Script sc = obj as Script;
                    sc.Name = script.name;
                    station.Scripts.Add(sc);
                    engine.messageQueue.Enqueue($"Info:Class:LineBuilder,Method:buildAllScript,Add:{ sc.Name}");
                }
                //script.class_path;
            }
        }

        public static List<Property> buildAllPropertys(Station station)
        {
            var ent_propertys = engine.conmetMesService.GetPropertys(int.Parse(station.SID), null, null, 1);
            var ent_tags = engine.opcservice.GetOpcTagByEntAndNo(int.Parse(station.SID), null);
            List<Property> properties = new List<Property>();
            foreach(var property in ent_propertys)
            {
                string adress = "";
                TagType tagType = 0;
                if(property.is_tag > 0)
                {
                    mes_opc_tag tag = ent_tags.Where(s => s.property_id == property.id).FirstOrDefault();
                    if(tag != null)
                    {
                        adress = tag.tag_adress;
                        tagType = (tag.attribute == "1" ? TagType.Trigger : TagType.Normal);
                    }
                    else
                    {
                        engine.messageQueue.Enqueue($"Error:Class:LineBuilder,Method:buildAllPropertys,Param:{property.property_name},Msg:Not Find Match OpcTag");
                    }
                }
                //DataType dataType;

                var pro = buildProperty(property.property_name, adress, station, tagType, (DataType)property.data_type);
                properties.Add(pro);

            }

            return properties;
        }

        private static Property buildProperty(string propertyName, string adress, Station station, TagType tagType, DataType dataType)
        {
            Property prop = new Property();
            prop.CurrDataType = dataType;
            prop.Container = station;
            prop.Name = propertyName;
            prop.OldValue = "";
            prop.Value = "";
            OpcTag tag = new OpcTag(Guid.NewGuid().ToString(), propertyName, "", adress, prop, true, tagType);
            prop.Tag = tag;
            station.Properties.Add(prop);
            return prop;
        }
    }

标签:AssyL2OP20CUP,之二,station,stp,数采,OPC,ent,op20Cup,TagType
From: https://blog.51cto.com/kenji/7684517

相关文章

  • 软件设计模式系列之二十一——观察者模式
    1观察者模式的定义观察者模式(ObserverPattern)是一种行为型设计模式,它允许对象之间建立一对多的依赖关系,当一个对象的状态发生变化时,所有依赖于它的对象都会得到通知并自动更新。这个模式也被称为发布-订阅模式,因为它模拟了一个主题(发布者)与多个观察者(订阅者)之间的关系。观察者......
  • 软件设计模式系列之二十——备忘录模式
    备忘录模式是一种行为型设计模式,它允许我们在不暴露对象内部细节的情况下捕获和恢复对象的内部状态。这个模式非常有用,因为它可以帮助我们实现撤销、恢复和历史记录等功能。在本文中,我们将深入探讨备忘录模式的各个方面,包括定义、示例、结构、实现步骤、代码实现、典型应用场景、......
  • 算法基础之二分查找
    原题链接二分查找中的mid+1和mid-1的问题二分查找中的边界问题处理不好很容易导致死循环和计算错误的问题,以题目数的范围为例。题目大意​二分查找重复数第一次出现的位置和最后一次出现的位置。数学含义​第一次位置即找到一个长度最大的>=X区间的左边界​最......
  • c# opc协议,连接plc
     原网址:https://www.coder.work/article/3045229 我正在使用来自OPCFoundation的两个.dll文件- opcNetApi.dll和opcNetApi.Com.dll privatevoidreadplc(){Opc.URLurl=newOpc.URL("opcda://48.5.0.05/RSLinxOPCServer");Opc.Da.Serverserver=null;Opc......
  • JAVA应用XFire框架来实现WebServie的大文件传输功能之二(上传)
    xml文件:<?xmlversion="1.0"encoding="UTF-8"?><beansxmlns="http://xfire.codehaus.org/config/1.0"><service><name>HelloWorldService</name><namespace>http://localhost:8090......
  • Ansible专栏文章之二:初入Ansible世界,用法概览和初体验
    回到:Ansible系列文章各位读者,请您:由于Ansible使用Jinja2模板,它的模板语法{%raw%}{{}}{%endraw%}和{%raw%}{%%}{%endraw%}和我博客系统hexo的模板使用的符号一样,在渲染时会产生冲突,尽管我尽我努力地花了大量时间做了调整,但无法保证已经全部都调整。因此,如果各位阅......
  • cas入门之二十四:ticket的过期策略
    cas提供了可插拔式的ticket过期策略框架用于tgt和st。在cas应用中,tgt和st的过期策略配置默认在cas/webapp/WEB-INF/spring-configuration/ticketExpirationPolicies.xml文件中。在cas的过期策略中,并没有明确指出哪一种ticket应用于哪一种过期策略,但是我们根据类名,还是能够进行区分......
  • 工程管理之二:日志初始化工具
    现在公司工作中使用的日志工具是slf4j+logback。初始化工具类实现如下:publicclassLogUtil{ privatestaticfinalorg.slf4j.LoggerLOGGER=LoggerFactory.getLogger(LogUtil.class); publicstaticfinalString__CONF_DIR__="conf"; publicstaticvoidloadLogback......
  • 支持JDK19虚拟线程的web框架,之二:完整开发一个支持虚拟线程的quarkus应用
    欢迎访问我的GitHub这里分类和汇总了欣宸的全部原创(含配套源码):https://github.com/zq2599/blog_demos本篇概览本篇是《支持JDK19虚拟线程的web框架》系列的中篇,前文咱们体验了有虚拟线程支持的web服务,经过测试,发现性能上它与其他两种常见web架构并无明显区别,既然如此,还有......
  • 算法回顾之二:直接插入排序
    算法回顾系列第二篇:直接插入排序算法-------------------------------------------直接插入排序基本原理:把n个待排序的元素看成为一个有序表和一个无序表。开始时有序表中只包含一个元素,无序表中包含有n-1个元素。排序过程中每次从无序表中取出第一个元素,将它插入到有序表中的适当......