123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net.NetworkInformation;
- using System.Text;
- using System.Threading.Tasks;
- namespace WCS.Core
- {
- public class PLC : EntityEx<PLCInfo>
- {
- public bool Ping { get; private set; }
- public PLC(PLCInfo ent,World world) : base(ent)
- {
- if (Configs.PLCAccessorCreater != null)
- {
- Accessor = Configs.PLCAccessorCreater.Create(ent);
- }
- else
- throw new Exception("Configs.PLCAccessorCreater未赋值");
- Task.Run(() =>
- {
- while (true)
- {
- Ping=ping();
- Task.Delay(1000).Wait();
- }
- });
- }
- public IPLCAccessor Accessor { get; private set; }
- bool ping(int timeout = 100)
- {
- var p = new Ping();
- var res = p.Send(Entity.IP, timeout);
- return res.Status == IPStatus.Success;
- }
-
- }
- public interface IPLCAccessorCreater
- {
- IPLCAccessor Create(PLCInfo data);
- }
- public interface IPLCAccessor
- {
- void WriteBytes(ushort db, ushort address, byte[] data);
- byte[] ReadBytes(ushort db, ushort address, ushort length);
- }
- }
|