Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

182 řádky
5.7 KiB

  1. using HKHelper;
  2. using System.Diagnostics;
  3. using System.Text;
  4. using UHFHelper;
  5. namespace test
  6. {
  7. public partial class Form1 : Form
  8. {
  9. public Form1()
  10. {
  11. InitializeComponent();
  12. }
  13. private void button1_Click(object sender, EventArgs e)
  14. {
  15. //判断串口是否打开
  16. if (!UHFCardHelper.GetInstance().ComOpen)
  17. {
  18. Resultoutput resultoutput = UHFCardHelper.GetInstance().OpenPort();
  19. if (resultoutput.Res)
  20. {
  21. MessageBox.Show(resultoutput.ResMes);
  22. }
  23. else
  24. {
  25. MessageBox.Show(resultoutput.ResMes);
  26. }
  27. }
  28. }
  29. private void button2_Click(object sender, EventArgs e)
  30. {
  31. if (!UHFCardHelper.GetInstance().ComOpen)
  32. {
  33. MessageBox.Show("串口未打开");
  34. return;
  35. }
  36. string res = UHFCardHelper.GetInstance().ReadCard();
  37. label1.Text = res;
  38. }
  39. private void button3_Click(object sender, EventArgs e)
  40. {
  41. UHFCardHelper.GetInstance().ClosePort();
  42. }
  43. private void button4_Click(object sender, EventArgs e)
  44. {
  45. var res = UHFCardHelper.GetInstance().WriteCard(textBox1.Text);
  46. MessageBox.Show(res.ResMes);
  47. }
  48. List<int> add = new List<int>();
  49. private void Form1_Load(object sender, EventArgs e)
  50. {
  51. //// 查看本机可用串口
  52. //foreach (var val in UHF_RS485_Helper.GetLocalSerialPortNames())
  53. //{
  54. // this.comboBox1.Items.Add(val);
  55. //}
  56. add.Add(01);
  57. add.Add(02);
  58. }
  59. UHF_RS485_Helper uHF_RS485_Helper;
  60. private void button5_Click(object sender, EventArgs e)
  61. {
  62. // 初始化
  63. UHF_RS485_Helper.GetInstance().Open(new SerialParam
  64. {
  65. PortName = "COM8",
  66. BaudRate = 57600,
  67. DataBits = 8
  68. });
  69. if (!UHF_RS485_Helper.GetInstance().GetSerialPortState())
  70. {
  71. MessageBox.Show("打开失败");
  72. }
  73. }
  74. private void button6_Click(object sender, EventArgs e)
  75. {
  76. if (UHF_RS485_Helper.GetInstance().GetSerialPortState())
  77. {
  78. var oldss = UHF_RS485_Helper.GetInstance().ReadCard(01);
  79. var sss = oldss?.ResData;
  80. textBox4.Text = sss;
  81. label2.Text = sss;
  82. }
  83. }
  84. private void button7_Click(object sender, EventArgs e)
  85. {
  86. UHFCardHelper.GetInstance().WorkMode();
  87. }
  88. private void button8_Click(object sender, EventArgs e)
  89. {
  90. System.Timers.Timer ti = new();
  91. ti.Interval = 500;
  92. ti.Elapsed += Ti_Elapsed;
  93. ti.Start();
  94. }
  95. private void Ti_Elapsed(object? sender, System.Timers.ElapsedEventArgs e)
  96. {
  97. foreach (var item in add)
  98. {
  99. var oldss = UHF_RS485_Helper.GetInstance().ReadCard(item);
  100. if (oldss != null)
  101. {
  102. //lvi.SubItems.Add(oldss.ResData ?? "无");
  103. //this.listView1.Items.Add(lvi);
  104. this.Invoke(() =>
  105. {
  106. if (listView1.Items.Count == 0)
  107. {
  108. ListViewItem lvi = new ListViewItem();
  109. lvi.SubItems.Add(oldss.ResData ?? "无");
  110. lvi.SubItems.Add("1");
  111. this.listView1.Items.Add(lvi);
  112. }
  113. bool isCunzai = false;
  114. for (int i = 0; i < listView1.Items.Count; i++) //判断是否在Listview列表内
  115. {
  116. if (oldss.ResData == listView1.Items[i].SubItems[1].Text)
  117. {
  118. var aListItem = listView1.Items[i];
  119. aListItem.SubItems[2].Text = Convert.ToString(Convert.ToInt32(aListItem.SubItems[2].Text) + 1);
  120. isCunzai = true;
  121. }
  122. }
  123. if (!isCunzai)
  124. {
  125. ListViewItem lvi = new ListViewItem();
  126. lvi.SubItems.Add(oldss.ResData ?? "无");
  127. lvi.SubItems.Add("1");
  128. this.listView1.Items.Add(lvi);
  129. }
  130. });
  131. }
  132. }
  133. }
  134. private void button9_Click(object sender, EventArgs e)
  135. {
  136. ListViewItem lvi = new ListViewItem("1");
  137. lvi.SubItems.Add("第1列,第1行");
  138. lvi.SubItems.Add("第2列,第2行");
  139. }
  140. private void button10_Click(object sender, EventArgs e)
  141. {
  142. HKControl.Main.GetInstance.Init();
  143. }
  144. private void textBox2_TextChanged(object sender, EventArgs e)
  145. {
  146. }
  147. private void button11_Click(object sender, EventArgs e)
  148. {
  149. int num = Convert.ToInt32(textBox2.Text.Trim());
  150. HKControl.Main.GetInstance.Start(num);
  151. }
  152. //关闭显示器
  153. private void button12_Click(object sender, EventArgs e)
  154. {
  155. Debug.WriteLine("关闭"+ TelevisionStart.TurnOff());
  156. }
  157. //打开显示器
  158. private void button13_Click(object sender, EventArgs e)
  159. {
  160. Debug.WriteLine("打开" + TelevisionStart.TurnOn());
  161. }
  162. }
  163. }