K
Kittisak_TH
Guest
Dear Developer team,
i got sample code in C# and I want to convert to VB2008 for unsing on Smart device (CE).
Thie problem is I can't call Thread "thrReceiveUii = new System.Threading.Thread(ReceiveUiiProc);".
because I can't convert sub "private void ReceiveUiiProc()" to VB.Net.
C# code below.
private void _btReadReadID_Click(object sender, EventArgs e)
{
ReadID();
}
byte[] uAccessPwd = new byte[4];
/// <summary>
/// read epc
/// </summary>
void ReadID()
{
if (this.cbAnticollision.Checked)
{
flagAnti = 0x01;
iniAntiQ = (byte)int.Parse(this.cbqvalue.Text);
}
else
flagAnti = 0x00;
if (this._btReadReadID.Text == "ReadEPC")
{
if (btnEPCTID.Text == "Stop")
{
MessageBox.Show("Please stop TID reading");
return;
}
_lvReadID.Visible = true;
listView1.Visible = false;
this._btReadReadID.Text = "Stop";
this._btClearReadID.Enabled = false;
this.cbAnticollision.Enabled = false;
ClearReadID();
run = true;
}
else
{
this._btReadReadID.Text = "ReadEPC";
this._btClearReadID.Enabled = true;
this.cbAnticollision.Enabled = true;
run = false;
}
if (run)
{
//MessageBox.Show("ReadingMode:" + flagAnti + ",Q" + iniAntiQ);
canReceive = UHF.UHFInventory(flagAnti, iniAntiQ);
if (canReceive)
{
//enable UII thread receiving
if (thrReceiveUii == null)
{
thrReceiveUii = new System.Threading.Thread(ReceiveUiiProc);
thrReceiveUii.IsBackground = true;
thrReceiveUii.Start();
}
else
{
thrReceiveUii.Start();
}
}
}
else
{
//disable UII thread receiving
if (thrReceiveUii != null)
{
thrReceiveUii.Abort();
thrReceiveUii = null;
canReceive = false;
}
//stop UHF reading
UHF.UHFStopGet();
}
}
System.Threading.Thread thrReceiveUii = null;
bool canReceive = false;
string tid = "";
private void ReceiveUiiProc()
{
while (canReceive)
{
int[] uLenUii = new int[1];
byte[] uUii = new byte[128]; //UII should be at least 6 bytes
if (UHF.UHFGetReceived(uLenUii, uUii))//
{
if (uLenUii[0] > 0)
{
Win32.PlayScanSound();
string uii = BitConverter.ToString(uUii, 0, uLenUii[0]).Replace("-", "");
//show to the interface
TagRead ent = new TagRead();
ent.Uii = uii;
ent.Epc = uii.Substring(4, uii.Length - 4); //EPC
ent.Count = 1;
if (!datalist.ContainsKey(ent.Epc))
{
datalist.Add(ent.Epc, 1);
ListViewItem lv = new ListViewItem();
lv.Text = (datalist.Count).ToString();
lv.SubItems.Add(ent.Epc);
lv.SubItems.Add("1");
_lvReadID.Invoke(new EventHandler(delegate
{
_lvReadID.Items.Add(lv);
}));
_lbSumTagsReadID.Invoke(new EventHandler(delegate
{
_lbSumTagsReadID.Text = datalist.Count.ToString();
}));
}
else
{
datalist[ent.Epc] += 1;
DisplayTagID(ent);
}
//UpdateControl(ent);
}
}
// System.Threading.Thread.Sleep(50);
}
}
Dictionary<string, int> datalist = new Dictionary<string, int>();//EPC list, EPC, times
private void DisplayTagID(TagRead ent)
{
_lvReadID.Invoke(new EventHandler(delegate
{
for (int cpt = 0; cpt < _lvReadID.Items.Count; cpt++)
{
if (this._lvReadID.Items[cpt].SubItems[1].Text == ent.Epc)
{
_lvReadID.Items[cpt].SubItems[2].Text = datalist[ent.Epc].ToString();
break;
}
}
}));
}
private void ClearReadID()
{
datalist.Clear();
datalisttid.Clear();
listView1.Items.Clear();
_lvReadID.Items.Clear();
_lbSumTagsReadID.Text = "0";
}
#region invalid codes
delegate void UpdateControlDelegate(TagRead ent);
List<TagRead> list = new List<TagRead>();
private void UpdateControl(TagRead ent)
{
if (this.InvokeRequired)
{
UpdateControlDelegate d = new UpdateControlDelegate(UpdateControl);
this.Invoke(d, ent);
}
else
{
bool exist = false;
foreach (TagRead var in list)
{
if (var.Epc == ent.Epc)
{
exist = true;
var.Count += ent.Count;
}
}
if (!exist)
{
ent.Serial = list.Count + 1;
list.Add(ent);
}
this._lvReadID.Items.Clear();
foreach (TagRead var in list)
{
string[] strArr = new string[3];
strArr[0] = var.Serial.ToString();
strArr[1] = var.Epc;
strArr[2] = var.Count.ToString();
ListViewItem item = new ListViewItem(strArr);
this._lvReadID.Items.Add(item);
}
_lbSumTagsReadID.Invoke(new EventHandler(delegate
{
_lbSumTagsReadID.Text = list.Count.ToString();
}));
}
}
#endregion
Continue reading...
i got sample code in C# and I want to convert to VB2008 for unsing on Smart device (CE).
Thie problem is I can't call Thread "thrReceiveUii = new System.Threading.Thread(ReceiveUiiProc);".
because I can't convert sub "private void ReceiveUiiProc()" to VB.Net.
C# code below.
private void _btReadReadID_Click(object sender, EventArgs e)
{
ReadID();
}
byte[] uAccessPwd = new byte[4];
/// <summary>
/// read epc
/// </summary>
void ReadID()
{
if (this.cbAnticollision.Checked)
{
flagAnti = 0x01;
iniAntiQ = (byte)int.Parse(this.cbqvalue.Text);
}
else
flagAnti = 0x00;
if (this._btReadReadID.Text == "ReadEPC")
{
if (btnEPCTID.Text == "Stop")
{
MessageBox.Show("Please stop TID reading");
return;
}
_lvReadID.Visible = true;
listView1.Visible = false;
this._btReadReadID.Text = "Stop";
this._btClearReadID.Enabled = false;
this.cbAnticollision.Enabled = false;
ClearReadID();
run = true;
}
else
{
this._btReadReadID.Text = "ReadEPC";
this._btClearReadID.Enabled = true;
this.cbAnticollision.Enabled = true;
run = false;
}
if (run)
{
//MessageBox.Show("ReadingMode:" + flagAnti + ",Q" + iniAntiQ);
canReceive = UHF.UHFInventory(flagAnti, iniAntiQ);
if (canReceive)
{
//enable UII thread receiving
if (thrReceiveUii == null)
{
thrReceiveUii = new System.Threading.Thread(ReceiveUiiProc);
thrReceiveUii.IsBackground = true;
thrReceiveUii.Start();
}
else
{
thrReceiveUii.Start();
}
}
}
else
{
//disable UII thread receiving
if (thrReceiveUii != null)
{
thrReceiveUii.Abort();
thrReceiveUii = null;
canReceive = false;
}
//stop UHF reading
UHF.UHFStopGet();
}
}
System.Threading.Thread thrReceiveUii = null;
bool canReceive = false;
string tid = "";
private void ReceiveUiiProc()
{
while (canReceive)
{
int[] uLenUii = new int[1];
byte[] uUii = new byte[128]; //UII should be at least 6 bytes
if (UHF.UHFGetReceived(uLenUii, uUii))//
{
if (uLenUii[0] > 0)
{
Win32.PlayScanSound();
string uii = BitConverter.ToString(uUii, 0, uLenUii[0]).Replace("-", "");
//show to the interface
TagRead ent = new TagRead();
ent.Uii = uii;
ent.Epc = uii.Substring(4, uii.Length - 4); //EPC
ent.Count = 1;
if (!datalist.ContainsKey(ent.Epc))
{
datalist.Add(ent.Epc, 1);
ListViewItem lv = new ListViewItem();
lv.Text = (datalist.Count).ToString();
lv.SubItems.Add(ent.Epc);
lv.SubItems.Add("1");
_lvReadID.Invoke(new EventHandler(delegate
{
_lvReadID.Items.Add(lv);
}));
_lbSumTagsReadID.Invoke(new EventHandler(delegate
{
_lbSumTagsReadID.Text = datalist.Count.ToString();
}));
}
else
{
datalist[ent.Epc] += 1;
DisplayTagID(ent);
}
//UpdateControl(ent);
}
}
// System.Threading.Thread.Sleep(50);
}
}
Dictionary<string, int> datalist = new Dictionary<string, int>();//EPC list, EPC, times
private void DisplayTagID(TagRead ent)
{
_lvReadID.Invoke(new EventHandler(delegate
{
for (int cpt = 0; cpt < _lvReadID.Items.Count; cpt++)
{
if (this._lvReadID.Items[cpt].SubItems[1].Text == ent.Epc)
{
_lvReadID.Items[cpt].SubItems[2].Text = datalist[ent.Epc].ToString();
break;
}
}
}));
}
private void ClearReadID()
{
datalist.Clear();
datalisttid.Clear();
listView1.Items.Clear();
_lvReadID.Items.Clear();
_lbSumTagsReadID.Text = "0";
}
#region invalid codes
delegate void UpdateControlDelegate(TagRead ent);
List<TagRead> list = new List<TagRead>();
private void UpdateControl(TagRead ent)
{
if (this.InvokeRequired)
{
UpdateControlDelegate d = new UpdateControlDelegate(UpdateControl);
this.Invoke(d, ent);
}
else
{
bool exist = false;
foreach (TagRead var in list)
{
if (var.Epc == ent.Epc)
{
exist = true;
var.Count += ent.Count;
}
}
if (!exist)
{
ent.Serial = list.Count + 1;
list.Add(ent);
}
this._lvReadID.Items.Clear();
foreach (TagRead var in list)
{
string[] strArr = new string[3];
strArr[0] = var.Serial.ToString();
strArr[1] = var.Epc;
strArr[2] = var.Count.ToString();
ListViewItem item = new ListViewItem(strArr);
this._lvReadID.Items.Add(item);
}
_lbSumTagsReadID.Invoke(new EventHandler(delegate
{
_lbSumTagsReadID.Text = list.Count.ToString();
}));
}
}
#endregion
Continue reading...