Пример #1
0
        /// <summary>
        /// 更新变量
        /// </summary>
        /// <param name="tagTable">变量表</param>
        /// <param name="tag">变量</param>
        /// <param name="properties">变量数据</param>
        /// <param name="isConstant">是否静态变量</param>
        public static IBLTag UpdateTag(
            this ICoreObject tagTable,
            IBLTag tag,
            Dictionary <string, string> properties,
            bool isConstant = false,
            ISynchronizeInvoke synchronizer = null)
        {
            ISynchronizeInvoke UsingSynchronizer;

            if (synchronizer == null)
            {
                UsingSynchronizer = tagTable.GetSynchronizer();
            }
            else
            {
                UsingSynchronizer = synchronizer;
            }
            return(TiaStarter.RunFuncInSynchronizer(UsingSynchronizer,
                                                    () =>
            {
                bool result = UpdateTagReal(tagTable, tag, properties, isConstant);
                return FindRootTagByName(tagTable.GetParent(), tag.Name);
            }) as IBLTag);
        }
        private static void SetIpAddress(this ICoreObject onlineCore,
                                         DiagServiceProvider DiagServiceProvider,
                                         int addressType,
                                         byte[] ipAddress,
                                         byte[] subnetMask,
                                         byte[] router)
        {
            IEthernetDiscoverNode ethernetDiscoverNode = DiagServiceProvider.PELifelistService.GetOamNode(onlineCore.GetParent().GetParent()) as IEthernetDiscoverNode;

            if (ethernetDiscoverNode == null)
            {
                return;
            }
            IPAddress ipAddress1 = new IPAddress(ethernetDiscoverNode.IpStationParams.LocalIpParam.InternetProtocolAddress.GetAddressBytes());
            IPAddress ipAddress2 = new IPAddress(ethernetDiscoverNode.IpStationParams.LocalIpParam.LocalIpv4SubnetMask.GetAddressBytes());
            IPAddress ipAddress3 = new IPAddress(ethernetDiscoverNode.IpStationParams.LocalIpParam.LocalDefaultRouter.GetAddressBytes());

            if (ethernetDiscoverNode.Configuration.ProtocolType != OamProtocolType.Ethernet && ethernetDiscoverNode.Configuration.ProtocolType != OamProtocolType.InternetProtocol && ethernetDiscoverNode.Configuration.ProtocolType != OamProtocolType.Auto)
            {
                throw new OnlineException(4, 240);
            }
            if (ipAddress == null)
            {
                throw new OnlineException(7, 240);
            }
            IPAddress ipAddress4 = new IPAddress(ipAddress);

            ethernetDiscoverNode.IpStationParams.LocalIpParam.InternetProtocolAddress = ipAddress4;
            if (subnetMask != null)
            {
                ethernetDiscoverNode.IpStationParams.LocalIpParam.LocalIpv4SubnetMask = new IPAddress(subnetMask);
            }
            if (router != null)
            {
                if (1 == addressType)
                {
                    IPAddress ipAddress5 = new IPAddress(router);
                    ethernetDiscoverNode.IpStationParams.LocalIpParam.LocalDefaultRouter = ipAddress5;
                }
                else
                {
                    ethernetDiscoverNode.IpStationParams.LocalIpParam.LocalDefaultRouter = ipAddress4;
                }
            }
            ethernetDiscoverNode.IpStationParams.LocalIpParam.IpActive = 1;
            ethernetDiscoverNode.IpStationParams.PermanentStorage      = true;
            int errorCode = ethernetDiscoverNode.IpStationParams.Write();

            if (errorCode != 0)
            {
                int serviceId = DiagServiceProvider.OnlineSessionDlc.OnlineAccess.ErrorHandler.ServiceId;
                ethernetDiscoverNode.IpStationParams.LocalIpParam.InternetProtocolAddress = ipAddress1;
                ethernetDiscoverNode.IpStationParams.LocalIpParam.LocalIpv4SubnetMask     = ipAddress2;
                ethernetDiscoverNode.IpStationParams.LocalIpParam.LocalDefaultRouter      = ipAddress3;
                ethernetDiscoverNode.IpStationParams.Write();
                throw new OnlineException(errorCode, serviceId, string.Empty);
            }
        }