ab56a9bcf7
SVN-Revision: r240
242 lines
8.1 KiB
C#
242 lines
8.1 KiB
C#
using Lskj.Control;
|
|
using ReaderApi;
|
|
using ReaderApi.Data;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace RFIDManagement
|
|
{
|
|
public partial class FrmDataWrite : Form
|
|
{
|
|
public FrmDataWrite()
|
|
{
|
|
InitializeComponent();
|
|
this.Load += OnFrmDataWriteLoad;
|
|
}
|
|
/// <summary>
|
|
/// 上下文
|
|
/// </summary>
|
|
public SynchronizationContext SyncContext = null;
|
|
/// <summary>
|
|
/// 数据源
|
|
/// </summary>
|
|
public DataTable SourceTable = new DataTable();
|
|
/// <summary>
|
|
/// 当前的标签
|
|
/// </summary>
|
|
public Reader SelectReader;
|
|
/// <summary>
|
|
/// 信息
|
|
/// </summary>
|
|
public List<Tag> ReadTag = new List<Tag>();
|
|
/// <summary>
|
|
/// 信息
|
|
/// </summary>
|
|
public List<Tag> WriteResult = new List<Tag>();
|
|
/// <summary>
|
|
/// 更新数据Timer
|
|
/// </summary>
|
|
public System.Windows.Forms.Timer UpdateViewTimer;
|
|
private void OnFrmDataWriteLoad(object sender, EventArgs e)
|
|
{
|
|
UpdateViewTimer = new System.Windows.Forms.Timer();
|
|
UpdateViewTimer.Interval = 200;
|
|
UpdateViewTimer.Tick += OnUpdateViewTimerTick;
|
|
UpdateViewTimer.Enabled = true;
|
|
for (int index = 1; index <= 32; index++)
|
|
{
|
|
com_Ant.Properties.Items.Add("Ant" + index.ToString());
|
|
}
|
|
string comAnt = IniHelper.Read("ComAnt");
|
|
string txtPower = IniHelper.Read("TxtPower");
|
|
string txtPassword = IniHelper.Read("TxtPassword");
|
|
int selectIndex = com_Ant.Properties.Items.IndexOf(comAnt);
|
|
com_Ant.SelectedIndex = 0;
|
|
if (selectIndex > 0)
|
|
{
|
|
com_Ant.SelectedIndex = selectIndex;
|
|
}
|
|
if (!string.IsNullOrEmpty(txtPower))
|
|
{
|
|
txt_Power.Text = txtPower;
|
|
}
|
|
if (!string.IsNullOrEmpty(txtPassword))
|
|
{
|
|
txt_Password.Text = txtPassword;
|
|
}
|
|
SyncContext = SynchronizationContext.Current;
|
|
this.writeBtn.Click += OnWriteBtnClick;
|
|
InitSourceTable();
|
|
MatchEpcPara para = new MatchEpcPara();
|
|
para.isSelect = false;
|
|
var result = SelectReader?.SendSyn(para);
|
|
}
|
|
/// <summary>
|
|
/// 创建数据源
|
|
/// </summary>
|
|
private void InitSourceTable()
|
|
{
|
|
SourceTable = new DataTable();
|
|
SourceTable.Columns.Add("EpcColumn");
|
|
SourceTable.Columns.Add("DataColumn");
|
|
SourceTable.Columns.Add("ResultColumn");
|
|
this.gcMain.DataSource = SourceTable;
|
|
}
|
|
/// <summary>
|
|
/// 写入按钮点击
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void OnWriteBtnClick(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (txt_Data.Text.Length == 0)
|
|
{
|
|
MessageUtil.Show("写入数据不能为空");
|
|
return;
|
|
}
|
|
if (txt_Data.Text.Length % 4 != 0)
|
|
{
|
|
MessageUtil.Show("写入数据必须为4的倍数");
|
|
return;
|
|
}
|
|
WriteResult.Clear();
|
|
SourceTable.Rows.Clear();
|
|
CustomRWPara para = new CustomRWPara();
|
|
para.operate = 0x01;
|
|
para.writeMode = 0x80;//改写pc值
|
|
para.ant = byte.Parse(System.Text.RegularExpressions.Regex.Replace(com_Ant.Text, @"[^0-9]+", ""));
|
|
para.power = byte.Parse(txt_Power.Text);
|
|
para.passWord = txt_Password.Text;
|
|
GlobalPara.tagDisplayArea = TagDisplayArea.writeTag;
|
|
para.startAdd = 0x01;
|
|
para.area = Area.EPC;
|
|
para.data = txt_Data.Text;
|
|
var result = SelectReader?.SendSyn(para);
|
|
if (result != null)
|
|
{
|
|
SaveInfo();
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 添加数据
|
|
/// </summary>
|
|
/// <param name="tag"></param>
|
|
public void AddTag(Tag tag)
|
|
{
|
|
if (GlobalPara.tagDisplayArea == TagDisplayArea.writeTag)
|
|
{
|
|
if (tag.cmd == CmdType.cmd_tag)
|
|
{
|
|
GlobalMethod.AddTag(tag, WriteResult);
|
|
}
|
|
else
|
|
{
|
|
WriteResult.Add(tag);
|
|
}
|
|
WriteDataAddOne(tag);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 进制数据
|
|
/// </summary>
|
|
/// <param name="state"></param>
|
|
public void WriteDataAddOne(object state)
|
|
{
|
|
if ((state as Tag).isSuccess.Contains("成功") || (state as Tag).isSuccess.Contains("success"))
|
|
{
|
|
//if (radioHexaDecimal.Checked)
|
|
//{
|
|
// txt_Data.Text = GlobalMethod.AddOneStep(16, txt_Data.Text, 1, 0);
|
|
//}
|
|
//else if (radioDecimal.Checked)
|
|
//{
|
|
// txt_Data.Text = GlobalMethod.AddOneStep(10, txt_Data.Text, 1, 0);
|
|
//}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 更新数据
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void OnUpdateViewTimerTick(object sender, EventArgs e)
|
|
{
|
|
ShowWriteResult();
|
|
}
|
|
/// <summary>
|
|
/// 保存信息
|
|
/// </summary>
|
|
private void SaveInfo()
|
|
{
|
|
IniHelper.Write("ComAnt", com_Ant.Text);
|
|
IniHelper.Write("TxtPower", txt_Power.Text);
|
|
IniHelper.Write("TxtPassword", txt_Password.Text);
|
|
}
|
|
/// <summary>
|
|
/// 更新数据
|
|
/// </summary>
|
|
private void ShowWriteResult()
|
|
{
|
|
try
|
|
{
|
|
lock (WriteResult)
|
|
{
|
|
foreach (var tag in WriteResult)
|
|
{
|
|
var newTag = true;
|
|
for (int index = 0; index < SourceTable.Rows.Count; index++)
|
|
{
|
|
if (tag.epc != null)
|
|
{
|
|
if (tag.customData != null)
|
|
{
|
|
if ((SourceTable.Rows[index]["EpcColumn"] + "").Equals(tag.epc) && (SourceTable.Rows[index]["DataColumn"] + "").Equals(tag.customData))
|
|
{
|
|
newTag = false;
|
|
break;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if ((SourceTable.Rows[index]["EpcColumn"] + "").Equals(tag.epc))
|
|
{
|
|
newTag = false;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (newTag)
|
|
{
|
|
DataRow newRow = SourceTable.NewRow();
|
|
newRow["EpcColumn"] = tag.epc;
|
|
newRow["DataColumn"] = tag.customData;
|
|
newRow["ResultColumn"] = tag.isSuccess;
|
|
SourceTable.Rows.Add(newRow);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageUtil.Show(ex.Message);
|
|
}
|
|
}
|
|
}
|
|
}
|