Exemple #1
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);
        }
        private void Read(CoilsWorkItem workItem)
        {
            UInt16 address = workItem.Address.Index;
            UInt16 length = workItem.QuantityOfCoils;
            Boolean[] reply;

            lock (DriverLock)
            {
                reply = Driver.ReadCoils(1, address, length);
            }

            Byte[] buffer = new Byte[reply.Length * sizeof(Boolean)];
            Buffer.BlockCopy(reply, 0, buffer, 0, buffer.Length);
            workItem.Buffer = buffer;
        }
Exemple #3
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;
        }