Exemplo n.º 1
0
        /// <summary>
        /// 按照编号获取设置线圈
        /// </summary>
        /// <param name="number"></param>
        /// <returns></returns>
        public bool this[int number]
        {
            get
            {
                if (number < 0 || number >= bitArray.Length)
                {
                    throw new ArgumentOutOfRangeException("number");
                }

                return(bitArray[number]);
            }
            set
            {
                if (number < 0 || number >= bitArray.Length)
                {
                    throw new ArgumentOutOfRangeException("number");
                }

                if (this[number] != value)
                {
                    bitArray.Set(number, value);
                    NumberData <bool> data = new NumberData <bool>(number, value);
                    if (write.Contains(data))
                    {
                        write[write.IndexOf(data)] = data;
                    }
                    else
                    {
                        write.Add(new NumberData <bool>(number, value));
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void Add(NumberData <ushort> data)
        {
            if (RegisterBlock.Contains(data))
            {
                throw new ArgumentException("address error");
            }

            RegisterBlock.Add(data);
            RegisterBlock.Sort();
        }
Exemplo n.º 3
0
 private void ReadChangeRegisters(ushort address, ushort value)
 {
     for (int i = 0; i < RegisterBlock.Count; i++)
     {
         if (RegisterBlock[i].Num == address)
         {
             RegisterBlock[i] = new NumberData <ushort>(RegisterBlock[i].Num, value);
             return;
         }
     }
 }
Exemplo n.º 4
0
        public ushort GetValueUshort(ushort address)
        {
            NumberData <ushort> data = new NumberData <ushort>(address, 0);
            int findIndex            = RegisterBlock.IndexOf(data);

            if (findIndex == -1)
            {
                throw new ArgumentException("there is no address in read adress list, error address" + address, "address");
            }

            return(RegisterBlock[findIndex].Value);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 根据PLC的标号获取设置线圈
        /// </summary>
        /// <param name="number"></param>
        /// <returns></returns>
        public bool this[string numberID]
        {
            get
            {
                int num = _driver.Convert_PLCNumberID_To_ModubsAddress(numberID);

                for (int i = 0; i < SingleCoilsRead.Count; i++)
                {
                    NumberData <bool> data = SingleCoilsRead[i];
                    if (data.Num == num)
                    {
                        return(data.Value);
                    }
                }

                return(this[num]);
            }
            set
            {
                int num = _driver.Convert_PLCNumberID_To_ModubsAddress(numberID);

                for (int i = 0; i < SingleCoilsRead.Count; i++)
                {
                    NumberData <bool> data = SingleCoilsRead[i];
                    if (data.Num == num)
                    {
                        if (data.Value != value)
                        {
                            data.Value         = value;
                            SingleCoilsRead[i] = data;

                            if (write.Contains(data))
                            {
                                write[write.IndexOf(data)] = data;
                            }
                            else
                            {
                                write.Add(data);
                            }
                        }

                        return;
                    }
                }

                this[num] = value;
            }
        }
Exemplo n.º 6
0
        private void WriteChangeRegisters(ushort address, ushort value)
        {
            NumberData <ushort> data = new NumberData <ushort>(address, value);

            int readIndex = RegisterBlock.IndexOf(data);

            if (readIndex > -1)
            {
                RegisterBlock[readIndex] = data;
            }

            int writeIndex = writeBlock.IndexOf(data);

            if (writeIndex == -1)
            {
                writeBlock.Add(data);
            }
            else
            {
                writeBlock[writeIndex] = data;
            }
        }
Exemplo n.º 7
0
        public void ReadCoils()
        {
            ushort number = 0;

            while (number < bitArray.Length)
            {
                if (number + PLCDevice.Read_Write_Bool_Max_Number < bitArray.Length)
                {
                    ReadCoils(number, PLCDevice.Read_Write_Bool_Max_Number);
                }
                else
                {
                    ReadCoils(number, (ushort)(bitArray.Length - number));
                }
                number += PLCDevice.Read_Write_Bool_Max_Number;
            }


            for (int i = 0; i < SingleCoilsRead.Count; i++)
            {
                bool[] inputs = ReadCoils(_driver.Slave, (ushort)SingleCoilsRead[i].Num, 1);
                SingleCoilsRead[i] = new NumberData <bool>(SingleCoilsRead[i].Num, inputs[0]);
            }
        }
Exemplo n.º 8
0
 public int CompareTo(NumberData <T> other)
 {
     return(this.Num - other.Num);
 }
Exemplo n.º 9
0
 public bool Equals(NumberData <T> other)
 {
     return(this.Num == other.Num);
 }