1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- using System.Net.NetworkInformation;
- namespace WCS.Core
- {
- public class PLC : EntityEx<PLCInfo>
- {
- public bool Ping { get; private set; }
- public PLC(PLCInfo ent) : 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);
- }
- });
- }
- public IPLCAccessor Accessor { get; private set; }
- private bool ping(int timeout = 100)
- {
- var p = new Ping();
- var res = p.Send(Entity.IP, timeout);
- return res.Status == IPStatus.Success;
- //return true;
- }
- }
- 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);
- }
- }
|