UAlarm.xaml.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. using SecsGem.Core;
  2. using SecsGem.Core.EnumData;
  3. using SecsGem.Core.Hsms;
  4. using SecsGem.Core.ItemModel;
  5. using SecsGem.Core.Utility;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows;
  12. using System.Windows.Controls;
  13. using System.Windows.Data;
  14. using System.Windows.Documents;
  15. using System.Windows.Input;
  16. using System.Windows.Media;
  17. using System.Windows.Media.Imaging;
  18. using System.Windows.Navigation;
  19. using System.Windows.Shapes;
  20. namespace EapClientSimulator
  21. {
  22. /// <summary>
  23. /// UReport.xaml 的交互逻辑
  24. /// </summary>
  25. public partial class UAlarm : UserControl
  26. {
  27. public UAlarm()
  28. {
  29. InitializeComponent();
  30. }
  31. public event EventHandler<string> OnSendMessage;
  32. private void EnableAlarm(bool enable)
  33. {
  34. SecsHsmsMessageHeader secsMessageHeader = new SecsHsmsMessageHeader()
  35. {
  36. Stream = 0x05,
  37. Function = 3,
  38. SType = SType.DataMessage,
  39. TransactionId = IdGenerator.GenerateTransactionId(),
  40. ReplyFlag = true,
  41. };
  42. Item item = new SecsGem.Core.ItemModel.ListItem();
  43. Item aledItem = new IntItem(enable?0x80:0x00);
  44. item.AddItem(aledItem);
  45. Item alidItem = null;
  46. if(string.IsNullOrEmpty(txtCeId.Text))
  47. {
  48. alidItem = ItemUtil.GetEmptyItem(SecsGem.Core.DataFormat.U4);
  49. }
  50. else
  51. {
  52. if(int.TryParse(txtCeId.Text,out var alid))
  53. {
  54. alidItem=new IntItem(alid);
  55. }
  56. else
  57. {
  58. return;
  59. }
  60. }
  61. item.AddItem(alidItem);
  62. SecsMessage secsMessage = new SecsMessage(secsMessageHeader, item);
  63. if(GlobalData.Client!=null)
  64. {
  65. GlobalData.Client.SendMessage(secsMessage);
  66. if (OnSendMessage != null)
  67. {
  68. OnSendMessage(this, SmlSerializationUtil.SerializeItemToString(secsMessage));
  69. }
  70. }
  71. }
  72. private void btnEnable_Click(object sender, RoutedEventArgs e)
  73. {
  74. EnableAlarm(true);
  75. }
  76. private void btnDisEnable_Click(object sender, RoutedEventArgs e)
  77. {
  78. EnableAlarm(false);
  79. }
  80. }
  81. }