|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- 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);
- }
- List<int> add = new List<int>();
- private void Form1_Load(object sender, EventArgs e)
- {
-
- //// 鿴ô
- //foreach (var val in UHF_RS485_Helper.GetLocalSerialPortNames())
- //{
- // this.comboBox1.Items.Add(val);
- //}
- add.Add(01);
- add.Add(02);
- }
- UHF_RS485_Helper uHF_RS485_Helper;
- private void button5_Click(object sender, EventArgs e)
- {
- // ʼ
- UHF_RS485_Helper.GetInstance().Open(new SerialParam
- {
- PortName = "COM8",
- BaudRate = 57600,
- DataBits = 8
- });
- if (!UHF_RS485_Helper.GetInstance().GetSerialPortState())
- {
- MessageBox.Show("ʧ");
- }
- }
-
- private void button6_Click(object sender, EventArgs e)
- {
- if (UHF_RS485_Helper.GetInstance().GetSerialPortState())
- {
- var oldss = 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)
- {
- System.Timers.Timer ti = new();
- ti.Interval = 500;
- ti.Elapsed += Ti_Elapsed;
- ti.Start();
- }
-
- private void Ti_Elapsed(object? sender, System.Timers.ElapsedEventArgs e)
- {
- foreach (var item in add)
- {
- var oldss = UHF_RS485_Helper.GetInstance().ReadCard(item);
- if (oldss != null)
- {
- //lvi.SubItems.Add(oldss.ResData ?? "");
- //this.listView1.Items.Add(lvi);
- this.Invoke(() =>
- {
- if (listView1.Items.Count == 0)
- {
- ListViewItem lvi = new ListViewItem();
- lvi.SubItems.Add(oldss.ResData ?? "");
- lvi.SubItems.Add("1");
- this.listView1.Items.Add(lvi);
- }
- bool isCunzai = false;
-
- for (int i = 0; i < listView1.Items.Count; i++) //жǷListviewб
- {
- if (oldss.ResData == listView1.Items[i].SubItems[1].Text)
- {
- var aListItem = listView1.Items[i];
- aListItem.SubItems[2].Text = Convert.ToString(Convert.ToInt32(aListItem.SubItems[2].Text) + 1);
- isCunzai = true;
- }
- }
- if (!isCunzai)
- {
- ListViewItem lvi = new ListViewItem();
- lvi.SubItems.Add(oldss.ResData ?? "");
- lvi.SubItems.Add("1");
- this.listView1.Items.Add(lvi);
- }
- });
- }
- }
- }
-
- private void button9_Click(object sender, EventArgs e)
- {
- ListViewItem lvi = new ListViewItem("1");
- lvi.SubItems.Add("1,1");
- lvi.SubItems.Add("2,2");
-
- }
-
- private void button10_Click(object sender, EventArgs e)
- {
- HKControl.Main.GetInstance.Init();
- }
-
- private void textBox2_TextChanged(object sender, EventArgs e)
- {
-
- }
-
- private void button11_Click(object sender, EventArgs e)
- {
- int num = Convert.ToInt32(textBox2.Text.Trim());
- HKControl.Main.GetInstance.Start(num);
- }
- }
- }
|