private void bEpcWrite_Click(object sender, EventArgs e) { ushort[] value = new ushort[16]; int i = 0; byte membank; byte wordptr; byte wordcnt; int status; string hexValues; membank = (byte)(cEpcMembank.SelectedIndex); wordptr = (byte)(cEpcWordptr.SelectedIndex); wordcnt = (byte)(cEpcWordcnt.SelectedIndex); hexValues = tEpcData.Text; string[] hexValuesSplit = hexValues.Split(' '); try { foreach (String hex in hexValuesSplit) { // Convert the number expressed in base-16 to an integer. if (hex.Length >= 2) { int x = Convert.ToInt32(hex, 16); value[i++] = (ushort)x; } } } catch (Exception) { lInfo.Items.Add("Please input data needed"); return; } if (i != wordcnt) { lInfo.Items.Add("Please input data needed"); return; } for (byte j = 0; j < wordcnt; j++) { status = Reader1.EpcWrite(membank, (byte)(wordptr + j), value[j]); if (status != 0) { lInfo.Items.Add("Write failed!"); return; } } lInfo.Items.Add("Write success!"); }
private void bEpcWrite_Click(object sender, EventArgs e) { int membank1; int wordptr1; int wordcnt1; int status1 = 0; byte[] value1 = new byte[16]; bool makan = false; string s = "The data is:"; string s1 = ""; string s2 = ""; membank1 = cEpcMembank.SelectedIndex; wordptr1 = cEpcWordptr.SelectedIndex; wordcnt1 = cEpcWordcnt.SelectedIndex; status1 = Reader1.EpcRead((byte)membank1, (byte)wordptr1, (byte)wordcnt1, ref value1); for (int i = 0; i < wordcnt1 * 2; i++) { s1 = string.Format("{0:X2}", value1[i]); s2 += s1; s += s1; } dataBaca = s2; if (status1 != 0) { MessageBox.Show("Kartu Tidak Terbaca"); } else { if (comboBox1.Text == dataBaca) { ushort[] value = new ushort[16]; int i = 0; byte membank; byte wordptr; byte wordcnt; int status; string hexValues; membank = (byte)(cEpcMembank.SelectedIndex); wordptr = (byte)(cEpcWordptr.SelectedIndex); wordcnt = (byte)(cEpcWordcnt.SelectedIndex); hexValues = tEpcData.Text; string[] hexValuesSplit = hexValues.Split(' '); if (comboBox1.Items.Count == 0) { return; } try { foreach (String hex in hexValuesSplit) { // Convert the number expressed in base-16 to an integer. if (hex.Length >= 2) { int x = Convert.ToInt32(hex, 16); value[i++] = (ushort)x; } } } catch (Exception) { MessageBox.Show("Please input data needed"); //lInfo.Items.Add("Please input data needed"); return; } if (i != wordcnt) { MessageBox.Show("Please input data needed"); //lInfo.Items.Add("Please input data needed"); return; } for (byte j = 0; j < wordcnt; j++) { status = Reader1.EpcWrite(membank, (byte)(wordptr + j), value[j]); if (status != 0) { MessageBox.Show("Write Failed!"); // lInfo.Items.Add("Write Failed!"); return; } //else if (comboBox1.SelectedIndex != timerScanEPC_Tick) } MessageBox.Show("Write Succes!"); //lInfo.Items.Add("Write success!"); } else { MessageBox.Show("ID Kartu Tidak Sama"); } } }