Пример #1
0
        public static IEnumerable <HoldingRegistersWorkItem> GetWorkItems(IEnumerable <IModbusHoldingRegistersTag> Tags, UInt16 MaxQuantityOfRegisters = 125)
        {
            IList <IModbusHoldingRegistersTag> TagList = Tags.Where(tag => tag.Address.Table == Table.HoldingRegisters).OrderBy(tag => tag.Address.Index).ToList();

            List <HoldingRegistersWorkItem> WorkItems = new List <HoldingRegistersWorkItem>();

            HoldingRegistersWorkItem WorkItem = null;

            foreach (IModbusHoldingRegistersTag tag in TagList)
            {
                if (WorkItem == null)
                {
                    WorkItem = new HoldingRegistersWorkItem(MaxQuantityOfRegisters);
                    WorkItems.Add(WorkItem);
                }
                if (!(WorkItem.Add(tag)))
                {
                    WorkItem = new HoldingRegistersWorkItem(MaxQuantityOfRegisters);
                    WorkItem.Add(tag);
                    WorkItems.Add(WorkItem);
                }
            }
            return(WorkItems);
        }
Пример #2
0
        public static IEnumerable <CoilsWorkItem> GetWorkItems(IEnumerable <IModbusCoilsTag> Tags, UInt16 MaxQuantityOfCoils = 2000)
        {
            IList <IModbusCoilsTag> TagList = Tags.Where(tag => tag.Address.Table == Table.Coils).OrderBy(tag => tag.Address.Index).ToList();

            List <CoilsWorkItem> WorkItems = new List <CoilsWorkItem>();

            CoilsWorkItem WorkItem = null;

            foreach (IModbusCoilsTag tag in TagList)
            {
                if (WorkItem == null)
                {
                    WorkItem = new CoilsWorkItem(MaxQuantityOfCoils);
                    WorkItems.Add(WorkItem);
                }
                if (!(WorkItem.Add(tag)))
                {
                    WorkItem = new CoilsWorkItem(MaxQuantityOfCoils);
                    WorkItem.Add(tag);
                    WorkItems.Add(WorkItem);
                }
            }
            return(WorkItems);
        }