终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

64 lines
2.0 KiB

  1. using BPASmartClient.Modbus;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace BPASmartClient.PLC
  8. {
  9. /// <summary>
  10. /// PLC读取参数
  11. /// </summary>
  12. internal class PLCReadParameter
  13. {
  14. /// <summary>
  15. /// 读取类型
  16. /// </summary>
  17. internal CommandType CmdType { get; set; }
  18. /// <summary>
  19. /// 地址
  20. /// </summary>
  21. internal string Address { get; set; }
  22. /// <summary>
  23. /// 长度
  24. /// </summary>
  25. internal ushort Length { get; set; }
  26. /// <summary>
  27. /// 配置转模型
  28. /// </summary>
  29. /// <param name="content">M,M0.3,3;M,M100.0,16;M,M235.0,1;M,M102,7;M,M103,6;VW,VW372,1</param>
  30. /// <returns>读取参数模型</returns>
  31. public static List<PLCReadParameter> DeSerialize(string content)
  32. {
  33. List<PLCReadParameter> result = new List<PLCReadParameter>();
  34. var wholeTemp = content.Split(';');
  35. foreach (var temp in wholeTemp)
  36. {
  37. if (temp.Contains(","))
  38. {
  39. var subTemp = temp.Split(',');
  40. if (null != subTemp && subTemp.Length == 3)
  41. {
  42. PLCReadParameter parameter = new PLCReadParameter();
  43. switch (subTemp[0])
  44. {
  45. case "M":
  46. parameter.CmdType = CommandType.Coils;
  47. break;
  48. case "VW":
  49. parameter.CmdType = CommandType.HoldingRegisters;
  50. break;
  51. }
  52. parameter.Address = subTemp[1];
  53. parameter.Length = ushort.Parse(subTemp[2]);
  54. result.Add(parameter);
  55. }
  56. }
  57. }
  58. return result;
  59. }
  60. }
  61. }