init commit
This commit is contained in:
@@ -0,0 +1,263 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SimpleCore.Library;
|
||||
|
||||
namespace StandardScene.ExtendDevice.ButtonBox
|
||||
{
|
||||
/// <summary>
|
||||
/// 按钮状态枚举
|
||||
/// </summary>
|
||||
public enum ButtonState
|
||||
{
|
||||
/// <summary>
|
||||
/// 未按下
|
||||
/// </summary>
|
||||
Released = 0,
|
||||
|
||||
/// <summary>
|
||||
/// 已按下
|
||||
/// </summary>
|
||||
Pressed = 1,
|
||||
|
||||
/// <summary>
|
||||
/// 未知状态
|
||||
/// </summary>
|
||||
Unknown = 2
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 按钮盒状态枚举
|
||||
/// </summary>
|
||||
public enum ButtonBoxState
|
||||
{
|
||||
/// <summary>
|
||||
/// 离线
|
||||
/// </summary>
|
||||
Offline = 0,
|
||||
|
||||
/// <summary>
|
||||
/// 在线
|
||||
/// </summary>
|
||||
Online = 1,
|
||||
|
||||
/// <summary>
|
||||
/// 连接中
|
||||
/// </summary>
|
||||
Connecting = 2,
|
||||
|
||||
/// <summary>
|
||||
/// 错误
|
||||
/// </summary>
|
||||
Error = 3
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 基础按钮盒类,包含状态机
|
||||
/// </summary>
|
||||
public abstract class BasicButtonBox
|
||||
{
|
||||
/// <summary>
|
||||
/// 按钮盒索引
|
||||
/// </summary>
|
||||
public int Index { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// IP地址
|
||||
/// </summary>
|
||||
public string Ip { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 端口
|
||||
/// </summary>
|
||||
public int Port { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 按钮盒状态
|
||||
/// </summary>
|
||||
public ButtonBoxState State { get; protected set; } = ButtonBoxState.Offline;
|
||||
|
||||
/// <summary>
|
||||
/// 是否在线
|
||||
/// </summary>
|
||||
public bool IsOnline => State == ButtonBoxState.Online;
|
||||
|
||||
/// <summary>
|
||||
/// 按钮状态字典,键为按钮索引
|
||||
/// </summary>
|
||||
public Dictionary<int, ButtonState> ButtonStates { get; protected set; } = new Dictionary<int, ButtonState>();
|
||||
|
||||
/// <summary>
|
||||
/// 按钮配置信息字典,键为按钮索引
|
||||
/// </summary>
|
||||
public Dictionary<int, ButtonModel> ButtonConfigs { get; protected set; } = new Dictionary<int, ButtonModel>();
|
||||
|
||||
/// <summary>
|
||||
/// 按钮动作执行后清零对应寄存器:默认空实现,具体盒型(如 Azowie)按需重写。
|
||||
/// 用于解耦 ButtonMission 对具体盒型的 is 判断,便于驱动外移至卫星 dll。
|
||||
/// </summary>
|
||||
public virtual void ClearButtonRegister(int buttonIndex)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 最后更新时间
|
||||
/// </summary>
|
||||
public DateTime LastUpdateTime { get; protected set; } = DateTime.Now;
|
||||
|
||||
/// <summary>
|
||||
/// 错误信息
|
||||
/// </summary>
|
||||
public string ErrorMessage { get; protected set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 更新按钮盒状态
|
||||
/// </summary>
|
||||
public virtual void UpdateState(ButtonBoxState newState, string errorMessage = "")
|
||||
{
|
||||
State = newState;
|
||||
ErrorMessage = errorMessage;
|
||||
LastUpdateTime = DateTime.Now;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新按钮状态
|
||||
/// </summary>
|
||||
/// <param name="buttonIndex">按钮索引</param>
|
||||
/// <param name="state">按钮状态</param>
|
||||
public virtual void UpdateButtonState(int buttonIndex, ButtonState state)
|
||||
{
|
||||
bool hadPrev = ButtonStates.TryGetValue(buttonIndex, out var previous);
|
||||
if (hadPrev && previous == state)
|
||||
return;
|
||||
|
||||
ButtonStates[buttonIndex] = state;
|
||||
if (hadPrev)
|
||||
Diagnosis.Post($"按钮盒{Index}_按钮{buttonIndex}:状态变更为{state}", "ButtonBox", false);
|
||||
LastUpdateTime = DateTime.Now;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取按钮状态
|
||||
/// </summary>
|
||||
/// <param name="buttonIndex">按钮索引</param>
|
||||
/// <returns>按钮状态,如果不存在则返回Unknown</returns>
|
||||
public virtual ButtonState GetButtonState(int buttonIndex)
|
||||
{
|
||||
return ButtonStates.TryGetValue(buttonIndex, out var state) ? state : ButtonState.Unknown;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化按钮状态
|
||||
/// </summary>
|
||||
/// <param name="buttonIndices">按钮索引列表</param>
|
||||
public virtual void InitializeButtons(List<int> buttonIndices)
|
||||
{
|
||||
ButtonStates.Clear();
|
||||
foreach (var index in buttonIndices)
|
||||
{
|
||||
ButtonStates[index] = ButtonState.Released;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化按钮配置信息
|
||||
/// </summary>
|
||||
/// <param name="buttonConfigs">按钮配置列表</param>
|
||||
public virtual void InitializeButtonConfigs(List<ButtonModel> buttonConfigs)
|
||||
{
|
||||
ButtonConfigs.Clear();
|
||||
if (buttonConfigs != null)
|
||||
{
|
||||
foreach (var config in buttonConfigs)
|
||||
{
|
||||
ButtonConfigs[config.Index] = new ButtonModel
|
||||
{
|
||||
Index = config.Index,
|
||||
TriggerMission = config.TriggerMission,
|
||||
TriggerMethod = config.TriggerMethod,
|
||||
TriggerMethodParams = config.TriggerMethodParams,
|
||||
TriggerState = config.TriggerState,
|
||||
TriggerDelay = config.TriggerDelay
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新按钮配置信息
|
||||
/// </summary>
|
||||
/// <param name="buttonConfigs">按钮配置列表</param>
|
||||
public virtual void UpdateButtonConfigs(List<ButtonModel> buttonConfigs)
|
||||
{
|
||||
if (buttonConfigs == null)
|
||||
{
|
||||
ButtonConfigs.Clear();
|
||||
return;
|
||||
}
|
||||
|
||||
// 创建配置字典
|
||||
var configDict = buttonConfigs.ToDictionary(b => b.Index);
|
||||
|
||||
// 删除配置中不存在的按钮
|
||||
var toRemove = ButtonConfigs.Keys.Where(k => !configDict.ContainsKey(k)).ToList();
|
||||
foreach (var key in toRemove)
|
||||
{
|
||||
ButtonConfigs.Remove(key);
|
||||
}
|
||||
|
||||
// 添加或更新按钮配置
|
||||
foreach (var config in buttonConfigs)
|
||||
{
|
||||
ButtonConfigs[config.Index] = new ButtonModel
|
||||
{
|
||||
Index = config.Index,
|
||||
TriggerMission = config.TriggerMission,
|
||||
TriggerMethod = config.TriggerMethod,
|
||||
TriggerMethodParams = config.TriggerMethodParams,
|
||||
TriggerState = config.TriggerState,
|
||||
TriggerDelay = config.TriggerDelay
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取按钮配置信息
|
||||
/// </summary>
|
||||
/// <param name="buttonIndex">按钮索引</param>
|
||||
/// <returns>按钮配置信息,如果不存在则返回null</returns>
|
||||
public virtual ButtonModel GetButtonConfig(int buttonIndex)
|
||||
{
|
||||
return ButtonConfigs.TryGetValue(buttonIndex, out var config) ? config : null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 连接按钮盒
|
||||
/// </summary>
|
||||
public virtual void Connect()
|
||||
{
|
||||
UpdateState(ButtonBoxState.Connecting);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 断开连接
|
||||
/// </summary>
|
||||
public virtual void Disconnect()
|
||||
{
|
||||
UpdateState(ButtonBoxState.Offline);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 当与此按钮盒绑定的业务方法执行完成后触发的回调。
|
||||
/// 子类可重写以实现按钮灯反馈、蜂鸣等效果。
|
||||
/// </summary>
|
||||
/// <param name="buttonConfig">触发本次调用的按钮配置</param>
|
||||
/// <param name="isSuccess">业务方法是否执行成功</param>
|
||||
public virtual void OnActionExecuted(ButtonModel buttonConfig, bool isSuccess)
|
||||
{
|
||||
// 基类默认不做任何事,由具体实现按需要重写
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,608 @@
|
||||
namespace StandardScene.ExtendDevice.ButtonBox
|
||||
{
|
||||
partial class ButtonBoxManager
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.buttonBoxListView = new System.Windows.Forms.ListView();
|
||||
this.columnHeaderBoxIndex = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
|
||||
this.columnHeaderIp = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
|
||||
this.columnHeaderPort = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
|
||||
this.columnHeaderType = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
|
||||
this.groupBoxButtonBox = new System.Windows.Forms.GroupBox();
|
||||
this.btnSaveButtonBox = new System.Windows.Forms.Button();
|
||||
this.btnDeleteButtonBox = new System.Windows.Forms.Button();
|
||||
this.btnAddButtonBox = new System.Windows.Forms.Button();
|
||||
this.labelType = new System.Windows.Forms.Label();
|
||||
this.comboBoxType = new System.Windows.Forms.ComboBox();
|
||||
this.labelBoxIndex = new System.Windows.Forms.Label();
|
||||
this.textBoxBoxIndex = new System.Windows.Forms.TextBox();
|
||||
this.labelPort = new System.Windows.Forms.Label();
|
||||
this.textBoxPort = new System.Windows.Forms.TextBox();
|
||||
this.labelIp = new System.Windows.Forms.Label();
|
||||
this.textBoxIp = new System.Windows.Forms.TextBox();
|
||||
this.buttonListView = new System.Windows.Forms.ListView();
|
||||
this.columnHeaderButtonIndex = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
|
||||
this.columnHeaderTriggerMission = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
|
||||
this.columnHeaderTriggerMethod = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
|
||||
this.columnHeaderTriggerMethodParams = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
|
||||
this.columnHeaderTriggerState = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
|
||||
this.columnHeaderTriggerDelay = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
|
||||
this.groupBoxButton = new System.Windows.Forms.GroupBox();
|
||||
this.btnSaveButton = new System.Windows.Forms.Button();
|
||||
this.btnDeleteButton = new System.Windows.Forms.Button();
|
||||
this.btnAddButton = new System.Windows.Forms.Button();
|
||||
this.labelTriggerMethodParams = new System.Windows.Forms.Label();
|
||||
this.textBoxTriggerMethodParams = new System.Windows.Forms.TextBox();
|
||||
this.labelTriggerMethod = new System.Windows.Forms.Label();
|
||||
this.textBoxTriggerMethod = new System.Windows.Forms.TextBox();
|
||||
this.labelTriggerMission = new System.Windows.Forms.Label();
|
||||
this.textBoxTriggerMission = new System.Windows.Forms.TextBox();
|
||||
this.labelButtonIndex = new System.Windows.Forms.Label();
|
||||
this.textBoxButtonIndex = new System.Windows.Forms.TextBox();
|
||||
this.labelTriggerState = new System.Windows.Forms.Label();
|
||||
this.comboBoxTriggerState = new System.Windows.Forms.ComboBox();
|
||||
this.labelTriggerDelay = new System.Windows.Forms.Label();
|
||||
this.textBoxTriggerDelay = new System.Windows.Forms.TextBox();
|
||||
this.labelTitle = new System.Windows.Forms.Label();
|
||||
this.groupBoxButtonBox.SuspendLayout();
|
||||
this.groupBoxButton.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// buttonBoxListView
|
||||
//
|
||||
this.buttonBoxListView.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||
| System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.buttonBoxListView.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.buttonBoxListView.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
|
||||
this.columnHeaderBoxIndex,
|
||||
this.columnHeaderIp,
|
||||
this.columnHeaderPort,
|
||||
this.columnHeaderType});
|
||||
this.buttonBoxListView.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.buttonBoxListView.FullRowSelect = true;
|
||||
this.buttonBoxListView.GridLines = true;
|
||||
this.buttonBoxListView.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
|
||||
this.buttonBoxListView.HideSelection = false;
|
||||
this.buttonBoxListView.Location = new System.Drawing.Point(15, 55);
|
||||
this.buttonBoxListView.MultiSelect = false;
|
||||
this.buttonBoxListView.Name = "buttonBoxListView";
|
||||
this.buttonBoxListView.OwnerDraw = true;
|
||||
this.buttonBoxListView.Size = new System.Drawing.Size(450, 290);
|
||||
this.buttonBoxListView.TabIndex = 0;
|
||||
this.buttonBoxListView.UseCompatibleStateImageBehavior = false;
|
||||
this.buttonBoxListView.View = System.Windows.Forms.View.Details;
|
||||
this.buttonBoxListView.SelectedIndexChanged += new System.EventHandler(this.buttonBoxListView_SelectedIndexChanged);
|
||||
//
|
||||
// columnHeaderBoxIndex
|
||||
//
|
||||
this.columnHeaderBoxIndex.Text = "编码";
|
||||
this.columnHeaderBoxIndex.Width = 70;
|
||||
//
|
||||
// columnHeaderIp
|
||||
//
|
||||
this.columnHeaderIp.Text = "IP地址";
|
||||
this.columnHeaderIp.Width = 130;
|
||||
//
|
||||
// columnHeaderPort
|
||||
//
|
||||
this.columnHeaderPort.Text = "端口";
|
||||
this.columnHeaderPort.Width = 90;
|
||||
//
|
||||
// columnHeaderType
|
||||
//
|
||||
this.columnHeaderType.Text = "类型";
|
||||
this.columnHeaderType.Width = 140;
|
||||
//
|
||||
// groupBoxButtonBox
|
||||
//
|
||||
this.groupBoxButtonBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.groupBoxButtonBox.Controls.Add(this.btnSaveButtonBox);
|
||||
this.groupBoxButtonBox.Controls.Add(this.btnDeleteButtonBox);
|
||||
this.groupBoxButtonBox.Controls.Add(this.btnAddButtonBox);
|
||||
this.groupBoxButtonBox.Controls.Add(this.labelType);
|
||||
this.groupBoxButtonBox.Controls.Add(this.comboBoxType);
|
||||
this.groupBoxButtonBox.Controls.Add(this.labelBoxIndex);
|
||||
this.groupBoxButtonBox.Controls.Add(this.textBoxBoxIndex);
|
||||
this.groupBoxButtonBox.Controls.Add(this.labelPort);
|
||||
this.groupBoxButtonBox.Controls.Add(this.textBoxPort);
|
||||
this.groupBoxButtonBox.Controls.Add(this.labelIp);
|
||||
this.groupBoxButtonBox.Controls.Add(this.textBoxIp);
|
||||
this.groupBoxButtonBox.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.groupBoxButtonBox.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(68)))), ((int)(((byte)(68)))), ((int)(((byte)(68)))));
|
||||
this.groupBoxButtonBox.Location = new System.Drawing.Point(15, 360);
|
||||
this.groupBoxButtonBox.Name = "groupBoxButtonBox";
|
||||
this.groupBoxButtonBox.Padding = new System.Windows.Forms.Padding(12, 10, 12, 12);
|
||||
this.groupBoxButtonBox.Size = new System.Drawing.Size(450, 250);
|
||||
this.groupBoxButtonBox.TabIndex = 1;
|
||||
this.groupBoxButtonBox.TabStop = false;
|
||||
this.groupBoxButtonBox.Text = "按钮盒信息";
|
||||
//
|
||||
// btnSaveButtonBox
|
||||
//
|
||||
this.btnSaveButtonBox.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(122)))), ((int)(((byte)(204)))));
|
||||
this.btnSaveButtonBox.FlatAppearance.BorderSize = 0;
|
||||
this.btnSaveButtonBox.FlatAppearance.MouseDownBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(92)))), ((int)(((byte)(153)))));
|
||||
this.btnSaveButtonBox.FlatAppearance.MouseOverBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(102)))), ((int)(((byte)(170)))));
|
||||
this.btnSaveButtonBox.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
|
||||
this.btnSaveButtonBox.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.btnSaveButtonBox.ForeColor = System.Drawing.Color.White;
|
||||
this.btnSaveButtonBox.Location = new System.Drawing.Point(330, 200);
|
||||
this.btnSaveButtonBox.Name = "btnSaveButtonBox";
|
||||
this.btnSaveButtonBox.Size = new System.Drawing.Size(100, 38);
|
||||
this.btnSaveButtonBox.TabIndex = 10;
|
||||
this.btnSaveButtonBox.Text = "保存";
|
||||
this.btnSaveButtonBox.UseVisualStyleBackColor = false;
|
||||
this.btnSaveButtonBox.Click += new System.EventHandler(this.btnSaveButtonBox_Click);
|
||||
//
|
||||
// btnDeleteButtonBox
|
||||
//
|
||||
this.btnDeleteButtonBox.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(53)))), ((int)(((byte)(69)))));
|
||||
this.btnDeleteButtonBox.FlatAppearance.BorderSize = 0;
|
||||
this.btnDeleteButtonBox.FlatAppearance.MouseDownBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(165)))), ((int)(((byte)(40)))), ((int)(((byte)(52)))));
|
||||
this.btnDeleteButtonBox.FlatAppearance.MouseOverBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(187)))), ((int)(((byte)(45)))), ((int)(((byte)(59)))));
|
||||
this.btnDeleteButtonBox.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
|
||||
this.btnDeleteButtonBox.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.btnDeleteButtonBox.ForeColor = System.Drawing.Color.White;
|
||||
this.btnDeleteButtonBox.Location = new System.Drawing.Point(220, 200);
|
||||
this.btnDeleteButtonBox.Name = "btnDeleteButtonBox";
|
||||
this.btnDeleteButtonBox.Size = new System.Drawing.Size(100, 38);
|
||||
this.btnDeleteButtonBox.TabIndex = 9;
|
||||
this.btnDeleteButtonBox.Text = "删除";
|
||||
this.btnDeleteButtonBox.UseVisualStyleBackColor = false;
|
||||
this.btnDeleteButtonBox.Click += new System.EventHandler(this.btnDeleteButtonBox_Click);
|
||||
//
|
||||
// btnAddButtonBox
|
||||
//
|
||||
this.btnAddButtonBox.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(40)))), ((int)(((byte)(167)))), ((int)(((byte)(69)))));
|
||||
this.btnAddButtonBox.FlatAppearance.BorderSize = 0;
|
||||
this.btnAddButtonBox.FlatAppearance.MouseDownBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(30)))), ((int)(((byte)(125)))), ((int)(((byte)(52)))));
|
||||
this.btnAddButtonBox.FlatAppearance.MouseOverBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(33)))), ((int)(((byte)(136)))), ((int)(((byte)(56)))));
|
||||
this.btnAddButtonBox.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
|
||||
this.btnAddButtonBox.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.btnAddButtonBox.ForeColor = System.Drawing.Color.White;
|
||||
this.btnAddButtonBox.Location = new System.Drawing.Point(110, 200);
|
||||
this.btnAddButtonBox.Name = "btnAddButtonBox";
|
||||
this.btnAddButtonBox.Size = new System.Drawing.Size(100, 38);
|
||||
this.btnAddButtonBox.TabIndex = 8;
|
||||
this.btnAddButtonBox.Text = "添加";
|
||||
this.btnAddButtonBox.UseVisualStyleBackColor = false;
|
||||
this.btnAddButtonBox.Click += new System.EventHandler(this.btnAddButtonBox_Click);
|
||||
//
|
||||
// labelType
|
||||
//
|
||||
this.labelType.AutoSize = true;
|
||||
this.labelType.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.labelType.Location = new System.Drawing.Point(28, 168);
|
||||
this.labelType.Name = "labelType";
|
||||
this.labelType.Size = new System.Drawing.Size(65, 24);
|
||||
this.labelType.TabIndex = 7;
|
||||
this.labelType.Text = "类型:";
|
||||
//
|
||||
// comboBoxType
|
||||
//
|
||||
this.comboBoxType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.comboBoxType.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.comboBoxType.FormattingEnabled = true;
|
||||
this.comboBoxType.Location = new System.Drawing.Point(110, 165);
|
||||
this.comboBoxType.Name = "comboBoxType";
|
||||
this.comboBoxType.Size = new System.Drawing.Size(320, 32);
|
||||
this.comboBoxType.TabIndex = 6;
|
||||
//
|
||||
// labelBoxIndex
|
||||
//
|
||||
this.labelBoxIndex.AutoSize = true;
|
||||
this.labelBoxIndex.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.labelBoxIndex.Location = new System.Drawing.Point(28, 48);
|
||||
this.labelBoxIndex.Name = "labelBoxIndex";
|
||||
this.labelBoxIndex.Size = new System.Drawing.Size(65, 24);
|
||||
this.labelBoxIndex.TabIndex = 1;
|
||||
this.labelBoxIndex.Text = "编码:";
|
||||
//
|
||||
// textBoxBoxIndex
|
||||
//
|
||||
this.textBoxBoxIndex.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.textBoxBoxIndex.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.textBoxBoxIndex.Location = new System.Drawing.Point(110, 45);
|
||||
this.textBoxBoxIndex.Name = "textBoxBoxIndex";
|
||||
this.textBoxBoxIndex.Size = new System.Drawing.Size(320, 30);
|
||||
this.textBoxBoxIndex.TabIndex = 0;
|
||||
//
|
||||
// labelIp
|
||||
//
|
||||
this.labelIp.AutoSize = true;
|
||||
this.labelIp.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.labelIp.Location = new System.Drawing.Point(18, 88);
|
||||
this.labelIp.Name = "labelIp";
|
||||
this.labelIp.Size = new System.Drawing.Size(85, 24);
|
||||
this.labelIp.TabIndex = 3;
|
||||
this.labelIp.Text = "IP地址:";
|
||||
//
|
||||
// textBoxIp
|
||||
//
|
||||
this.textBoxIp.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.textBoxIp.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.textBoxIp.Location = new System.Drawing.Point(110, 85);
|
||||
this.textBoxIp.Name = "textBoxIp";
|
||||
this.textBoxIp.Size = new System.Drawing.Size(320, 30);
|
||||
this.textBoxIp.TabIndex = 2;
|
||||
this.textBoxIp.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))));
|
||||
//
|
||||
// labelPort
|
||||
//
|
||||
this.labelPort.AutoSize = true;
|
||||
this.labelPort.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.labelPort.Location = new System.Drawing.Point(28, 128);
|
||||
this.labelPort.Name = "labelPort";
|
||||
this.labelPort.Size = new System.Drawing.Size(65, 24);
|
||||
this.labelPort.TabIndex = 5;
|
||||
this.labelPort.Text = "端口:";
|
||||
//
|
||||
// textBoxPort
|
||||
//
|
||||
this.textBoxPort.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.textBoxPort.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.textBoxPort.Location = new System.Drawing.Point(110, 125);
|
||||
this.textBoxPort.Name = "textBoxPort";
|
||||
this.textBoxPort.Size = new System.Drawing.Size(320, 30);
|
||||
this.textBoxPort.TabIndex = 4;
|
||||
//
|
||||
// buttonListView
|
||||
//
|
||||
this.buttonListView.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||
| System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.buttonListView.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.buttonListView.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
|
||||
this.columnHeaderButtonIndex,
|
||||
this.columnHeaderTriggerState,
|
||||
this.columnHeaderTriggerDelay,
|
||||
this.columnHeaderTriggerMission,
|
||||
this.columnHeaderTriggerMethod,
|
||||
this.columnHeaderTriggerMethodParams});
|
||||
this.buttonListView.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.buttonListView.FullRowSelect = true;
|
||||
this.buttonListView.GridLines = true;
|
||||
this.buttonListView.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
|
||||
this.buttonListView.HideSelection = false;
|
||||
this.buttonListView.Location = new System.Drawing.Point(483, 55);
|
||||
this.buttonListView.MultiSelect = false;
|
||||
this.buttonListView.Name = "buttonListView";
|
||||
this.buttonListView.OwnerDraw = true;
|
||||
this.buttonListView.Size = new System.Drawing.Size(700, 290);
|
||||
this.buttonListView.TabIndex = 2;
|
||||
this.buttonListView.UseCompatibleStateImageBehavior = false;
|
||||
this.buttonListView.View = System.Windows.Forms.View.Details;
|
||||
this.buttonListView.SelectedIndexChanged += new System.EventHandler(this.buttonListView_SelectedIndexChanged);
|
||||
//
|
||||
// columnHeaderButtonIndex
|
||||
//
|
||||
this.columnHeaderButtonIndex.Text = "编码";
|
||||
this.columnHeaderButtonIndex.Width = 70;
|
||||
//
|
||||
// columnHeaderTriggerState
|
||||
//
|
||||
this.columnHeaderTriggerState.Text = "触发状态";
|
||||
this.columnHeaderTriggerState.Width = 100;
|
||||
//
|
||||
// columnHeaderTriggerDelay
|
||||
//
|
||||
this.columnHeaderTriggerDelay.Text = "触发延迟";
|
||||
this.columnHeaderTriggerDelay.Width = 90;
|
||||
//
|
||||
// columnHeaderTriggerMission
|
||||
//
|
||||
this.columnHeaderTriggerMission.Text = "触发任务";
|
||||
this.columnHeaderTriggerMission.Width = 140;
|
||||
//
|
||||
// columnHeaderTriggerMethod
|
||||
//
|
||||
this.columnHeaderTriggerMethod.Text = "触发方法";
|
||||
this.columnHeaderTriggerMethod.Width = 140;
|
||||
//
|
||||
// columnHeaderTriggerMethodParams
|
||||
//
|
||||
this.columnHeaderTriggerMethodParams.Text = "方法参数";
|
||||
this.columnHeaderTriggerMethodParams.Width = 160;
|
||||
//
|
||||
// groupBoxButton
|
||||
//
|
||||
this.groupBoxButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.groupBoxButton.Controls.Add(this.btnSaveButton);
|
||||
this.groupBoxButton.Controls.Add(this.btnDeleteButton);
|
||||
this.groupBoxButton.Controls.Add(this.btnAddButton);
|
||||
this.groupBoxButton.Controls.Add(this.labelTriggerMethodParams);
|
||||
this.groupBoxButton.Controls.Add(this.textBoxTriggerMethodParams);
|
||||
this.groupBoxButton.Controls.Add(this.labelTriggerMethod);
|
||||
this.groupBoxButton.Controls.Add(this.textBoxTriggerMethod);
|
||||
this.groupBoxButton.Controls.Add(this.labelTriggerMission);
|
||||
this.groupBoxButton.Controls.Add(this.textBoxTriggerMission);
|
||||
this.groupBoxButton.Controls.Add(this.labelButtonIndex);
|
||||
this.groupBoxButton.Controls.Add(this.textBoxButtonIndex);
|
||||
this.groupBoxButton.Controls.Add(this.labelTriggerState);
|
||||
this.groupBoxButton.Controls.Add(this.comboBoxTriggerState);
|
||||
this.groupBoxButton.Controls.Add(this.labelTriggerDelay);
|
||||
this.groupBoxButton.Controls.Add(this.textBoxTriggerDelay);
|
||||
this.groupBoxButton.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.groupBoxButton.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(68)))), ((int)(((byte)(68)))), ((int)(((byte)(68)))));
|
||||
this.groupBoxButton.Location = new System.Drawing.Point(483, 360);
|
||||
this.groupBoxButton.Name = "groupBoxButton";
|
||||
this.groupBoxButton.Padding = new System.Windows.Forms.Padding(12, 10, 12, 12);
|
||||
this.groupBoxButton.Size = new System.Drawing.Size(700, 250);
|
||||
this.groupBoxButton.TabIndex = 3;
|
||||
this.groupBoxButton.TabStop = false;
|
||||
this.groupBoxButton.Text = "按钮信息";
|
||||
//
|
||||
// btnSaveButton
|
||||
//
|
||||
this.btnSaveButton.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(122)))), ((int)(((byte)(204)))));
|
||||
this.btnSaveButton.FlatAppearance.BorderSize = 0;
|
||||
this.btnSaveButton.FlatAppearance.MouseDownBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(92)))), ((int)(((byte)(153)))));
|
||||
this.btnSaveButton.FlatAppearance.MouseOverBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(102)))), ((int)(((byte)(170)))));
|
||||
this.btnSaveButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
|
||||
this.btnSaveButton.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.btnSaveButton.ForeColor = System.Drawing.Color.White;
|
||||
this.btnSaveButton.Location = new System.Drawing.Point(580, 180);
|
||||
this.btnSaveButton.Name = "btnSaveButton";
|
||||
this.btnSaveButton.Size = new System.Drawing.Size(100, 38);
|
||||
this.btnSaveButton.TabIndex = 13;
|
||||
this.btnSaveButton.Text = "保存";
|
||||
this.btnSaveButton.UseVisualStyleBackColor = false;
|
||||
this.btnSaveButton.Click += new System.EventHandler(this.btnSaveButton_Click);
|
||||
//
|
||||
// btnDeleteButton
|
||||
//
|
||||
this.btnDeleteButton.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(53)))), ((int)(((byte)(69)))));
|
||||
this.btnDeleteButton.FlatAppearance.BorderSize = 0;
|
||||
this.btnDeleteButton.FlatAppearance.MouseDownBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(165)))), ((int)(((byte)(40)))), ((int)(((byte)(52)))));
|
||||
this.btnDeleteButton.FlatAppearance.MouseOverBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(187)))), ((int)(((byte)(45)))), ((int)(((byte)(59)))));
|
||||
this.btnDeleteButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
|
||||
this.btnDeleteButton.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.btnDeleteButton.ForeColor = System.Drawing.Color.White;
|
||||
this.btnDeleteButton.Location = new System.Drawing.Point(470, 180);
|
||||
this.btnDeleteButton.Name = "btnDeleteButton";
|
||||
this.btnDeleteButton.Size = new System.Drawing.Size(100, 38);
|
||||
this.btnDeleteButton.TabIndex = 12;
|
||||
this.btnDeleteButton.Text = "删除";
|
||||
this.btnDeleteButton.UseVisualStyleBackColor = false;
|
||||
this.btnDeleteButton.Click += new System.EventHandler(this.btnDeleteButton_Click);
|
||||
//
|
||||
// btnAddButton
|
||||
//
|
||||
this.btnAddButton.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(40)))), ((int)(((byte)(167)))), ((int)(((byte)(69)))));
|
||||
this.btnAddButton.FlatAppearance.BorderSize = 0;
|
||||
this.btnAddButton.FlatAppearance.MouseDownBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(30)))), ((int)(((byte)(125)))), ((int)(((byte)(52)))));
|
||||
this.btnAddButton.FlatAppearance.MouseOverBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(33)))), ((int)(((byte)(136)))), ((int)(((byte)(56)))));
|
||||
this.btnAddButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
|
||||
this.btnAddButton.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.btnAddButton.ForeColor = System.Drawing.Color.White;
|
||||
this.btnAddButton.Location = new System.Drawing.Point(360, 180);
|
||||
this.btnAddButton.Name = "btnAddButton";
|
||||
this.btnAddButton.Size = new System.Drawing.Size(100, 38);
|
||||
this.btnAddButton.TabIndex = 11;
|
||||
this.btnAddButton.Text = "添加";
|
||||
this.btnAddButton.UseVisualStyleBackColor = false;
|
||||
this.btnAddButton.Click += new System.EventHandler(this.btnAddButton_Click);
|
||||
//
|
||||
// labelTriggerMethodParams
|
||||
//
|
||||
this.labelTriggerMethodParams.AutoSize = true;
|
||||
this.labelTriggerMethodParams.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.labelTriggerMethodParams.Location = new System.Drawing.Point(370, 128);
|
||||
this.labelTriggerMethodParams.Name = "labelTriggerMethodParams";
|
||||
this.labelTriggerMethodParams.Size = new System.Drawing.Size(103, 24);
|
||||
this.labelTriggerMethodParams.TabIndex = 11;
|
||||
this.labelTriggerMethodParams.Text = "方法参数:";
|
||||
//
|
||||
// textBoxTriggerMethodParams
|
||||
//
|
||||
this.textBoxTriggerMethodParams.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.textBoxTriggerMethodParams.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.textBoxTriggerMethodParams.Location = new System.Drawing.Point(490, 125);
|
||||
this.textBoxTriggerMethodParams.Name = "textBoxTriggerMethodParams";
|
||||
this.textBoxTriggerMethodParams.Size = new System.Drawing.Size(190, 30);
|
||||
this.textBoxTriggerMethodParams.TabIndex = 10;
|
||||
//
|
||||
// labelTriggerState
|
||||
//
|
||||
this.labelTriggerState.AutoSize = true;
|
||||
this.labelTriggerState.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.labelTriggerState.Location = new System.Drawing.Point(370, 48);
|
||||
this.labelTriggerState.Name = "labelTriggerState";
|
||||
this.labelTriggerState.Size = new System.Drawing.Size(103, 24);
|
||||
this.labelTriggerState.TabIndex = 3;
|
||||
this.labelTriggerState.Text = "触发状态:";
|
||||
//
|
||||
// comboBoxTriggerState
|
||||
//
|
||||
this.comboBoxTriggerState.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.comboBoxTriggerState.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.comboBoxTriggerState.FormattingEnabled = true;
|
||||
this.comboBoxTriggerState.Location = new System.Drawing.Point(490, 45);
|
||||
this.comboBoxTriggerState.Name = "comboBoxTriggerState";
|
||||
this.comboBoxTriggerState.Size = new System.Drawing.Size(190, 32);
|
||||
this.comboBoxTriggerState.TabIndex = 2;
|
||||
//
|
||||
// labelTriggerDelay
|
||||
//
|
||||
this.labelTriggerDelay.AutoSize = true;
|
||||
this.labelTriggerDelay.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.labelTriggerDelay.Location = new System.Drawing.Point(28, 88);
|
||||
this.labelTriggerDelay.Name = "labelTriggerDelay";
|
||||
this.labelTriggerDelay.Size = new System.Drawing.Size(103, 24);
|
||||
this.labelTriggerDelay.TabIndex = 5;
|
||||
this.labelTriggerDelay.Text = "触发延迟:";
|
||||
//
|
||||
// textBoxTriggerDelay
|
||||
//
|
||||
this.textBoxTriggerDelay.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.textBoxTriggerDelay.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.textBoxTriggerDelay.Location = new System.Drawing.Point(150, 85);
|
||||
this.textBoxTriggerDelay.Name = "textBoxTriggerDelay";
|
||||
this.textBoxTriggerDelay.Size = new System.Drawing.Size(200, 30);
|
||||
this.textBoxTriggerDelay.TabIndex = 4;
|
||||
//
|
||||
// labelTriggerMethod
|
||||
//
|
||||
this.labelTriggerMethod.AutoSize = true;
|
||||
this.labelTriggerMethod.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.labelTriggerMethod.Location = new System.Drawing.Point(28, 128);
|
||||
this.labelTriggerMethod.Name = "labelTriggerMethod";
|
||||
this.labelTriggerMethod.Size = new System.Drawing.Size(103, 24);
|
||||
this.labelTriggerMethod.TabIndex = 9;
|
||||
this.labelTriggerMethod.Text = "触发方法:";
|
||||
//
|
||||
// textBoxTriggerMethod
|
||||
//
|
||||
this.textBoxTriggerMethod.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.textBoxTriggerMethod.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.textBoxTriggerMethod.Location = new System.Drawing.Point(150, 125);
|
||||
this.textBoxTriggerMethod.Name = "textBoxTriggerMethod";
|
||||
this.textBoxTriggerMethod.Size = new System.Drawing.Size(200, 30);
|
||||
this.textBoxTriggerMethod.TabIndex = 8;
|
||||
//
|
||||
// labelTriggerMission
|
||||
//
|
||||
this.labelTriggerMission.AutoSize = true;
|
||||
this.labelTriggerMission.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.labelTriggerMission.Location = new System.Drawing.Point(370, 88);
|
||||
this.labelTriggerMission.Name = "labelTriggerMission";
|
||||
this.labelTriggerMission.Size = new System.Drawing.Size(103, 24);
|
||||
this.labelTriggerMission.TabIndex = 7;
|
||||
this.labelTriggerMission.Text = "触发任务:";
|
||||
//
|
||||
// textBoxTriggerMission
|
||||
//
|
||||
this.textBoxTriggerMission.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.textBoxTriggerMission.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.textBoxTriggerMission.Location = new System.Drawing.Point(490, 85);
|
||||
this.textBoxTriggerMission.Name = "textBoxTriggerMission";
|
||||
this.textBoxTriggerMission.Size = new System.Drawing.Size(190, 30);
|
||||
this.textBoxTriggerMission.TabIndex = 6;
|
||||
//
|
||||
// labelButtonIndex
|
||||
//
|
||||
this.labelButtonIndex.AutoSize = true;
|
||||
this.labelButtonIndex.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.labelButtonIndex.Location = new System.Drawing.Point(28, 48);
|
||||
this.labelButtonIndex.Name = "labelButtonIndex";
|
||||
this.labelButtonIndex.Size = new System.Drawing.Size(65, 24);
|
||||
this.labelButtonIndex.TabIndex = 1;
|
||||
this.labelButtonIndex.Text = "编码:";
|
||||
//
|
||||
// textBoxButtonIndex
|
||||
//
|
||||
this.textBoxButtonIndex.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.textBoxButtonIndex.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.textBoxButtonIndex.Location = new System.Drawing.Point(150, 45);
|
||||
this.textBoxButtonIndex.Name = "textBoxButtonIndex";
|
||||
this.textBoxButtonIndex.Size = new System.Drawing.Size(200, 30);
|
||||
this.textBoxButtonIndex.TabIndex = 0;
|
||||
//
|
||||
// labelTitle
|
||||
//
|
||||
this.labelTitle.AutoSize = true;
|
||||
this.labelTitle.Font = new System.Drawing.Font("微软雅黑", 16F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.labelTitle.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(51)))), ((int)(((byte)(51)))), ((int)(((byte)(51)))));
|
||||
this.labelTitle.Location = new System.Drawing.Point(15, 12);
|
||||
this.labelTitle.Name = "labelTitle";
|
||||
this.labelTitle.Size = new System.Drawing.Size(150, 42);
|
||||
this.labelTitle.TabIndex = 4;
|
||||
this.labelTitle.Text = "按钮盒管理";
|
||||
//
|
||||
// ButtonBoxManager
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 18F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(245)))), ((int)(((byte)(245)))), ((int)(((byte)(247)))));
|
||||
this.ClientSize = new System.Drawing.Size(1200, 620);
|
||||
this.Controls.Add(this.labelTitle);
|
||||
this.Controls.Add(this.groupBoxButton);
|
||||
this.Controls.Add(this.buttonListView);
|
||||
this.Controls.Add(this.groupBoxButtonBox);
|
||||
this.Controls.Add(this.buttonBoxListView);
|
||||
this.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.MinimumSize = new System.Drawing.Size(1200, 620);
|
||||
this.Name = "ButtonBoxManager";
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||
this.Text = "按钮盒管理";
|
||||
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.ButtonBoxManager_FormClosing);
|
||||
this.Load += new System.EventHandler(this.ButtonBoxManager_Load);
|
||||
this.groupBoxButtonBox.ResumeLayout(false);
|
||||
this.groupBoxButtonBox.PerformLayout();
|
||||
this.groupBoxButton.ResumeLayout(false);
|
||||
this.groupBoxButton.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.ListView buttonBoxListView;
|
||||
private System.Windows.Forms.ColumnHeader columnHeaderBoxIndex;
|
||||
private System.Windows.Forms.ColumnHeader columnHeaderIp;
|
||||
private System.Windows.Forms.ColumnHeader columnHeaderPort;
|
||||
private System.Windows.Forms.ColumnHeader columnHeaderType;
|
||||
private System.Windows.Forms.GroupBox groupBoxButtonBox;
|
||||
private System.Windows.Forms.TextBox textBoxIp;
|
||||
private System.Windows.Forms.Label labelIp;
|
||||
private System.Windows.Forms.Label labelPort;
|
||||
private System.Windows.Forms.TextBox textBoxPort;
|
||||
private System.Windows.Forms.Label labelBoxIndex;
|
||||
private System.Windows.Forms.TextBox textBoxBoxIndex;
|
||||
private System.Windows.Forms.Label labelType;
|
||||
private System.Windows.Forms.ComboBox comboBoxType;
|
||||
private System.Windows.Forms.Button btnAddButtonBox;
|
||||
private System.Windows.Forms.Button btnDeleteButtonBox;
|
||||
private System.Windows.Forms.Button btnSaveButtonBox;
|
||||
private System.Windows.Forms.ListView buttonListView;
|
||||
private System.Windows.Forms.ColumnHeader columnHeaderButtonIndex;
|
||||
private System.Windows.Forms.ColumnHeader columnHeaderTriggerMission;
|
||||
private System.Windows.Forms.ColumnHeader columnHeaderTriggerMethod;
|
||||
private System.Windows.Forms.ColumnHeader columnHeaderTriggerMethodParams;
|
||||
private System.Windows.Forms.GroupBox groupBoxButton;
|
||||
private System.Windows.Forms.Label labelButtonIndex;
|
||||
private System.Windows.Forms.TextBox textBoxButtonIndex;
|
||||
private System.Windows.Forms.Label labelTriggerMission;
|
||||
private System.Windows.Forms.TextBox textBoxTriggerMission;
|
||||
private System.Windows.Forms.Label labelTriggerMethod;
|
||||
private System.Windows.Forms.TextBox textBoxTriggerMethod;
|
||||
private System.Windows.Forms.Label labelTriggerMethodParams;
|
||||
private System.Windows.Forms.TextBox textBoxTriggerMethodParams;
|
||||
private System.Windows.Forms.Label labelTriggerState;
|
||||
private System.Windows.Forms.ComboBox comboBoxTriggerState;
|
||||
private System.Windows.Forms.Label labelTriggerDelay;
|
||||
private System.Windows.Forms.TextBox textBoxTriggerDelay;
|
||||
private System.Windows.Forms.ColumnHeader columnHeaderTriggerState;
|
||||
private System.Windows.Forms.ColumnHeader columnHeaderTriggerDelay;
|
||||
private System.Windows.Forms.Button btnAddButton;
|
||||
private System.Windows.Forms.Button btnDeleteButton;
|
||||
private System.Windows.Forms.Button btnSaveButton;
|
||||
private System.Windows.Forms.Label labelTitle;
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StandardScene.ExtendDevice.ButtonBox
|
||||
{
|
||||
/// <summary>
|
||||
/// 按钮盒模型
|
||||
/// </summary>
|
||||
public class ButtonBoxModel
|
||||
{
|
||||
public string Ip { get; set; } = string.Empty;
|
||||
public int Port { get; set; } = 0;
|
||||
public int Index { get; set; } = 0;
|
||||
public string Type { get; set; } = string.Empty;
|
||||
public List<ButtonModel> Buttons { get; set; } = new List<ButtonModel>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 按钮模型
|
||||
/// </summary>
|
||||
public class ButtonModel
|
||||
{
|
||||
public int Index { get; set; } = 0;
|
||||
public string TriggerMission { get; set; } = string.Empty;
|
||||
public string TriggerMethod { get; set; } = string.Empty;
|
||||
public string TriggerMethodParams { get; set; } = string.Empty;
|
||||
public string TriggerState { get; set; } = string.Empty;
|
||||
public ushort TriggerDelay { get; set; } = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,806 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using LessokajiWeaverUtilities.MagicAttributes;
|
||||
using LessokajiWeaverUtilities.Utilities;
|
||||
using SimpleLite;
|
||||
using SimpleLite.RCS;
|
||||
using SimpleLite.RCS.CarTypes;
|
||||
using SimpleCore;
|
||||
using SimpleCore.Library;
|
||||
using StandardScene;
|
||||
using StandardScene.Utils;
|
||||
|
||||
namespace StandardScene.ExtendDevice.ButtonBox
|
||||
{
|
||||
[MissionType(Name = "按钮进程")]
|
||||
[I18N.DocumentTranslation(Name = "ButtonMission",locale = "en")]
|
||||
public class ButtonMission:Mission
|
||||
{
|
||||
private const string DataFileName = "ButtonBoxConfig.json";
|
||||
private string _dataFilePath;
|
||||
|
||||
/// <summary>
|
||||
/// 当前所有按钮盒实例列表
|
||||
/// </summary>
|
||||
private List<BasicButtonBox> _buttonBoxes = new List<BasicButtonBox>();
|
||||
|
||||
/// <summary>
|
||||
/// 用于管理异步循环的取消令牌源
|
||||
/// </summary>
|
||||
private CancellationTokenSource _cancellationTokenSource;
|
||||
|
||||
/// <summary>
|
||||
/// 保存监控配置与状态的后台任务,便于关闭时等待
|
||||
/// </summary>
|
||||
private Task _configTask;
|
||||
|
||||
private Task _stateTask;
|
||||
|
||||
/// <summary>
|
||||
/// 同步锁,用于保护按钮盒列表的并发访问
|
||||
/// </summary>
|
||||
private readonly object _syncLock = new object();
|
||||
|
||||
[MethodMember(Name = "启动进程")]
|
||||
[I18N.DocumentTranslation(Name = "Start Mission", locale = "en")]
|
||||
public override void Execute()
|
||||
{
|
||||
// 设置数据文件路径
|
||||
_dataFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, DataFileName);
|
||||
|
||||
// 如果已经启动,先停止之前的循环
|
||||
StopInternalAsync().GetAwaiter().GetResult();
|
||||
|
||||
// 创建新的取消令牌源
|
||||
_cancellationTokenSource = new CancellationTokenSource();
|
||||
|
||||
// 启动异步循环
|
||||
var token = _cancellationTokenSource.Token;
|
||||
_configTask = Task.Run(async () => await MonitorButtonBoxConfigAsync(token), token);
|
||||
_stateTask = Task.Run(async () => await MonitorButtonStatesAsync(token), token);
|
||||
status.status = "Running";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步监控按钮盒配置文件
|
||||
/// </summary>
|
||||
private async Task MonitorButtonBoxConfigAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
while (!cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 读取配置文件
|
||||
var configButtonBoxes = LoadButtonBoxConfig();
|
||||
|
||||
// 同步按钮盒列表
|
||||
SyncButtonBoxes(configButtonBoxes);
|
||||
|
||||
// 等待10秒
|
||||
await Task.Delay(TimeSpan.FromSeconds(10), cancellationToken);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
// 正常取消,退出循环
|
||||
break;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// 记录错误,但继续运行
|
||||
Diagnosis.Log($"按钮盒配置监控错误: {ExceptionFormatter.FormatEx(ex)}", "ButtonMission", true);
|
||||
// 发生错误时等待5秒后重试
|
||||
try
|
||||
{
|
||||
await Task.Delay(TimeSpan.FromSeconds(5), cancellationToken);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 停止监控任务
|
||||
/// </summary>
|
||||
[MethodMember(Name = "停止进程")]
|
||||
[I18N.DocumentTranslation(Name = "Stop Mission", locale = "en")]
|
||||
public void Stop()
|
||||
{
|
||||
StopInternalAsync().GetAwaiter().GetResult();
|
||||
status.status = "/";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 取消并释放当前的取消令牌源
|
||||
/// </summary>
|
||||
private async Task StopInternalAsync()
|
||||
{
|
||||
var cts = Interlocked.Exchange(ref _cancellationTokenSource, null);
|
||||
var configTask = Interlocked.Exchange(ref _configTask, null);
|
||||
var stateTask = Interlocked.Exchange(ref _stateTask, null);
|
||||
|
||||
if (cts == null && configTask == null && stateTask == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
cts?.Cancel();
|
||||
}
|
||||
catch (ObjectDisposedException)
|
||||
{
|
||||
// 已释放,忽略
|
||||
}
|
||||
|
||||
var runningTasks = new[] { configTask, stateTask }
|
||||
.Where(t => t != null)
|
||||
.ToArray();
|
||||
|
||||
if (runningTasks.Length > 0)
|
||||
{
|
||||
var aggregateTask = Task.WhenAll(runningTasks);
|
||||
var timeoutTask = Task.Delay(TimeSpan.FromSeconds(5));
|
||||
var completedTask = await Task.WhenAny(aggregateTask, timeoutTask).ConfigureAwait(false);
|
||||
|
||||
if (completedTask == timeoutTask)
|
||||
{
|
||||
Diagnosis.Log("停止按钮监控任务超时", "ButtonMission", true);
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
await aggregateTask.ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Diagnosis.Log($"停止按钮监控任务时发生异常: {ExceptionFormatter.FormatEx(ex)}", "ButtonMission", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cts?.Dispose();
|
||||
|
||||
DisconnectAllButtonBoxes();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 断开所有按钮盒连接
|
||||
/// </summary>
|
||||
private void DisconnectAllButtonBoxes()
|
||||
{
|
||||
List<BasicButtonBox> snapshot;
|
||||
lock (_syncLock)
|
||||
{
|
||||
snapshot = _buttonBoxes.ToList();
|
||||
}
|
||||
|
||||
foreach (var box in snapshot)
|
||||
{
|
||||
try
|
||||
{
|
||||
box.Disconnect();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Diagnosis.Log($"停止按钮盒失败: Index={box.Index}, Error={ExceptionFormatter.FormatEx(ex)}", "ButtonMission", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 监控按钮状态,用于触发按钮动作
|
||||
/// </summary>
|
||||
private async Task MonitorButtonStatesAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
while (!cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
try
|
||||
{
|
||||
List<(BasicButtonBox Box, ButtonModel Config)> snapshot;
|
||||
lock (_syncLock)
|
||||
{
|
||||
snapshot = _buttonBoxes
|
||||
.SelectMany(box => box.ButtonConfigs.Values.Select(cfg => (Box: box, Config: cfg)))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
foreach (var (box, config) in snapshot)
|
||||
{
|
||||
if (box == null || config == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(config.TriggerMission) ||
|
||||
string.IsNullOrWhiteSpace(config.TriggerMethod))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var desiredState = ButtonState.Pressed;
|
||||
if (!string.IsNullOrWhiteSpace(config.TriggerState) &&
|
||||
Enum.TryParse(config.TriggerState, out ButtonState parsedState))
|
||||
{
|
||||
desiredState = parsedState;
|
||||
}
|
||||
|
||||
var currentState = box.GetButtonState(config.Index);
|
||||
bool isActive = currentState == desiredState&&box.IsOnline;
|
||||
|
||||
int delay = config.TriggerDelay;
|
||||
if (delay <= 0)
|
||||
{
|
||||
delay = 1;
|
||||
}
|
||||
|
||||
int uniqueId = unchecked((box.Index << 16) ^ config.Index);
|
||||
|
||||
LadderLogic.TriggerOnce(isActive, delay*1000, () =>
|
||||
{
|
||||
ExecuteButtonAction(config, box);
|
||||
}, uniqueId);
|
||||
}
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
break;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Diagnosis.Log($"按钮状态监控错误: {ExceptionFormatter.FormatEx(ex)}", "ButtonMission", true);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await Task.Delay(TimeSpan.FromMilliseconds(500), cancellationToken);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载按钮盒配置文件
|
||||
/// </summary>
|
||||
private List<ButtonBoxModel> LoadButtonBoxConfig()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (File.Exists(_dataFilePath))
|
||||
{
|
||||
var jsonContent = File.ReadAllText(_dataFilePath, Encoding.UTF8);
|
||||
if (!string.IsNullOrWhiteSpace(jsonContent))
|
||||
{
|
||||
var buttonBoxes = jsonContent.JsonTo<List<ButtonBoxModel>>();
|
||||
return buttonBoxes ?? new List<ButtonBoxModel>();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Diagnosis.Log($"加载按钮盒配置文件失败: {ExceptionFormatter.FormatEx(ex)}", "ButtonMission", true);
|
||||
}
|
||||
|
||||
return new List<ButtonBoxModel>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 同步按钮盒列表,根据配置文件进行增删改
|
||||
/// </summary>
|
||||
private void SyncButtonBoxes(List<ButtonBoxModel> configButtonBoxes)
|
||||
{
|
||||
var boxesToAdd = new List<ButtonBoxModel>();
|
||||
|
||||
lock (_syncLock)
|
||||
{
|
||||
// 创建配置中的按钮盒索引字典,用于快速查找
|
||||
var configDict = configButtonBoxes.ToDictionary(b => b.Index);
|
||||
|
||||
// 创建当前按钮盒索引字典
|
||||
var currentDict = _buttonBoxes.ToDictionary(b => b.Index);
|
||||
|
||||
// 1. 删除:在配置中不存在的按钮盒
|
||||
var toRemove = _buttonBoxes.Where(b => !configDict.ContainsKey(b.Index)).ToList();
|
||||
foreach (var buttonBox in toRemove)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 断开连接
|
||||
buttonBox.Disconnect();
|
||||
_buttonBoxes.Remove(buttonBox);
|
||||
Diagnosis.Post($"删除按钮盒: Index={buttonBox.Index}, IP={buttonBox.Ip}", "ButtonMission", true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Diagnosis.Log($"删除按钮盒失败: {ExceptionFormatter.FormatEx(ex)}", "ButtonMission", true);
|
||||
}
|
||||
}
|
||||
|
||||
// 2. 添加和修改:遍历配置中的按钮盒
|
||||
foreach (var configBox in configButtonBoxes)
|
||||
{
|
||||
if (currentDict.TryGetValue(configBox.Index, out var existingBox))
|
||||
{
|
||||
// 修改:检查是否需要更新
|
||||
if (ShouldUpdateButtonBox(existingBox, configBox))
|
||||
{
|
||||
try
|
||||
{
|
||||
UpdateButtonBox(existingBox, configBox);
|
||||
Diagnosis.Post($"更新按钮盒: Index={configBox.Index}, IP={configBox.Ip}, Type={configBox.Type}", "ButtonMission", true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Diagnosis.Log($"更新按钮盒失败: {ExceptionFormatter.FormatEx(ex)}", "ButtonMission", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
boxesToAdd.Add(configBox);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var configBox in boxesToAdd)
|
||||
{
|
||||
try
|
||||
{
|
||||
var newBox = CreateButtonBoxInstance(configBox);
|
||||
if (newBox != null)
|
||||
{
|
||||
lock (_syncLock)
|
||||
{
|
||||
_buttonBoxes.Add(newBox);
|
||||
}
|
||||
Diagnosis.Post($"添加按钮盒: Index={configBox.Index}, IP={configBox.Ip}, Type={configBox.Type}", "ButtonMission", true);
|
||||
}
|
||||
else
|
||||
{
|
||||
Diagnosis.Log($"无法创建按钮盒实例: Index={configBox.Index}, Type={configBox.Type}", "ButtonMission", true);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Diagnosis.Log($"添加按钮盒失败: {ExceptionFormatter.FormatEx(ex)}", "ButtonMission", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 判断是否需要更新按钮盒
|
||||
/// </summary>
|
||||
private bool ShouldUpdateButtonBox(BasicButtonBox existingBox, ButtonBoxModel configBox)
|
||||
{
|
||||
// 检查基本属性是否变更
|
||||
if (existingBox.Ip != configBox.Ip
|
||||
|| existingBox.Port != configBox.Port
|
||||
|| existingBox.GetType().Name != configBox.Type)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// 检查按钮信息是否变更
|
||||
return HasButtonConfigsChanged(existingBox, configBox);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查按钮配置信息是否变更
|
||||
/// </summary>
|
||||
private bool HasButtonConfigsChanged(BasicButtonBox existingBox, ButtonBoxModel configBox)
|
||||
{
|
||||
var configButtons = configBox.Buttons ?? new List<ButtonModel>();
|
||||
var configDict = configButtons.ToDictionary(b => b.Index);
|
||||
var existingDict = existingBox.ButtonConfigs;
|
||||
|
||||
// 检查按钮数量是否变化
|
||||
if (existingDict.Count != configDict.Count)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// 检查每个按钮的配置是否变化
|
||||
foreach (var configButton in configButtons)
|
||||
{
|
||||
if (!existingDict.TryGetValue(configButton.Index, out var existingButton))
|
||||
{
|
||||
// 新增了按钮
|
||||
return true;
|
||||
}
|
||||
|
||||
// 检查按钮配置是否变化
|
||||
if (existingButton.TriggerMission != configButton.TriggerMission
|
||||
|| existingButton.TriggerMethod != configButton.TriggerMethod
|
||||
|| existingButton.TriggerMethodParams != configButton.TriggerMethodParams
|
||||
|| existingButton.TriggerState != configButton.TriggerState
|
||||
|| existingButton.TriggerDelay != configButton.TriggerDelay)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// 检查是否有按钮被删除
|
||||
foreach (var existingKey in existingDict.Keys)
|
||||
{
|
||||
if (!configDict.ContainsKey(existingKey))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新按钮盒属性
|
||||
/// </summary>
|
||||
private void UpdateButtonBox(BasicButtonBox buttonBox, ButtonBoxModel configBox)
|
||||
{
|
||||
// 如果类型改变,需要重新创建实例
|
||||
if (buttonBox.GetType().Name != configBox.Type)
|
||||
{
|
||||
// 断开旧连接
|
||||
buttonBox.Disconnect();
|
||||
|
||||
// 从列表中移除
|
||||
_buttonBoxes.Remove(buttonBox);
|
||||
|
||||
// 创建新实例
|
||||
var newBox = CreateButtonBoxInstance(configBox);
|
||||
if (newBox != null)
|
||||
{
|
||||
_buttonBoxes.Add(newBox);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 只更新属性
|
||||
bool needReconnect = buttonBox.Ip != configBox.Ip || buttonBox.Port != configBox.Port;
|
||||
buttonBox.Ip = configBox.Ip;
|
||||
buttonBox.Port = configBox.Port;
|
||||
|
||||
// 更新按钮配置信息
|
||||
buttonBox.UpdateButtonConfigs(configBox.Buttons);
|
||||
|
||||
// 初始化按钮状态(基于配置中的按钮索引)
|
||||
var buttonIndices = configBox.Buttons?.Select(b => b.Index).ToList() ?? new List<int>();
|
||||
buttonBox.InitializeButtons(buttonIndices);
|
||||
|
||||
// 如果IP或端口改变,需要重新连接
|
||||
if (needReconnect)
|
||||
{
|
||||
buttonBox.Disconnect();
|
||||
buttonBox.Connect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通过类型字符串创建按钮盒实例
|
||||
/// </summary>
|
||||
private BasicButtonBox CreateButtonBoxInstance(ButtonBoxModel configBox)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(configBox.Type))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// 获取当前命名空间下所有继承自BasicButtonBox的类
|
||||
// 跨程序集发现:按钮盒具体类型可能位于卫星插件 dll(StandardScene.Devices.ButtonBox),
|
||||
// 用内核同款全域类型发现替代仅扫当前程序集的 GetExecutingAssembly。
|
||||
var buttonBoxType = SimpleLite.Utils.UiTypeDiscovery.AllTypes()
|
||||
.FirstOrDefault(t => t.IsClass
|
||||
&& !t.IsAbstract
|
||||
&& t.Namespace == typeof(BasicButtonBox).Namespace
|
||||
&& t.IsSubclassOf(typeof(BasicButtonBox))
|
||||
&& t.Name == configBox.Type);
|
||||
|
||||
if (buttonBoxType == null)
|
||||
{
|
||||
Diagnosis.Log($"未找到按钮盒类型: {configBox.Type}", "ButtonMission", true);
|
||||
return null;
|
||||
}
|
||||
|
||||
// 使用反射创建实例
|
||||
var instance = (BasicButtonBox)Activator.CreateInstance(buttonBoxType);
|
||||
|
||||
// 设置属性
|
||||
instance.Index = configBox.Index;
|
||||
instance.Ip = configBox.Ip;
|
||||
instance.Port = configBox.Port;
|
||||
|
||||
// 初始化按钮配置信息
|
||||
instance.InitializeButtonConfigs(configBox.Buttons);
|
||||
|
||||
// 初始化按钮状态(基于配置中的按钮索引)
|
||||
var buttonIndices = configBox.Buttons?.Select(b => b.Index).ToList() ?? new List<int>();
|
||||
instance.InitializeButtons(buttonIndices);
|
||||
|
||||
// 自动连接
|
||||
instance.Connect();
|
||||
|
||||
return instance;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Diagnosis.Log($"创建按钮盒实例失败: Type={configBox.Type}, Error={ExceptionFormatter.FormatEx(ex)}", "ButtonMission", true);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前所有按钮盒实例(只读)
|
||||
/// </summary>
|
||||
public IReadOnlyList<BasicButtonBox> GetButtonBoxes()
|
||||
{
|
||||
lock (_syncLock)
|
||||
{
|
||||
return _buttonBoxes.ToList().AsReadOnly();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 执行按钮动作(在独立线程中异步执行,避免阻塞按钮监控循环)
|
||||
/// </summary>
|
||||
private void ExecuteButtonAction(ButtonModel buttonConfig, BasicButtonBox buttonBox)
|
||||
{
|
||||
|
||||
|
||||
Task.Run(() => ExecuteButtonActionInternal(buttonConfig, buttonBox));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 实际执行业务方法的内部逻辑,包含成功/失败反馈。
|
||||
/// </summary>
|
||||
private void ExecuteButtonActionInternal(ButtonModel buttonConfig, BasicButtonBox buttonBox)
|
||||
{
|
||||
var success = false;
|
||||
try
|
||||
{
|
||||
// 按钮动作执行后清零对应按钮寄存器(具体盒型按需重写,默认空实现)
|
||||
buttonBox.ClearButtonRegister(buttonConfig.Index);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(buttonConfig.TriggerMission) ||
|
||||
string.IsNullOrWhiteSpace(buttonConfig.TriggerMethod))
|
||||
{
|
||||
// 配置不完整,直接反馈失败
|
||||
Diagnosis.Log("按钮配置缺少 TriggerMission 或 TriggerMethod,无法执行动作", "ButtonMission", true);
|
||||
return;
|
||||
}
|
||||
|
||||
var mission = SimpleProject.proj?.Missions?
|
||||
.FirstOrDefault(m => m.GetType().Name == buttonConfig.TriggerMission || m.name == buttonConfig.TriggerMission);
|
||||
|
||||
if (mission == null)
|
||||
{
|
||||
Diagnosis.Log($"未找到触发任务: {buttonConfig.TriggerMission}", "ButtonMission", true);
|
||||
return;
|
||||
}
|
||||
|
||||
var method = mission.GetType().GetMethod(buttonConfig.TriggerMethod,
|
||||
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
|
||||
|
||||
if (method == null)
|
||||
{
|
||||
Diagnosis.Log($"任务 {buttonConfig.TriggerMission} 中未找到方法 {buttonConfig.TriggerMethod}", "ButtonMission", true);
|
||||
return;
|
||||
}
|
||||
|
||||
var parameters = ParseMethodParameters(buttonConfig.TriggerMethodParams, method);
|
||||
|
||||
if (method.IsStatic)
|
||||
{
|
||||
var result = method.Invoke(null, parameters);
|
||||
success = HandleMethodResult(result);
|
||||
}
|
||||
else
|
||||
{
|
||||
var result = method.Invoke(mission, parameters);
|
||||
success = HandleMethodResult(result);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Diagnosis.Log($"执行按钮动作失败: {ExceptionFormatter.FormatEx(ex)}", "ButtonMission", true);
|
||||
}
|
||||
finally
|
||||
{
|
||||
// 业务方法执行完成后,回调按钮盒进行反馈(如灯光、蜂鸣等)
|
||||
try
|
||||
{
|
||||
buttonBox.OnActionExecuted(buttonConfig, success);
|
||||
}
|
||||
catch (Exception feedbackEx)
|
||||
{
|
||||
Diagnosis.Log($"按钮盒执行反馈失败: {ExceptionFormatter.FormatEx(feedbackEx)}", "ButtonMission", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 处理反射调用结果:支持 Task/Task<bool> 等异步返回类型。
|
||||
/// 返回 true 表示执行成功。
|
||||
/// </summary>
|
||||
private bool HandleMethodResult(object result)
|
||||
{
|
||||
try
|
||||
{
|
||||
switch (result)
|
||||
{
|
||||
case null:
|
||||
return true;
|
||||
case Task<bool> tb:
|
||||
return tb.GetAwaiter().GetResult();
|
||||
case Task t:
|
||||
t.GetAwaiter().GetResult();
|
||||
return true;
|
||||
case bool b:
|
||||
return b;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Diagnosis.Log($"按钮动作方法异步执行失败: {ExceptionFormatter.FormatEx(ex)}", "ButtonMission", true);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解析方法参数
|
||||
/// </summary>
|
||||
private object[] ParseMethodParameters(string paramsStr, MethodInfo methodInfo)
|
||||
{
|
||||
var paramInfos = methodInfo.GetParameters();
|
||||
|
||||
if (paramInfos.Length == 0)
|
||||
{
|
||||
return Array.Empty<object>();
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(paramsStr))
|
||||
{
|
||||
return paramInfos.Select(p => p.HasDefaultValue ? p.DefaultValue : GetDefaultValue(p.ParameterType)).ToArray();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var paramStrings = paramsStr.Split(',');
|
||||
var parameters = new List<object>();
|
||||
|
||||
for (int i = 0; i < paramInfos.Length; i++)
|
||||
{
|
||||
var paramInfo = paramInfos[i];
|
||||
var paramType = paramInfo.ParameterType;
|
||||
|
||||
if (i < paramStrings.Length)
|
||||
{
|
||||
var trimmed = paramStrings[i].Trim();
|
||||
parameters.Add(ConvertParameter(trimmed, paramType));
|
||||
}
|
||||
else
|
||||
{
|
||||
parameters.Add(paramInfo.HasDefaultValue ? paramInfo.DefaultValue : GetDefaultValue(paramType));
|
||||
}
|
||||
}
|
||||
|
||||
return parameters.ToArray();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Diagnosis.Log($"解析按钮参数失败: {ExceptionFormatter.FormatEx(ex)}", "ButtonMission", true);
|
||||
return paramInfos.Select(p => p.HasDefaultValue ? p.DefaultValue : GetDefaultValue(p.ParameterType)).ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 转换参数
|
||||
/// </summary>
|
||||
private object ConvertParameter(string value, Type targetType)
|
||||
{
|
||||
if (targetType == typeof(string))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
if (targetType == typeof(int) || targetType == typeof(int?))
|
||||
{
|
||||
return int.TryParse(value, out int result) ? result : (targetType == typeof(int?) ? (int?)null : 0);
|
||||
}
|
||||
if (targetType == typeof(double) || targetType == typeof(double?))
|
||||
{
|
||||
return double.TryParse(value, out double result) ? result : (targetType == typeof(double?) ? (double?)null : 0d);
|
||||
}
|
||||
if (targetType == typeof(float) || targetType == typeof(float?))
|
||||
{
|
||||
return float.TryParse(value, out float result) ? result : (targetType == typeof(float?) ? (float?)null : 0f);
|
||||
}
|
||||
if (targetType == typeof(bool) || targetType == typeof(bool?))
|
||||
{
|
||||
return bool.TryParse(value, out bool result) ? result : (targetType == typeof(bool?) ? (bool?)null : false);
|
||||
}
|
||||
if (targetType.IsEnum)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Enum.Parse(targetType, value, true);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return Enum.GetValues(targetType).GetValue(0);
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取类型默认值
|
||||
/// </summary>
|
||||
private object GetDefaultValue(Type type)
|
||||
{
|
||||
if (type.IsValueType)
|
||||
{
|
||||
return Activator.CreateInstance(type);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 打开按钮盒管理界面
|
||||
/// </summary>
|
||||
[MethodMember(Name = "打开管理界面")]
|
||||
[I18N.DocumentTranslation(Name = "Open Manager", locale = "en")]
|
||||
public static void OpenViewer()
|
||||
{
|
||||
try
|
||||
{
|
||||
var manager = ButtonBoxManager.Instance;
|
||||
|
||||
// 确保窗体没有被销毁
|
||||
if (manager.IsDisposed)
|
||||
{
|
||||
// 如果窗体被销毁,单例会自动重新创建
|
||||
manager = ButtonBoxManager.Instance;
|
||||
}
|
||||
|
||||
if (manager.Visible)
|
||||
{
|
||||
// 如果界面已经可见,将其激活并置于最前
|
||||
if (manager.WindowState == FormWindowState.Minimized)
|
||||
{
|
||||
manager.WindowState = FormWindowState.Normal;
|
||||
}
|
||||
manager.Activate();
|
||||
manager.BringToFront();
|
||||
}
|
||||
else
|
||||
{
|
||||
// 如果界面不可见,显示它
|
||||
manager.Show();
|
||||
manager.Activate();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"打开按钮盒管理界面失败: {ex.Message}", "错误",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user