ScpiFuncs_ChannelCommon.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Reflection;
  6. using System.Threading.Tasks;
  7. using Uestc.Auto6.Dso.Core;
  8. using Uestc.Auto6.Dso.ComModel;
  9. using UESTC.Auto.SCPIManager;
  10. namespace Uestc.Auto6.Dso.Scpi
  11. {
  12. partial class StubFunc
  13. {
  14. #region 模拟通道
  15. private static List<IChnlPrsnt> allChnls
  16. {
  17. get => Presenter.GetAllChnls().ToList();
  18. }
  19. /// <summary>
  20. /// 通道号处理
  21. /// </summary>
  22. /// <param name="analyResult"></param>
  23. /// <param name="chnlId"></param>
  24. /// <returns></returns>
  25. private static bool checkChannel(SCPICommandProcessFuncParam analyResult, out ChannelId chnlId)
  26. {
  27. chnlId = ChannelId.C1;
  28. if (analyResult == null)
  29. return false;
  30. var chnlsList = Enum.GetNames(typeof(ChannelId));
  31. if (analyResult.ChannelIndex < 0 || analyResult.ChannelIndex > chnlsList.Count())
  32. {
  33. return false;
  34. }
  35. return Enum.TryParse(chnlsList[analyResult.ChannelIndex - 1], out chnlId);
  36. }
  37. public static bool TryGetAnalogChannelPrsnt(SCPICommandProcessFuncParam analyResult, out AnalogPrsnt analogPrsnt)
  38. {
  39. analogPrsnt = null;
  40. if (!checkChannel(analyResult, out ChannelId chnlId))
  41. return false;
  42. var channel = allChnls.FirstOrDefault(chnl => chnl.Id == chnlId);
  43. if (channel == null)
  44. {
  45. return false;
  46. }
  47. if (!(channel is AnalogPrsnt))
  48. {
  49. return false;
  50. }
  51. analogPrsnt = (AnalogPrsnt)channel;
  52. return true;
  53. }
  54. public static bool scpiQuy_AnalogChannelCommon(SCPICommandProcessFuncParam analyResult, ref SCPISendMessage sendMessage)
  55. {
  56. bool returnResult = false;
  57. if (TryGetAnalogChannelPrsnt(analyResult, out AnalogPrsnt analogPrsnt))
  58. {
  59. ScpiTagObj scpiTagObj = (ScpiTagObj)analyResult.Tag;
  60. if (TryGetPropertyInfo(analogPrsnt, scpiTagObj.PropertyName, out PropertyInfo propertyInfo))
  61. {
  62. if (TryGetPropertyValue(analogPrsnt, propertyInfo, out string outputString, scpiTagObj.ParamList, scpiTagObj.IntOrDoubleMultiplier))
  63. {
  64. sendMessage.SendData = decodeStr(outputString);
  65. returnResult = true;
  66. }
  67. }
  68. }
  69. return returnResult;
  70. }
  71. public static bool scpiSet_AnalogChannelCommon(SCPICommandProcessFuncParam analyResult)
  72. {
  73. bool returnResult = false;
  74. if (!scpiSet_ParamCheck(analyResult))
  75. {
  76. return false;
  77. }
  78. if (TryGetAnalogChannelPrsnt(analyResult, out AnalogPrsnt analogPrsnt))
  79. {
  80. ScpiTagObj scpiTagObj = (ScpiTagObj)analyResult.Tag;
  81. if (TryGetPropertyInfo(analogPrsnt, scpiTagObj.PropertyName, out PropertyInfo propertyInfo))
  82. {
  83. List<string> param = ParamListToStrList(analyResult.Params);
  84. if (param.Count > 0)
  85. {
  86. if (TrySetPropertyValue(analogPrsnt, propertyInfo, param[0], scpiTagObj.ParamList, scpiTagObj.IntOrDoubleMultiplier))
  87. returnResult = true;
  88. }
  89. }
  90. }
  91. return returnResult;
  92. }
  93. #endregion 模拟通道
  94. }
  95. }