Example #1
0
        public static bool ReadPlusMcDbValuesRemote(this ClientSession session,
                                                    ICoreObject onlineTarget, ICoreObject blockDb, out OnlineBinary binaryToRead, uint dbValuesAid)
        {
            if (onlineTarget == null || blockDb == null)
            {
                throw new BlockLogicException("onlineTarget, blockDb is null");
            }
            if (!IecplUtilities.IsPlusPLC(blockDb) || !onlineTarget.GetObjectType().IsTypeOf(OnlineControllerTargetData.FullName))
            {
                throw new BlockLogicException("Target is no Plus- or Online target");
            }
            IGeneralBlockSourceData generalBlockSourceData = blockDb.GetAttributeSet(typeof(IGeneralBlockSourceData), false) as IGeneralBlockSourceData;

            if (generalBlockSourceData == null || generalBlockSourceData.BlockType != BlockType.DB)
            {
                throw new BlockLogicException("block is no data block!");
            }
            if ((int)dbValuesAid != 2550 && (int)dbValuesAid != 2548)
            {
                throw new System.NotSupportedException("Only ValueActual_Aid and ValueInitial_Aid are supported");
            }
            uint  blockRid = RidService.GetRidService(onlineTarget, true).GetBlockRid(blockDb);
            Error error    = new Error();
            ulong ticks    = 0UL;
            Dictionary <uint, byte[]> dictionary = new Dictionary <uint, byte[]>()
            {
                {
                    3U,
                    new byte[0]
                },
                {
                    4U,
                    new byte[0]
                },
                {
                    5U,
                    new byte[0]
                }
            };

            binaryToRead = new OnlineBinary(dictionary[4U], dictionary[5U], dictionary[3U], new System.DateTime());
            try
            {
                int   requestID      = -1;
                Value obj1           = new Value();
                Value obj2           = null;
                Error variableRemote = session.GetVariableRemote(new Rid(blockRid), new Aid(dbValuesAid), ref obj1, ref requestID);
                using (obj1)
                {
                    if (variableRemote.Failed)
                    {
                        return(false);
                    }
                    foreach (uint key in Enumerable.ToList(dictionary.Keys))
                    {
                        Error errorState = obj1.GetValue(key, ref obj2);
                        using (obj2)
                        {
                            if (errorState.Failed)
                            {
                                return(false);
                            }
                            byte[] numArray = new byte[0];
                            obj2.GetValue(ref numArray);
                            dictionary[key] = numArray;
                        }
                    }
                    Error errorState1 = obj1.GetValue(6U, ref obj2);
                    using (obj2)
                    {
                        if (errorState1.Failed)
                        {
                            return(false);
                        }
                        obj2.GetValue(ref ticks);
                    }
                    binaryToRead = new OnlineBinary(dictionary[4U], dictionary[5U], dictionary[3U], DateTimeExtensions.ConvertPLCToESTime(ticks));
                }
            }
            finally
            {
            }
            return(true);
        }
        public static IBlock GetBlock(this ICoreObject coreObject)
        {
            IBlock block = IecplUtilities.GetBusinessLogicBlock(coreObject) as IBlock;

            return(block);
        }