using Newtonsoft.Json;
using Prism.Mvvm;
namespace TeamAAS_VP.Models
{
///
/// 波形数据来源模式
///
public enum WaveDataSourceMode
{
///
/// 锁付过程中轮询实时寄存器并累积曲线点(MDC V2 3300/3301 等)
///
RealtimeAccumulate = 0,
///
/// 从连续寄存器块批量读取波形(通用设备)
///
RegisterBlock = 1
}
///
/// Modbus TCP 主站配置(连接 MDC V2 电批等从站设备)
/// 默认地址参考 MDC V2 Appendix A,可在设置界面或 cfg 文件中修改
///
public class ModbusTcpMasterConfig : BindableBase
{
#region 连接
private string _IP = "192.168.1.100";
/// 目标从站 IP(MDC 出厂默认 192.168.1.100)
public string IP
{
get { return _IP; }
set { SetProperty(ref _IP, value); }
}
private int _Port = 5000;
/// 目标从站 Modbus TCP 端口(MDC V2 出厂默认 5000)
public int Port
{
get { return _Port; }
set { SetProperty(ref _Port, value); }
}
private byte _SlaveID = 1;
public byte SlaveID
{
get { return _SlaveID; }
set { SetProperty(ref _SlaveID, value); }
}
private bool _IsEnabled = false;
public bool IsEnabled
{
get { return _IsEnabled; }
set { SetProperty(ref _IsEnabled, value); }
}
private int _PollIntervalMs = 50;
/// 轮询间隔(毫秒)
public int PollIntervalMs
{
get { return _PollIntervalMs; }
set { SetProperty(ref _PollIntervalMs, value); }
}
private bool _UseInputRegisters = true;
///
/// true=功能码 0x04 读输入寄存器(MDC 状态/实时数据区 3100+)
/// false=功能码 0x03 读保持寄存器
///
public bool UseInputRegisters
{
get { return _UseInputRegisters; }
set { SetProperty(ref _UseInputRegisters, value); }
}
private WaveDataSourceMode _WaveDataMode = WaveDataSourceMode.RealtimeAccumulate;
public WaveDataSourceMode WaveDataMode
{
get { return _WaveDataMode; }
set { SetProperty(ref _WaveDataMode, value); }
}
private float _TorqueScaleFactor = 100f;
/// 扭矩寄存器缩放系数(MDC:Converted torque * x100)
public float TorqueScaleFactor
{
get { return _TorqueScaleFactor; }
set { SetProperty(ref _TorqueScaleFactor, value); }
}
#endregion
#region 状态寄存器(MDC:3212 Status, 3307 Motor RUN)
private ushort _LockInProgressAddress = 3307;
/// 锁付进行中地址(MDC:3307 Motor RUN,0=不检测)
public ushort LockInProgressAddress
{
get { return _LockInProgressAddress; }
set { SetProperty(ref _LockInProgressAddress, value); }
}
private ushort _LockInProgressActiveValue = 1;
public ushort LockInProgressActiveValue
{
get { return _LockInProgressActiveValue; }
set { SetProperty(ref _LockInProgressActiveValue, value); }
}
private ushort _FinishFlagAddress = 3212;
/// 锁付状态地址(MDC:3212,1=完成,2=NG)
public ushort FinishFlagAddress
{
get { return _FinishFlagAddress; }
set { SetProperty(ref _FinishFlagAddress, value); }
}
private ushort _FinishFlagCompleteValue = 1;
/// 锁付 OK 状态值(MDC:3212=1 Fastening complete)
public ushort FinishFlagCompleteValue
{
get { return _FinishFlagCompleteValue; }
set { SetProperty(ref _FinishFlagCompleteValue, value); }
}
private ushort _FinishFlagNgValue = 2;
/// 锁付 NG 状态值(MDC:3212=2 Fastening NG)
public ushort FinishFlagNgValue
{
get { return _FinishFlagNgValue; }
set { SetProperty(ref _FinishFlagNgValue, value); }
}
#endregion
#region 锁付结果寄存器(MDC Event Data 3200+,功能码 0x04)
private ushort _LockTurnsAddress = 3213;
/// 锁付圈数/角度源地址(MDC:3213 Snug torque angle,单位 degree,除以360得圈数)
public ushort LockTurnsAddress
{
get { return _LockTurnsAddress; }
set { SetProperty(ref _LockTurnsAddress, value); }
}
private float _TurnsScaleFactor = 360f;
/// 圈数换算除数(角度/360=圈数)
public float TurnsScaleFactor
{
get { return _TurnsScaleFactor; }
set { SetProperty(ref _TurnsScaleFactor, value); }
}
private ushort _LockTorqueAddress = 3204;
/// 锁付扭矩地址(MDC:3204 Converted torque * x100)
public ushort LockTorqueAddress
{
get { return _LockTorqueAddress; }
set { SetProperty(ref _LockTorqueAddress, value); }
}
private ushort _LockDurationAddress = 3201;
/// 锁付用时地址(MDC:3201 Fastening time ms)
public ushort LockDurationAddress
{
get { return _LockDurationAddress; }
set { SetProperty(ref _LockDurationAddress, value); }
}
private bool _LockDurationIsMilliseconds = true;
/// 锁付用时寄存器是否为毫秒(MDC 为 true)
public bool LockDurationIsMilliseconds
{
get { return _LockDurationIsMilliseconds; }
set { SetProperty(ref _LockDurationIsMilliseconds, value); }
}
private ushort _LockPassedAddress = 3305;
///
/// 锁付 OK 实时位(MDC:3305,仅供参考;判定 OK/NG 以 3212 Status 为准)
///
public ushort LockPassedAddress
{
get { return _LockPassedAddress; }
set { SetProperty(ref _LockPassedAddress, value); }
}
private ushort _ProgramNumberAddress = 3202;
/// 程序号地址(MDC:3202 Preset no.)
public ushort ProgramNumberAddress
{
get { return _ProgramNumberAddress; }
set { SetProperty(ref _ProgramNumberAddress, value); }
}
#endregion
#region 实时监控寄存器(MDC Realtime Data 3300+)
private ushort _RealtimeTorqueAddress = 3300;
/// 实时扭矩(MDC:3300 Converted torque * x100)
public ushort RealtimeTorqueAddress
{
get { return _RealtimeTorqueAddress; }
set { SetProperty(ref _RealtimeTorqueAddress, value); }
}
private ushort _RealtimeSpeedAddress = 3301;
/// 实时转速(MDC:3301 Speed rpm)
public ushort RealtimeSpeedAddress
{
get { return _RealtimeSpeedAddress; }
set { SetProperty(ref _RealtimeSpeedAddress, value); }
}
#endregion
#region 波形寄存器块(RegisterBlock 模式)
private ushort _WaveDataCountAddress = 100;
public ushort WaveDataCountAddress
{
get { return _WaveDataCountAddress; }
set { SetProperty(ref _WaveDataCountAddress, value); }
}
private ushort _WaveDataStartAddress = 101;
public ushort WaveDataStartAddress
{
get { return _WaveDataStartAddress; }
set { SetProperty(ref _WaveDataStartAddress, value); }
}
private int _WavePointRegisterCount = 12;
public int WavePointRegisterCount
{
get { return _WavePointRegisterCount; }
set { SetProperty(ref _WavePointRegisterCount, value); }
}
private int _MaxWavePoints = 500;
public int MaxWavePoints
{
get { return _MaxWavePoints; }
set { SetProperty(ref _MaxWavePoints, value); }
}
#endregion
#region 曲线上下限
private float _TorqueUpperLimit = 1.0f;
public float TorqueUpperLimit
{
get { return _TorqueUpperLimit; }
set { SetProperty(ref _TorqueUpperLimit, value); }
}
private float _TorqueLowerLimit = 0.5f;
public float TorqueLowerLimit
{
get { return _TorqueLowerLimit; }
set { SetProperty(ref _TorqueLowerLimit, value); }
}
private string _LockCurveImageFolder = "..//LockCurve";
public string LockCurveImageFolder
{
get { return _LockCurveImageFolder; }
set { SetProperty(ref _LockCurveImageFolder, value); }
}
#endregion
public ModbusTcpMasterConfig Clone()
{
return JsonConvert.DeserializeObject(
JsonConvert.SerializeObject(this));
}
}
}