예제 #1
0
 /// <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();
                 }
             };
         }
     }
 }