コード例 #1
0
        public void WriteDataToOpcServer(ProductionPlan production)
        {
            if (!opcContected)
            {
                opcContected = m_uaClient.ConnectOpcServerWithPwd(xmlSettings.URL, xmlSettings.UserName, xmlSettings.Password);
            }

            DB203Site siteNode = SetDB203Site(production);

            foreach (var pi in siteNode.GetType().GetProperties())
            {
                string name  = pi.Name;                     //获得属性的名字,后面就可以根据名字判断来进行些自己想要的操作
                var    value = pi.GetValue(siteNode, null); //用pi.GetValue获得值
                Type   t     = pi.GetType();

                bool retValue = false;

                switch (pi.PropertyType.Name)
                {
                case "Byte":
                    retValue = m_uaClient.WriteDataToOpcServer <byte>(db203Site_KeyValue[name], (byte)value);
                    break;

                case "Int16":
                    retValue = m_uaClient.WriteDataToOpcServer <short>(db203Site_KeyValue[name], (short)value);
                    break;

                case "UInt16":
                    retValue = m_uaClient.WriteDataToOpcServer <ushort>(db203Site_KeyValue[name], (ushort)value);
                    break;

                case "UInt32":
                    retValue = m_uaClient.WriteDataToOpcServer <uint>(db203Site_KeyValue[name], (uint)value);
                    break;

                case "Byte[]":
                    //retValue = m_uaClient.WriteDataToOpcServer<byte[]>(db203Site_KeyValue[name], (byte[])value);
                    retValue = m_uaClient.WriteDataToOpcServer <byte[]>(db203Site_KeyValue[name], (byte[])value);
                    break;

                case "byte[]":
                    retValue = m_uaClient.WriteDataToOpcServer <byte[]>(db203Site_KeyValue[name], (byte[])value);
                    break;
                }
            }
        }
コード例 #2
0
        private DB203Site SetDB203Site(ProductionPlan production)
        {
            byte[] workpieceType = new byte[4];
            //byte[] workpiece = new ASCIIEncoding().GetBytes(production.WorkpieceType.ToUpper());
            if (production.WorkpieceType != "0")
            {
                byte[] workpiece = Encoding.Default.GetBytes(production.WorkpieceType.ToUpper());

                for (int i = 0; i < workpiece.Length; i++)
                {
                    workpieceType[i] = workpiece[i];
                }
            }
            DB203Site dB203Site = new DB203Site
            {
                Heartbeat     = 13,
                WorkpieceType = workpieceType,
                //WorkpieceType = Convert.ToUInt32(production.WorkpieceType),
                PrimerColor           = Convert.ToInt16(production.PrimerColor),
                PrimerFirm            = Convert.ToInt16(production.PrimerFirm),
                PrimerCraft           = Convert.ToInt16(production.PrimerCraft),
                PigmentedCoatingColor = Convert.ToInt16(production.PigmentedCoatingColor),
                PigmentedCoatingFirm  = Convert.ToInt16(production.PigmentedCoatingFirm),
                PigmentedCoatingCraft = Convert.ToInt16(production.PigmentedCoatingCraft),
                VarnishColor          = Convert.ToInt16(production.VarnishColor),
                VarnishFirm           = Convert.ToInt16(production.VarnishFirm),
                VarnishCraft          = Convert.ToInt16(production.VarnishCraft),
                BatchNo    = Convert.ToUInt32(production.BatchNo),
                Receive_1  = 0,
                Receive_2  = 0,
                Receive_3  = 0,
                Receive_4  = 0,
                Receive_5  = 0,
                Receive_6  = 0,
                Receive_7  = 0,
                Receive_8  = 0,
                Receive_9  = 0,
                Receive_10 = 0,
                TotalNum   = Convert.ToUInt16(production.TotalNum)
            };

            return(dB203Site);
        }