SampleMachine.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using SCADA;
  2. using SCADA.Drive;
  3. using SCADA_DAQ.Plugin.Core.Service;
  4. using SCADA_DAQ.Plugin.Machine.Device;
  5. using System;
  6. using System.Collections.ObjectModel;
  7. using System.ComponentModel;
  8. using System.Linq;
  9. namespace SCADA_DAQ.Customer.Machines
  10. {
  11. /// <summary>
  12. /// 客户自定义设备
  13. /// </summary>
  14. [DisplayName("客户自定义设备")]
  15. public partial class SampleMachine : BasePLCMachine
  16. {
  17. /// <summary>
  18. /// 报警合集
  19. /// </summary>
  20. public ObservableCollection<Alarm> AlarmCollection { get; set; } = new ObservableCollection<Alarm>();
  21. /// <summary>
  22. ///
  23. /// </summary>
  24. public Redundancy RedundancyService { get; set; } //冗余服务
  25. /// <summary>
  26. ///
  27. /// </summary>
  28. /// <param name="machieID"></param>
  29. public SampleMachine(string machieID) : base(machieID)
  30. {
  31. RedundancyService = ServiceHost.Instance.GetService<Redundancy>();
  32. AlarmCodes =
  33. Env.DAL.Base_AlarmCode.GetData<DBModel.Base_AlarmCode>()?
  34. .Select(t => new Alarm() { AlarmCode = t.AlarmCode_Str, Desc = t.AlarmDesc_Str })?
  35. .ToLookup(t => t.AlarmCode).ToDictionary(t => t.Key, t => t.First());
  36. }
  37. /// <summary>
  38. ///
  39. /// </summary>
  40. /// <param name="sender"></param>
  41. /// <param name="e"></param>
  42. protected override void RegReadValueChanged(object sender, RegReadValueChangedEventArgs e)
  43. {
  44. if (RedundancyService?.RedundancyState == RedundancyStates.Standby) { return; } //如果是待机模式就不执行下面的逻辑
  45. base.RegReadValueChanged(sender, e);
  46. var reg = (RegInfo)sender;
  47. //if (reg.Comment.Variable == "Sys_1minPlus")
  48. //{
  49. // Log.Info($"寄存器变化:{reg.Comment.Variable},value:{reg.Value}");
  50. //}
  51. }
  52. /// <summary>
  53. /// 扫描完成事件
  54. /// </summary>
  55. /// <param name="sender"></param>
  56. /// <param name="e"></param>
  57. protected override void ScanCompleted(object sender, EventArgs e)
  58. {
  59. if (RedundancyService?.RedundancyState == RedundancyStates.Standby) { return; } //如果是待机模式就不执行下面的逻辑
  60. base.ScanCompleted(sender, e);
  61. }
  62. /// <summary>
  63. ///
  64. /// </summary>
  65. /// <param name="sender"></param>
  66. /// <param name="e"></param>
  67. protected override void AlarmTriggered(object sender, AlarmTriggedEventArgs e)
  68. {
  69. base.AlarmTriggered(sender, e);
  70. var reg = (e.Alarm as Alarm<RegInfo>).Tag;
  71. }
  72. /// <summary>
  73. ///
  74. /// </summary>
  75. /// <param name="sender"></param>
  76. /// <param name="e"></param>
  77. protected override void AlarmReset(object sender, AlarmTriggedEventArgs e)
  78. {
  79. base.AlarmReset(sender, e);
  80. }
  81. }
  82. }