using System.Text; using UHFHelper; namespace test { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { //判断串口是否打开 if (!UHFCardHelper.GetInstance().ComOpen) { Resultoutput resultoutput = UHFCardHelper.GetInstance().OpenPort(); if (resultoutput.Res) { MessageBox.Show(resultoutput.ResMes); } else { MessageBox.Show(resultoutput.ResMes); } } } private void button2_Click(object sender, EventArgs e) { if (!UHFCardHelper.GetInstance().ComOpen) { MessageBox.Show("串口未打开"); return; } string res = UHFCardHelper.GetInstance().ReadCard(); label1.Text = res; } private void button3_Click(object sender, EventArgs e) { UHFCardHelper.GetInstance().ClosePort(); } private void button4_Click(object sender, EventArgs e) { var res = UHFCardHelper.GetInstance().WriteCard(textBox1.Text); MessageBox.Show(res.ResMes); } private void Form1_Load(object sender, EventArgs e) { //// 查看本机可用串口 //foreach (var val in UHF_RS485_Helper.GetLocalSerialPortNames()) //{ // this.comboBox1.Items.Add(val); //} } UHF_RS485_Helper uHF_RS485_Helper; private void button5_Click(object sender, EventArgs e) { // 初始化 UHF_RS485_Helper.GetInstance().Open(new SerialParam { PortName = "COM5", BaudRate = 57600, DataBits = 8 }); if (!UHF_RS485_Helper.GetInstance().GetSerialPortState()) { MessageBox.Show("打开失败"); } } private async void button6_Click(object sender, EventArgs e) { if (UHF_RS485_Helper.GetInstance().GetSerialPortState()) { var oldss = await UHF_RS485_Helper.GetInstance().ReadCard(01); var sss = oldss?.ResData; textBox4.Text = sss; label2.Text = sss; } } private void button7_Click(object sender, EventArgs e) { UHFCardHelper.GetInstance().WorkMode(); } private void button8_Click(object sender, EventArgs e) { UHF_RS485_Helper.GetInstance().OpenBeep(); } } }