using SqlSugar;
namespace Model.Entity.Config
{
///
/// 网关(通讯通道):TCP 类存 IP+端口,串口类存 COM+波特率,S7 类额外存 CPU/Rack/Slot。
/// 同一网关下多设备用从站号(SlaveId)区分。
///
public class GatewayEntity : BaseEntity
{
///
/// 网关编码(唯一,如 GW-ENV-01)
///
[SugarColumn(ColumnDescription = "网关编码", Length = 64)]
public string Code { get; set; }
///
/// 网关名称
///
[SugarColumn(ColumnDescription = "网关名称", Length = 100)]
public string Name { get; set; }
///
/// 通讯协议类型(决定连接参数组:TCP/Serial/S7)
///
[SugarColumn(ColumnDescription = "通讯协议类型")]
public IotDeviceProtocolEnum ProtocolType { get; set; } = IotDeviceProtocolEnum.ModbusTcp;
#region TCP 参数(ModbusTcp / Tcp / S7 协议使用)
///
/// IP 地址
///
[SugarColumn(ColumnDescription = "IP地址", Length = 50, IsNullable = true)]
public string? Host { get; set; }
///
/// 端口号(ModbusTcp 默认 502,S7 默认 102)
///
[SugarColumn(ColumnDescription = "端口号", IsNullable = true)]
public int? Port { get; set; }
#endregion
#region 串口参数(ModbusRtu / Serial 协议使用)
///
/// 串口号(如 COM3)
///
[SugarColumn(ColumnDescription = "串口号", Length = 20, IsNullable = true)]
public string? ComPort { get; set; }
///
/// 波特率(默认 9600)
///
[SugarColumn(ColumnDescription = "波特率", IsNullable = true)]
public int? BaudRate { get; set; }
///
/// 数据位(默认 8)
///
[SugarColumn(ColumnDescription = "数据位", IsNullable = true)]
public byte? DataBits { get; set; }
///
/// 停止位(1/2,默认 1)
///
[SugarColumn(ColumnDescription = "停止位", IsNullable = true)]
public byte? StopBits { get; set; }
///
/// 校验位(0=None 1=Odd 2=Even,默认 0)
///
[SugarColumn(ColumnDescription = "校验位", IsNullable = true)]
public byte? Parity { get; set; }
#endregion
#region S7 参数(S7 协议专用)
///
/// S7 CPU 型号(如 S71200、S71500)
///
[SugarColumn(ColumnDescription = "S7 CPU型号", Length = 20, IsNullable = true)]
public string? CpuType { get; set; }
///
/// S7 Rack(默认 0)
///
[SugarColumn(ColumnDescription = "S7 Rack", IsNullable = true)]
public byte? Rack { get; set; }
///
/// S7 Slot(默认 1)
///
[SugarColumn(ColumnDescription = "S7 Slot", IsNullable = true)]
public byte? Slot { get; set; }
#endregion
#region 状态
///
/// 是否启用
///
[SugarColumn(ColumnDescription = "是否启用")]
public bool IsEnabled { get; set; } = true;
///
/// 在线状态(0=离线 1=在线 3=异常,由测试连接更新)
///
[SugarColumn(ColumnDescription = "在线状态")]
public byte OnlineStatus { get; set; }
///
/// 最后连接成功时间
///
[SugarColumn(ColumnDescription = "最后连接时间", IsNullable = true)]
public DateTime? LastConnectedTime { get; set; }
///
/// 最近错误
///
[SugarColumn(ColumnDescription = "最近错误", Length = 500, IsNullable = true)]
public string? LastError { get; set; }
#endregion
///
/// 备注
///
[SugarColumn(ColumnDescription = "备注", Length = 500, IsNullable = true)]
public string? Remark { get; set; }
}
}