Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

98 rader
2.7 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. private void Form1_Load(object sender, EventArgs e)
  47. {
  48. //// 查看本机可用串口
  49. //foreach (var val in UHF_RS485_Helper.GetLocalSerialPortNames())
  50. //{
  51. // this.comboBox1.Items.Add(val);
  52. //}
  53. }
  54. UHF_RS485_Helper uHF_RS485_Helper;
  55. private void button5_Click(object sender, EventArgs e)
  56. {
  57. // 初始化
  58. UHF_RS485_Helper.GetInstance().Open(new SerialParam
  59. {
  60. PortName = "COM5",
  61. BaudRate = 57600,
  62. DataBits = 8
  63. });
  64. if (!UHF_RS485_Helper.GetInstance().GetSerialPortState())
  65. {
  66. MessageBox.Show("打开失败");
  67. }
  68. }
  69. private async void button6_Click(object sender, EventArgs e)
  70. {
  71. if (UHF_RS485_Helper.GetInstance().GetSerialPortState())
  72. {
  73. var oldss = await UHF_RS485_Helper.GetInstance().ReadCard(01);
  74. var sss = oldss?.ResData;
  75. textBox4.Text = sss;
  76. label2.Text = sss;
  77. }
  78. }
  79. private void button7_Click(object sender, EventArgs e)
  80. {
  81. UHFCardHelper.GetInstance().WorkMode();
  82. }
  83. private void button8_Click(object sender, EventArgs e)
  84. {
  85. UHF_RS485_Helper.GetInstance().OpenBeep();
  86. }
  87. }
  88. }