UStatusVariable.xaml.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using SecsGem.Core;
  2. using SecsGem.Core.EnumData;
  3. using SecsGem.Core.Hsms;
  4. using SecsGem.Core.ItemModel;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading;
  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 UStatusVariable : UserControl
  26. {
  27. public UStatusVariable()
  28. {
  29. InitializeComponent();
  30. }
  31. public event EventHandler<string> OnSendMessage;
  32. private void Query()
  33. {
  34. string[] strAry = txtCeId.Text.Split(';');
  35. Thread thread = new Thread(new ParameterizedThreadStart(CircleQuery));
  36. thread.IsBackground = true;
  37. thread.Start(strAry);
  38. }
  39. private void CircleQuery(object obj)
  40. {
  41. string[] strAry=(string[])obj;
  42. while (true)
  43. {
  44. SecsHsmsMessageHeader secsMessageHeader = new SecsHsmsMessageHeader()
  45. {
  46. Stream = 0x01,
  47. Function = 3,
  48. SType = SType.DataMessage,
  49. TransactionId = IdGenerator.GenerateTransactionId(),
  50. ReplyFlag = true,
  51. };
  52. Item item = new SecsGem.Core.ItemModel.ListItem();
  53. for (int i = 0; i < strAry.Length; i++)
  54. {
  55. if (!string.IsNullOrEmpty(strAry[i]))
  56. {
  57. if (long.TryParse(strAry[i], out long svid))
  58. {
  59. Item ceItem = new LongItem(svid);
  60. item.AddItem(ceItem);
  61. }
  62. else
  63. {
  64. return;
  65. }
  66. }
  67. }
  68. SecsMessage secsMessage = new SecsMessage(secsMessageHeader, item);
  69. if (GlobalData.Client != null)
  70. {
  71. GlobalData.Client.SendMessage(secsMessage);
  72. if (OnSendMessage != null)
  73. {
  74. OnSendMessage(this, SmlSerializationUtil.SerializeItemToString(secsMessage));
  75. }
  76. }
  77. Thread.Sleep(300);
  78. }
  79. }
  80. private void btnQuery_Click(object sender, RoutedEventArgs e)
  81. {
  82. Query();
  83. }
  84. }
  85. }