123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- using System.Collections.Generic;
- using System.Threading.Tasks;
- using System;
- namespace Team.Communicate.Modbus
- {
- public interface IModbusTcpMaster
- {
- public string Ip { get; }
- public int Port { get; }
- int ConnectTimeOut { get; set; }
- byte SlaveId { get; set; }
- bool IsConnect { get; }
- void Connect();
- Task ConnectAsync();
- /// <summary>
- /// 重连
- /// </summary>
- /// <param name="ip"></param>
- /// <param name="port"></param>
- /// <returns></returns>
- Task<bool> ReConnect();
- ushort[] ReadBytes(ushort start, ushort length);
- /// <summary>
- /// 获取单个位状态
- /// </summary>
- /// <param name="start">从PLC里读出第几个字节</param>
- /// <param name="index">第几位</param>
- /// <returns></returns>
- bool GetBool(ushort start, ushort index);
- List<KeyValuePair<string, bool>> GetBoolList(IEnumerable<string> addresses);
- /// <summary>
- /// 获取单个位状态
- /// </summary>
- /// <param name="start">从PLC里读出第几个字节</param>
- /// <param name="index" >第几位</param>
- /// <returns></returns>
- Task<bool> GetBoolAsync(ushort start, ushort index);
- /// <summary>
- /// 写modbus位
- /// </summary>
- /// <param name="start">字节位置</param>
- /// <param name="index">位索引</param>
- /// <param name="flag">位value</param>
- void WriteBool(ushort start, int index, bool flag);
- /// <summary>
- /// 异步写modbus位
- /// </summary>
- /// <param name="start">字节位置</param>
- /// <param name="index">位索引</param>
- /// <param name="flag">位value</param>
- Task WriteBoolAsync(ushort start, int index, bool flag);
- void WriteInt32(ushort start, int value);
- Task WriteInt32Async(ushort start, int value);
- /// <summary>
- /// 写modbus位
- /// </summary>
- /// <param name="start"></param>
- /// <param name="index"></param>
- /// <param name="value"></param>
- void WriteByte(ushort start, int index, byte value);
- /// <summary>
- /// 写modbus位
- /// </summary>
- /// <param name="start"></param>
- /// <param name="index"></param>
- /// <param name="value"></param>
- Task WriteByteAsync(ushort start, int index, byte value);
- /// <summary>
- /// 写入双精度浮点
- /// </summary>
- /// <param name="start"></param>
- /// <param name="value"></param>
- void WriteDouble(ushort start, double value);
- /// <summary>
- /// 异步写入双精度浮点
- /// </summary>
- /// <param name="start"></param>
- /// <param name="value"></param>
- /// <returns></returns>
- Task WriteDoubleAsync(ushort start, double value);
- /// <summary>
- /// 写入单精度浮点
- /// </summary>
- /// <param name="start"></param>
- /// <param name="value"></param>
- void WriteFloat(ushort start, float value);
- /// <summary>
- /// 异步写入单精度浮点
- /// </summary>
- /// <param name="start"></param>
- /// <param name="value"></param>
- /// <returns></returns>
- Task WriteFloatAsync(ushort start, float value);
- /// <summary>
- /// 获取浮点数值
- /// </summary>
- /// <param name="index">数据索引</param>
- /// <returns></returns>
- float GetFloat(ushort index);
- /// <summary>
- /// 获取浮点数值
- /// </summary>
- /// <param name="index">数据索引</param>
- /// <returns></returns>
- Task<float> GetFloatAsync(ushort index);
- /// <summary>
- /// 获取字
- /// </summary>
- /// <param name="index">数据索引</param>
- /// <returns></returns>
- ushort GetShort(ushort index);
- /// <summary>
- /// 获取字
- /// </summary>
- /// <param name="index">数据索引</param>
- /// <returns></returns>
- Task<ushort> GetShortAsync(ushort index);
- /// <summary>
- /// 获取整型数值
- /// </summary>
- /// 4字节整数
- /// <param name="index">数据索引</param>
- /// <returns></returns>
- int GetInteger(ushort index);
- /// <summary>
- /// 异步获取整型数值
- /// </summary>
- /// 4字节整数
- /// <param name="index">数据索引</param>
- /// <returns></returns>
- Task<int> GetIntegerAsync(ushort index);
- /// <summary>
- /// 读字节
- /// </summary>
- /// <param name="start">开始字索引</param>
- /// <param name="index">第几个字节</param>
- /// <returns></returns>
- Task<byte> GetByteAsync(ushort start, int index);
- /// <summary>
- /// 读字节
- /// </summary>
- /// <param name="start">开始字索引</param>
- /// <param name="index">第几个字节</param>
- /// <returns></returns>
- byte GetByte(ushort start, int index);
- ushort[] GetBytes(ushort start, ushort length);
- Task<ushort[]> GetBytesAsync(ushort start, ushort length);
-
- event EventHandler<bool> ConnectChanged;
-
- }
- }
|