Exemple #1
0
        public int WriteFloat(DeviceAddress address, float value)
        {
            int rs = _plcReader.WriteFloat(address, value);

            if (rs >= 0)
            {
                if (DataChange != null)
                {
                    ITag tag = GetTagByAddress(address);
                    if (tag != null)
                    {
                        DataChange(this,
                                   new DataChangeEventArgs(1,
                                                           new HistoryData[1] {
                            new HistoryData(tag.ID, QUALITIES.QUALITY_GOOD, new Storage {
                                Single = value
                            },
                                            DateTime.Now)
                        }));
                    }
                }
            }

            return(rs);
        }
 /// <summary>
 /// 订阅数据发送
 /// </summary>
 private void subscribeSendData()
 {
     if (_client.IsConnect)
     {
         foreach (var point in _points.BoolPoints)
         {
             point.SendEvent += (s, p, q) =>
             {
                 lock (_locker)
                 {
                     _timeRead.Stop();
                     var temp = s as DevicePoint <bool>;
                     if (!q)//true则进行所有数据发送,false只需发送单个数据
                     {
                         var address = temp.Address;
                         address.Address += p;
                         _client.WriteBool(address, temp[(byte)p]);
                     }
                     else
                     {
                         _client.WriteBools(temp.Address, temp.GetValues());
                     }
                     _timeRead.Start();
                 }
             };
         }
         foreach (var point in _points.ShortPoints)
         {
             point.SendEvent += (s, p, q) =>
             {
                 lock (_locker1)
                 {
                     _timeRead.Stop();
                     var temp = s as DevicePoint <short>;
                     if (!q)
                     {
                         var address = temp.Address;
                         address.Address += p;
                         _client.WriteShort(address, temp[(byte)p]);
                     }
                     else
                     {
                         _client.WriteShorts(temp.Address, s.GetValues());
                     }
                     _timeRead.Start();
                 }
             };
         }
         foreach (var point in _points.UshortPoints)
         {
             point.SendEvent += (s, p, q) =>
             {
                 lock (_locker2)
                 {
                     _timeRead.Stop();
                     var temp = s as DevicePoint <ushort>;
                     if (!q)
                     {
                         var address = temp.Address;
                         address.Address += p;
                         _client.WriteUShort(address, temp[(byte)p]);
                     }
                     else
                     {
                         _client.WriteUShorts(temp.Address, temp.GetValues());
                     }
                     _timeRead.Start();
                 }
             };
         }
         foreach (var point in _points.IntPoints)
         {
             point.SendEvent += (s, p, q) =>
             {
                 lock (_locker3)
                 {
                     _timeRead.Stop();
                     var temp = s as DevicePoint <int>;
                     if (!q)
                     {
                         var address = temp.Address;
                         address.Address += p * 2;
                         _client.WriteInt(address, temp[(byte)p]);
                     }
                     else
                     {
                         _client.WriteInts(temp.Address, s.GetValues());
                     }
                     _timeRead.Start();
                 }
             };
         }
         foreach (var point in _points.UintPoints)
         {
             point.SendEvent += (s, p, q) =>
             {
                 lock (_locker4)
                 {
                     _timeRead.Stop();
                     var temp = s as DevicePoint <uint>;
                     if (!q)
                     {
                         var address = temp.Address;
                         address.Address += p * 2;
                         _client.WriteUInt(address, temp[(byte)p]);
                     }
                     else
                     {
                         _client.WriteUInts(temp.Address, s.GetValues());
                     }
                     _timeRead.Start();
                 }
             };
         }
         foreach (var point in _points.FloatPoints)
         {
             point.SendEvent += (s, p, q) =>
             {
                 lock (_locker5)
                 {
                     _timeRead.Stop();
                     var temp = s as DevicePoint <float>;
                     if (!q)
                     {
                         var address = temp.Address;
                         address.Address += p * 2;
                         _client.WriteFloat(address, temp[(byte)p]);
                     }
                     else
                     {
                         _client.WriteFloats(temp.Address, s.GetValues());
                     }
                     _timeRead.Start();
                 }
             };
         }
     }
 }
Exemple #3
0
 public int WriteFloat(DeviceAddress address, float value)
 {
     return(_reader.WriteFloat(address, value));
 }