private void btnTestHgaFola_Click(object sender, EventArgs e)
        {
            //FolaTagDataForm form = new FolaTagDataForm();
            //form.ShowDialog();

            FolaReader  folaTag  = new FolaReader();
            FolaTagData folaData = new FolaTagData();

            try
            {
                // Don't forget to place file GCL52FW.DLL and RFID.DLL in the same directory with this executable file
                // Both files are in "lib" directory

                // FOLA = Read/Write Carrier Tag

                folaTag.PortSettings.PortName = "COM9"; // Don't need to set another values (baud rate, parity, databit, stopbit) , leave them default.
                folaTag.Initialize(false);

                // --- Read ----
                folaTag.ReadRFIDTag(0, ref folaData);  // Read from Head 0
                //folaData.CarrierID <- Carrier ID
                // folaData.WorkOrder <- WorkOrder
                // folaData.WorkOrderVersion <- WorkOrder Version
                // folaData[0].HgaSN <-- 1st HGA Serial Number
                // folaData[0].Status <-- 1st HGA Status
                // .....
                // .....
                // folaData[9].HgaSN <-- last HGA Serial Number
                // folaData[9].Status <-- last HGA Status

                //folaData[0].HgaSN = "DDDDDDDDDD";
                //folaData[0].Status = 'A';
                //folaData.SetProcessStepData(5, 'V', new StringBuilder("ZZZZZZ"));
                //folaData.LastStep = 6;
                //folaData.ProcStep[5].StationCode = folaData.ProcStep[4].StationCode;
                //folaData.ProcStep[5].ProcessRecipe = folaData.ProcStep[4].ProcessRecipe;
                //folaData.LastStep = 8;

                //folaTag.WriteRFIDTag(0, folaData);

                //folaData = folaTag.ReadRFIDTag(0);

                // --- Write ----

                //folaData[0].HgaSN = "XYZ100001D"; // 10 digig HGA serial number , for loading S/N will be generated by the machine
                //// the s/n is generated from carrier id(3)+slot(1)+cycle count(5)+check sum(1) = totally 10 digit
                //// use below functions to generate serial number
                //folaData[0].Status = 'A'; // HGA Status A = Pass , B = Fail
                //// .....
                //folaData[9].HgaSN = "XYZA00001Z";
                //folaData[9].Status = 'A';


                //// For CLU , write count must be plus one everytime
                //folaData.WriteCount++;

                //// Get Process Step from WorkOrder [Process]
                //folaData.ProcStep[0].StationCode = 'A'; // <-- ProcessStep1=A
                //folaData.ProcStep[0].ProcessRecipe = "SLS-1"; // <-- ProgramName1=SLS-1
                //folaData.ProcStep[1].StationCode = 'C'; // <-- ProcessStep2=C
                //folaData.ProcStep[1].ProcessRecipe = "SAS-1"; // <-- ProgramName2=SAS-1
                //folaData.ProcStep[2].StationCode = 'Q'; // <-- ProcessStep3=Q
                //folaData.ProcStep[2].ProcessRecipe = "SUL-1"; // <-- ProgramName3=SUL-1
                //folaData.ProcStep[3].StationCode = ' ';
                //folaData.ProcStep[3].ProcessRecipe = "";
                //// .....
                //folaData.ProcStep[folaData.MaxProcStep - 1].StationCode = ' ';
                //folaData.ProcStep[folaData.MaxProcStep - 1].ProcessRecipe = "";

                //folaData.LastStep = 1; // CLU Load Module is station code A , process step = 1 <- set laststep = process step

                // WriteRFIDTag(RFHead rfHead, FolaTagData tag, bool reReadBeforeWrite, bool writeProcessStep)
                // reReadBeforeWrite , true = compare the carrierID inside the RF tag and carrierID inside FolaTagData before writing to prevent wrong carrier writing.
                // writeProcessStep , true = write Process Step/Setup File too, For CLU must set as true.
                // WriteRFIDTag will not write CarrierID
                //folaTag.WriteRFIDTag(0, folaData, true);

                //byte checksum = folaTag.ReadCheckSum(0);
                //folaTag.WriteCheckSum(0, 0xac);

                MessageBox.Show("Done");
            }
            catch (ExceptionRFID ex)
            {
                MessageBox.Show(ex.Message);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            folaTag.ShutDown();
        }
        /// <summary>
        /// Read RFID
        /// </summary>
        public void ReadFolaRFID(RFHead RFIDHead)
        {
            _isReflowRequired = true;
            _rfidError        = RFIDErrors.NoError;
            if (HSTMachine.Workcell.HSTSettings.Install.OperationMode == OperationMode.Simulation)
            {
                Thread.Sleep(CommonFunctions.SIMULATION_DELAY);
                return;
            }


            _state = RFIDState.Reading;
            if (RFIDHead == RFHead.Head1)
            {
                try
                {
                    _readFolaTagData = _RFIDScanner.ReadRFIDTag(RFHead.Head1);  // Read RFID from Input Station
                    _state           = RFIDState.Idle;

                    if (HSTMachine.Workcell.HSTSettings.Install.DataLoggingForRFIDAndSeatrackRecordUpdateEnabled)
                    {
                        if (HSTMachine.Workcell.HSTSettings.Install.EnableDebugLog)
                        {
                            XyratexOSC.Logging.Log.Info(this, "Read RFID tag at Input Station for Carrier: {0}", _readFolaTagData.CarrierID);
                            XyratexOSC.Logging.Log.Info(this, "Carrier Size: {0}", _readFolaTagData.CarrierSize);
                            XyratexOSC.Logging.Log.Info(this, "Current Process Station Code: {0}", _readFolaTagData.CurrentProcessStep.StationCode);
                            XyratexOSC.Logging.Log.Info(this, "Current Process Recipe: {0}", _readFolaTagData.CurrentProcessStep.ProcessRecipe);
                            for (int x = 0; x < _readFolaTagData.CarrierSize; x++)
                            {
                                XyratexOSC.Logging.Log.Info(this, "HGA {0} Serial Number: {1}, Status: {2}, HGA Process Recipe: {3}, HGA Station Code: {4}", (x + 1), _readFolaTagData.HGAData[x].HgaSN, _readFolaTagData.HGAData[x].Status.ToString(), _readFolaTagData.ProcStep[x].ProcessRecipe, _readFolaTagData.ProcStep[x].StationCode.ToString());
                            }
                            XyratexOSC.Logging.Log.Info(this, "Last Step: {0}", _readFolaTagData.LastStep);
                            XyratexOSC.Logging.Log.Info(this, "MaxProcStep: {0}", _readFolaTagData.MaxProcStep);

                            XyratexOSC.Logging.Log.Info(this, "Work Order: {0}", _readFolaTagData.WorkOrder);
                            XyratexOSC.Logging.Log.Info(this, "Work Order Version: {0}", _readFolaTagData.WorkOrderVersion.ToString());
                            XyratexOSC.Logging.Log.Info(this, "Write Count: {0}", _readFolaTagData.WriteCount);
                        }

                        if (OnRFIDFolaReadInputStationDone != null)
                        {
                            OnRFIDFolaReadInputStationDone(_readFolaTagData);
                        }
                    }
                }
                catch (Exception ex)
                {
                    _state     = RFIDState.Idle;
                    _rfidError = RFIDErrors.RFIDReadError;
                    HSTException.Throw(HSTErrors.InputRFIDReadFailed, ex);
                }
            }
            else if (RFIDHead == RFHead.Head2)
            {
                try
                {
                    _readFolaTagData = _RFIDScanner.ReadRFIDTag(RFHead.Head2);  // Read RFID from Output Station
                    _state           = RFIDState.Idle;

                    if (HSTMachine.Workcell.HSTSettings.Install.DataLoggingForRFIDAndSeatrackRecordUpdateEnabled)
                    {
                        if (HSTMachine.Workcell.HSTSettings.Install.EnableDebugLog)
                        {
                            XyratexOSC.Logging.Log.Info(this, "Read RFID tag at Output Station for Carrier: {0}", _readFolaTagData.CarrierID);
                            XyratexOSC.Logging.Log.Info(this, "Carrier Size: {0}", _readFolaTagData.CarrierSize);
                            XyratexOSC.Logging.Log.Info(this, "Current Process Station Code: {0}", _readFolaTagData.CurrentProcessStep.StationCode);
                            XyratexOSC.Logging.Log.Info(this, "Current Process Recipe: {0}", _readFolaTagData.CurrentProcessStep.ProcessRecipe);
                            for (int x = 0; x < _readFolaTagData.CarrierSize; x++)
                            {
                                XyratexOSC.Logging.Log.Info(this, "HGA {0} Serial Number: {1}, Status: {2}, HGA Process Recipe: {3}, HGA Station Code: {4}", (x + 1), _readFolaTagData.HGAData[x].HgaSN, _readFolaTagData.HGAData[x].Status.ToString(), _readFolaTagData.ProcStep[x].ProcessRecipe, _readFolaTagData.ProcStep[x].StationCode.ToString());
                            }
                            XyratexOSC.Logging.Log.Info(this, "Last Step: {0}", _readFolaTagData.LastStep);
                            XyratexOSC.Logging.Log.Info(this, "MaxProcStep: {0}", _readFolaTagData.MaxProcStep);

                            XyratexOSC.Logging.Log.Info(this, "Work Order: {0}", _readFolaTagData.WorkOrder);
                            XyratexOSC.Logging.Log.Info(this, "Work Order Version: {0}", _readFolaTagData.WorkOrderVersion.ToString());
                            XyratexOSC.Logging.Log.Info(this, "Write Count: {0}", _readFolaTagData.WriteCount);
                        }

                        if (OnRFIDFolaReadOutputStationDone != null)
                        {
                            OnRFIDFolaReadOutputStationDone(_readFolaTagData);
                        }
                    }
                }
                catch (Exception ex)
                {
                    _state     = RFIDState.Idle;
                    _rfidError = RFIDErrors.RFIDReadError;
                    HSTException.Throw(HSTErrors.OutputRFIDReadError, ex);
                }
            }

            return;
        }