Files
ADP/BenchMovementModule/ViewModels/BenchMovementViewModel.cs
2026-07-03 14:10:52 +08:00

413 lines
11 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.Windows.Input;
using UIShare.ViewModelBase;
namespace BenchMovementModule.ViewModels
{
public class BenchMovementViewModel : NavigateViewModelBase, IRegionMemberLifetime, IDisposable
{
#region
public bool KeepAlive => true;
// --- 1. 台架位置区 ---
private double _posX;
public double PosX
{
get => _posX;
set => SetProperty(ref _posX, value);
}
private double _posY;
public double PosY
{
get => _posY;
set => SetProperty(ref _posY, value);
}
private double _posZ;
public double PosZ
{
get => _posZ;
set => SetProperty(ref _posZ, value);
}
// --- 2. 信号回读区 ---
private double _pos1X;
public double Pos1X
{
get => _pos1X;
set => SetProperty(ref _pos1X, value);
}
private int _pos1Quality;
public int Pos1Quality
{
get => _pos1Quality;
set => SetProperty(ref _pos1Quality, value);
}
private double _pos2X;
public double Pos2X
{
get => _pos2X;
set => SetProperty(ref _pos2X, value);
}
private int _pos2Quality;
public int Pos2Quality
{
get => _pos2Quality;
set => SetProperty(ref _pos2Quality, value);
}
private double _pos1Y;
public double Pos1Y
{
get => _pos1Y;
set => SetProperty(ref _pos1Y, value);
}
private double _pos2Y;
public double Pos2Y
{
get => _pos2Y;
set => SetProperty(ref _pos2Y, value);
}
// --- 3. 扫描参数区 ---
private double _scanStepX = 10;
public double ScanStepX
{
get => _scanStepX;
set => SetProperty(ref _scanStepX, value);
}
private double _scanStartX = -120;
public double ScanStartX
{
get => _scanStartX;
set => SetProperty(ref _scanStartX, value);
}
private double _scanEndX = 120;
public double ScanEndX
{
get => _scanEndX;
set => SetProperty(ref _scanEndX, value);
}
private double _scanStepY = 10;
public double ScanStepY
{
get => _scanStepY;
set => SetProperty(ref _scanStepY, value);
}
private double _scanStartY = -120;
public double ScanStartY
{
get => _scanStartY;
set => SetProperty(ref _scanStartY, value);
}
private double _scanEndY = 120;
public double ScanEndY
{
get => _scanEndY;
set => SetProperty(ref _scanEndY, value);
}
private double _scanStepZ = 1;
public double ScanStepZ
{
get => _scanStepZ;
set => SetProperty(ref _scanStepZ, value);
}
private double _scanStartZ = 0;
public double ScanStartZ
{
get => _scanStartZ;
set => SetProperty(ref _scanStartZ, value);
}
private double _scanEndZ = 0;
public double ScanEndZ
{
get => _scanEndZ;
set => SetProperty(ref _scanEndZ, value);
}
// --- 4. 寸动参数区 ---
private double _jogX;
public double JogX
{
get => _jogX;
set => SetProperty(ref _jogX, value);
}
private double _jogY;
public double JogY
{
get => _jogY;
set => SetProperty(ref _jogY, value);
}
private double _jogZ;
public double JogZ
{
get => _jogZ;
set => SetProperty(ref _jogZ, value);
}
// --- 5. 设置页网络及PLC参数 ---
private string _plcIp = "192.168.0.30";
public string PlcIp
{
get => _plcIp;
set => SetProperty(ref _plcIp, value);
}
private int _plcPort = 502;
public int PlcPort
{
get => _plcPort;
set => SetProperty(ref _plcPort, value);
}
// --- 6. 设置页:速度与零点设定 ---
private double _speedX;
public double SpeedX
{
get => _speedX;
set => SetProperty(ref _speedX, value);
}
private double _speedY;
public double SpeedY
{
get => _speedY;
set => SetProperty(ref _speedY, value);
}
private double _speedZ;
public double SpeedZ
{
get => _speedZ;
set => SetProperty(ref _speedZ, value);
}
private double _zeroX;
public double ZeroX
{
get => _zeroX;
set => SetProperty(ref _zeroX, value);
}
private double _zeroY;
public double ZeroY
{
get => _zeroY;
set => SetProperty(ref _zeroY, value);
}
private double _zeroZ;
public double ZeroZ
{
get => _zeroZ;
set => SetProperty(ref _zeroZ, value);
}
// --- 7. 设置页CAN设定信号映射 ---
private int _canChannel = 0;
public int CanChannel
{
get => _canChannel;
set => SetProperty(ref _canChannel, value);
}
private string _canMsgId = "0X0";
public string CanMsgId
{
get => _canMsgId;
set => SetProperty(ref _canMsgId, value);
}
private string _canMsgName = string.Empty;
public string CanMsgName
{
get => _canMsgName;
set => SetProperty(ref _canMsgName, value);
}
private string _sigPos1X = string.Empty;
public string SigPos1X
{
get => _sigPos1X;
set => SetProperty(ref _sigPos1X, value);
}
private string _sigPos2X = string.Empty;
public string SigPos2X
{
get => _sigPos2X;
set => SetProperty(ref _sigPos2X, value);
}
private string _sigPos1Y = string.Empty;
public string SigPos1Y
{
get => _sigPos1Y;
set => SetProperty(ref _sigPos1Y, value);
}
private string _sigPos2Y = string.Empty;
public string SigPos2Y
{
get => _sigPos2Y;
set => SetProperty(ref _sigPos2Y, value);
}
private string _sigPos1Quality = string.Empty;
public string SigPos1Quality
{
get => _sigPos1Quality;
set => SetProperty(ref _sigPos1Quality, value);
}
private string _sigPos2Quality = string.Empty;
public string SigPos2Quality
{
get => _sigPos2Quality;
set => SetProperty(ref _sigPos2Quality, value);
}
#endregion
#region
// 扫描控制面板命令
public ICommand StartScanCommand { get; }
public ICommand StopScanCommand { get; }
public ICommand GoHomeCommand { get; }
// 寸动执行单轴移动
public ICommand MoveXCommand { get; }
public ICommand MoveYCommand { get; }
public ICommand MoveZCommand { get; }
// 全局控制
public ICommand EmergencyStopCommand { get; }
// 参数设置应用命令
public ICommand ApplyNetworkCommand { get; }
public ICommand SetSpeedCommand { get; }
public ICommand SetZeroCommand { get; }
#endregion
#region
private readonly IContainerProvider _containerProvider;
private bool _isInitiated = false;
private string _testStatus = string.Empty;
#endregion
public BenchMovementViewModel(IContainerProvider containerProvider) : base(containerProvider)
{
_containerProvider = containerProvider;
// 初始化扫描控制命令绑定
StartScanCommand = new DelegateCommand(OnStartScan);
StopScanCommand = new DelegateCommand(OnStopScan);
GoHomeCommand = new DelegateCommand(OnGoHome);
// 初始化寸动命令绑定
MoveXCommand = new DelegateCommand(OnMoveX);
MoveYCommand = new DelegateCommand(OnMoveY);
MoveZCommand = new DelegateCommand(OnMoveZ);
// 急停与设置保存
EmergencyStopCommand = new DelegateCommand(OnEmergencyStop);
ApplyNetworkCommand = new DelegateCommand(OnApplyNetwork);
SetSpeedCommand = new DelegateCommand(OnSetSpeed);
SetZeroCommand = new DelegateCommand(OnSetZero);
}
#region
private void OnStartScan()
{
// TODO: 等协议到了处理开始扫描
}
private void OnStopScan()
{
// TODO: 等协议到了处理停止扫描
}
private void OnGoHome()
{
// TODO: 等协议到了处理台架回原点逻辑
}
private void OnMoveX()
{
// TODO: 执行单轴X向绝对位置寸动
}
private void OnMoveY()
{
// TODO: 执行单轴Y向绝对位置寸动
}
private void OnMoveZ()
{
// TODO: 执行单轴Z向绝对位置寸动
}
private void OnEmergencyStop()
{
// TODO: 全局急停高优先级报文/IO发送
}
private void OnApplyNetwork()
{
// TODO: 应用PLC的IP和端口网络连接配置
}
private void OnSetSpeed()
{
// TODO: 发送三轴移动速度设定参数
}
private void OnSetZero()
{
// TODO: 发送台架绝对位置零点校准设定
}
#endregion
#region
public override void OnNavigatedTo(NavigationContext navigationContext)
{
base.OnNavigatedTo(navigationContext);
if (!_isInitiated && navigationContext.Parameters.ContainsKey("Name"))
{
_testStatus = navigationContext.Parameters.GetValue<string>("Name");
// TODO: 若后续需要从全局环境 Scope 字典中加载参数配置,可以在此处对齐获取:
// var scope = _globalInfo.ScopeDic[_testStatus];
_isInitiated = true;
}
}
public void Dispose()
{
// 用于界面关闭或Region注销时的资源释放例如解除事件订阅、断开临时Socket通道、清空通信缓冲
}
#endregion
}
}