|
- using Microsoft.EntityFrameworkCore.Storage.ValueConversion.Internal;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
-
- namespace BPASmartClient.Device
- {
- public class VariableMonitorAttribute : Attribute
- {
- /// <summary>
- /// 变量描述
- /// </summary>
- /// <param name="Notes">描述</param>
- /// <param name="PLCAddress">PLC 地址</param>
- /// <param name="ModbusTcpAddress">Modbus TCP 地址</param>
- public VariableMonitorAttribute(string Notes, string PLCAddress = "", string ModbusTcpAddress = "")
- {
- this.PLCAddress = PLCAddress;
- this.ModbusTcpAddress = GetModbusTcpAdd(PLCAddress);// ModbusTcpAddress;
- this.Notes = Notes;
- }
-
- private string GetModbusTcpAdd(string address)
- {
- if (address == null) return "";
- if (address.Length > 0)
- {
- address = address.Trim();
- if (address.ToUpper().Contains("M") && address.Length >= 4)
- {
- var res = address.Substring(1).Split('.');
- if (res != null && res.Length == 2)
- {
- if (int.TryParse(res[0], out int firstAddress) && int.TryParse(res[1], out int ExitAddress))
- {
- if (ExitAddress >= 0 && ExitAddress <= 7)
- {
- return ((firstAddress * 8) + 320 + ExitAddress).ToString();
- }
- }
- }
- }
- else if ((address.ToUpper().Contains("VW") || address.ToUpper().Contains("VD")) && address.Length >= 3)
- {
- var res = address.Substring(2);
- if (res != null && int.TryParse(res, out int tempAddress))
- {
- return ((tempAddress / 2) + 100).ToString();
- }
- }
- }
- return "";
- }
-
- /// <summary>
- /// PLC 地址
- /// </summary>
- public string PLCAddress { get; set; }
-
- /// <summary>
- /// Modbus TCP 地址
- /// </summary>
- public string ModbusTcpAddress { get; set; }
-
- /// <summary>
- /// 描述
- /// </summary>
- public string Notes { get; set; }
- }
- }
|