using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using PLCCommunication;
namespace PLC
{
///
/// PLC基类
///
public abstract class PlcReadWriteBase : IPLC
{
///
/// 构造一个新的PLC对象
///
///
/// plc名
/// PLC的IP和端口
/// PLC的通讯超时时间
public PlcReadWriteBase(int pid, string pname, IPEndPoint iep, int timeout = 10)
{
this.zPlcID = pid;
this.zName = pname;
this.IP = iep.Address.ToString();
this.Port = iep.Port;
this.Timeout = timeout;
}
///
///
///
protected string zName;// 允许继承类以后可以更改名称
///
///
///
protected int zPlcID;
///
///
///
public string Name { get { return zName; } }
///
///
///
public int PlcID { get { return zPlcID; } }
///
/// Ip地址
///
public string IP { get; private set; }
///
/// 端口号
///
public int Port { get; private set; }
///
/// 是否链接成功
///
public bool IsConnected { get; set; }
///
/// PLC 的通讯超时时间
///
public int Timeout { get; private set; }
///
/// 链接PLC
///
public abstract bool Connect(ref string msg);
///
/// 断开PLC
///
public abstract bool Disconnect();
///
/// 读取Plc内部boo变量
///
///
///
public abstract bool ReadBool(string address);
///
/// 读取单个Int16整数
///
///
///
public abstract short ReadInt16(string address);
///
/// 异步读取单个Int16整数
///
///
///
public abstract Task> ReadInt16Async(string address);
///
/// 读取Int16数组
///
///
///
///
public abstract short[] ReadArrInt16(string address, ushort length);
///
/// 异步读取Int16数组
///
///
///
///
public abstract Task> ReadArrInt16Async(string address, ushort length);
///
///
///
///
///
public abstract int ReadInt32(string address);
///
/// 异步读取整数32位
///
///
///
public abstract Task> ReadInt32Async(string address);
///
///
///
///
///
public abstract float ReadFloat(string address);
///
/// 读取float数组
///
///
///
///
public abstract float[] ReadArrFloat(string address, ushort length);
///
/// 异步读取float数组
///
///
///
///
public abstract Task> ReadArrFloatAsync(string address, ushort length);
///
///
///
///
///
///
///
///
public abstract T ReadValue(string address, DataType type, ushort length = 0);
///
///
///
///
///
public abstract bool WriteBool(string address, bool value);
///
///
///
///
///
///
public abstract bool WriteInt16(string address, short value);
///
///
///
///
///
///
public abstract bool WriteInt32(string address, int value);
///
///
///
///
///
///
public abstract bool WriteFloat(string address, float value);
///
/// 泛型写入数据
///
///
///
///
///
public abstract JYResult WriteValue(string address, object value, PLC.DataType type = PLC.DataType.Short);
}
}