private void ProgramTag() { switch (iStep) { case STEP_START: bDone = false; if (tagProgrammer.ChangePowerLevel("25")) { iStep = STEP101; } else { iStep = 0; MessageBox.Show("Cannot change tag programmer power level.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } break; case STEP101: labelMessage.ForeColor = Color.Blue; labelMessage.Text = "Program new UID. Please wait..."; iStep = STEP102; break; case STEP102: switch (iTagType) { case TAG_TYPE_HDX: if (ProgramHDX(sNewUID)) { labelMessage.ForeColor = Color.Blue; labelMessage.Text = "Register tag UID..."; iTotalTagInBox++; txtQuantityPerBox.Text = iTotalTagInBox.ToString(); if (RegisterUID(iDatabase, true)) { iStep = STEP103; } else { labelMessage.ForeColor = Color.Red; labelMessage.Text = "Register tag UID fail!"; MessageBox.Show("Cannot register tag UID.\n" + registration.ErrorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); iStep = STEP202; } } else { labelMessage.ForeColor = Color.Red; labelMessage.Text = "Register bad tag UID..."; if (RegisterUID(iDatabase, false)) { iStep = STEP104; } else { labelMessage.Text = "Register tag UID fail!"; MessageBox.Show("Cannot register tag UID.\n" + registration.ErrorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); iStep = STEP202; } } sNewUID = null; break; case TAG_TYPE_HDX_PLUSE: if (ProgramHDX_Plus(sNewUID, Convert.ToDouble(txtWoTrimFrequency.Text))) { labelMessage.ForeColor = Color.Blue; labelMessage.Text = "Register tag UID..."; iTotalTagInBox++; txtQuantityPerBox.Text = iTotalTagInBox.ToString(); if (RegisterUID(iDatabase, true)) { iStep = STEP103; } else { labelMessage.ForeColor = Color.Red; labelMessage.Text = "Register tag UID fail!"; MessageBox.Show("Cannot register tag UID.\n" + registration.ErrorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); iStep = STEP202; } } else { labelMessage.ForeColor = Color.Red; labelMessage.Text = "Register bad tag UID..."; if (RegisterUID(iDatabase, false)) { iStep = STEP104; } else { labelMessage.Text = "Register tag UID fail!"; MessageBox.Show("Cannot register tag UID.\n" + registration.ErrorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); iStep = STEP202; } } sNewUID = null; break; } break; case STEP103: iTotalTagInBox = registration.CountTotalTagInBoxInSeverAndLocalDatabase(txtWorkOrder.Text, txtBoxNumber.Text); if (iTotalTagInBox >= 0) { txtQuantityPerBox.Text = iTotalTagInBox.ToString(); } labelMessage.ForeColor = Color.White; labelMessage.BackColor = Color.Green; labelMessage.Text = "Program and register tag UID is successful."; iStep = STEP201; break; case STEP104: labelMessage.ForeColor = Color.White; labelMessage.BackColor = Color.Red; labelMessage.Text = "Program UID fail!"; iStep = STEP202; break; case STEP201: iFunction = 0; btnReadtTagUID.Enabled = true; bDone = true; break; case STEP202: iFunction = 0; btnGetNewTagUID.Enabled = true; bDone = true; break; } }
private void Start() { ClearResult(); labelGood.Text = ctrlSys.PartInGoodBox.ToString(); labelQuantityWorked.Text = ctrlSys.QuantityWorked.ToString(); labelReject1.Text = ctrlSys.PartInRejectBox[0].ToString(); labelReject2.Text = ctrlSys.PartInRejectBox[1].ToString(); labelReject3.Text = ctrlSys.PartInRejectBox[2].ToString(); labelReject4.Text = ctrlSys.PartInRejectBox[3].ToString(); this.Cursor = Cursors.WaitCursor; if (ctrlSys.EnTagProgrammer && ctrlSys.EnTagMeter) { if (tagProgrammer.ChangePowerLevel(labelPowerLevel.Text)) { if (chkTest.Checked) { txtMachineMessage.Text = String.Format("Tag Programmer Power Level {0}%\r\n", labelPowerLevel.Text); if (tagMeter.IsAlive()) { if (!bgwInitTagMeter.IsBusy) { btnStart.Enabled = false; bgwInitTagMeter.RunWorkerAsync(); } else { bgwInitTagMeter.CancelAsync(); MessageBox.Show("Tag meter is busy.\nPlease start again.", "Tag meter busy", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show("Not response from tag meter.\nTry again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { ctrlSys.Start(); btnLogout.Enabled = false; btnStart.Enabled = false; btnStop.Enabled = true; btnPause.Enabled = true; } } else { this.Cursor = Cursors.Arrow; MessageBox.Show("Cannot change tag programmer power level.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else if (ctrlSys.EnTagProgrammer) { if (tagProgrammer.ChangePowerLevel(labelPowerLevel.Text)) { ctrlSys.Start(); btnLogout.Enabled = false; btnStart.Enabled = false; btnStop.Enabled = true; btnPause.Enabled = true; } else { this.Cursor = Cursors.Arrow; MessageBox.Show("Cannot change tag programmer power level.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else if (ctrlSys.EnTagMeter) { if (tagMeter.IsAlive()) { if (!bgwInitTagMeter.IsBusy) { btnStart.Enabled = false; bgwInitTagMeter.RunWorkerAsync(); } else { bgwInitTagMeter.CancelAsync(); MessageBox.Show("Tag meter is busy.\nPlease start again.", "Tag meter busy", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show("Not response from tag meter.\nTry again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } this.Cursor = Cursors.Arrow; }