Files
6150-HMI/CowainHmi/ucRfidCtrl.cs

126 lines
3.7 KiB
C#
Raw Normal View History

2026-01-15 15:06:36 +08:00
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices.ComTypes;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CowainHmi
{
public partial class ucRfidCtrl : UserControl
{
private string[] nameList;
[Category("PCHMI"), Description("RFID名称列表")]
public string[] NameList
{
get
{
return this.nameList;
}
set
{
this.nameList = value;
}
}
private string idAddr = "";
[Category("PCHMI"), Description("编号地址")]
public string IdAddr
{
get
{
return idAddr;
}
set
{
idAddr = value;
}
}
private string db = "DB900";
[Category("PCHMI"), Description("DB地址")]
public string DataAddr
{
get
{
return db;
}
set
{
db = value;
}
}
public ucRfidCtrl()
{
InitializeComponent();
}
private int id = 0;
private string rfidName;
private void ProgramAdds()
{
id = this.cbxCySelect.SelectedIndex;
rfidName = this.cbxCySelect.SelectedText;
this.lblTp. = $"{DataAddr}.{id * 22 + 12}.0";
this.lblRd. = $"{DataAddr}.{id * 22 + 12}.1";
this.lblErr. = $"{DataAddr}.{id * 22 + 12}.4";
this.lblReadDone. = $"{DataAddr}.{id * 22 + 12}.3";
this.lblWriteDone. = $"{DataAddr}.{id * 22 + 12}.2";
this.txtReadTime. = $"{DataAddr}.{id * 22 + 18}";
this.txtWriteTime. = $"{DataAddr}.{id * 22 + 20}";
this.txtStartAdd. = $"{DataAddr}.{id * 22 + 0}";
this.txtLength. = $"{DataAddr}.{id * 22 + 2}";
this.txtLength.. = $"{DataAddr}.{id * 22 + 10}.2";
this.btnRead..[0] = $"{DataAddr}.{id * 22 + 10}.0";
this.btnRead. = $"{DataAddr}.{id * 22 + 10}.0";
this.btnWrite..[0] = $"{DataAddr}.{id * 22 + 10}.1";
this.btnWrite. = $"{DataAddr}.{id * 22 + 10}.1";
this.swAutoLength..[0] = $"{DataAddr}.{id * 22 + 10}.2";
this.swAutoLength. = $"{DataAddr}.{id * 22 + 10}.2";
}
private void ucPressCtrl_Load(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(IdAddr))
{
return;
}
id = PCHMI.VL.GET_UINT16(0, IdAddr) - 1;//读气缸编号
if (id < 0)
{
PCHMI.RT.SEND_UINT16(0, IdAddr, 1);
id = 0;
}
this.cbxCySelect.DataSource = NameList;
this.cbxCySelect.SelectedIndexChanged += CbxRfidSelect_SelectedIndexChanged;
//ProgramAdds();
this.cbxCySelect.SelectedIndex = id;
}
private async void CbxRfidSelect_SelectedIndexChanged(object sender, EventArgs e)
{
ProgramAdds();
string addr = $"{DataAddr}.{id * 22 + 4}";
PCHMI.VL.GET_INT16(0, addr);
await Task.Delay(300);
int dbno = PCHMI.VL.GET_INT16(0, addr);//读数据db值
if (dbno > 0)
{
this.dgvData.DB = dbno;
}
}
}
}