Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

152 Zeilen
4.9 KiB

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