25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

184 satır
5.7 KiB

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