public void LoadDataMQCStarting()
        {
            try
            {
                stopwatch.Start();
                LoadAdress();
                if (ListMachines.Count > 0)
                {
                    DicMQCVariableIP = new Dictionary <string, MQCVariable>();

                    foreach (var machine in ListMachines)
                    {
                        int                   ConnectionPLC = -1;
                        MQCVariable           mQCVariable   = new MQCVariable();
                        QRMQC_MES             qRMQC_MES     = new QRMQC_MES();
                        QRIDMES               qRIDMES       = new QRIDMES();
                        Sharp.ReadVariablePLC pLC           = new Sharp.ReadVariablePLC(machine.IP, 0, 0, out ConnectionPLC);
                        mQCVariable.Connection = ConnectionPLC;
                        if (ConnectionPLC == 0)
                        {
                            Dictionary <string, bool> DicStatusPLC = new Dictionary <string, bool>();

                            DicStatusPLC             = pLC.ReadStatusPLCMQC();
                            mQCVariable.DicSPLCtatus = DicStatusPLC;

                            if (DicStatusPLC.Count == 4)
                            {
                                if (DicStatusPLC[VariablePLC.FlagKT])
                                {
                                    string QRMES = pLC.ReadAreaByteToString(181, 100, 100);
                                    mQCVariable.QRMES = QRMES;

                                    string QRID = pLC.ReadAreaByteToString(181, 0, 100);
                                    mQCVariable.QRID = QRID;

                                    var ResultValidationQRCode = SubFunction.IsValidationQRCode(QRMES, QRID);
                                    pLC.WriteDinttoPLC(ResultValidationQRCode, 181, 206, 2);//write message error to PLC
                                    if (ResultValidationQRCode == 0)
                                    {
                                        pLC.WritebittoPLC(true, 181, 204, 1);//Write FlagKT to PLC
                                    }
                                    else
                                    {
                                        pLC.WritebittoPLC(false, 181, 204, 1);//Write FlagKT to PLC
                                    }

                                    qRMQC_MES = QRSpilittoClass.QRstring2MQCFormat(mQCVariable.QRMES);
                                    //  get values from db and write value PLC
                                    SQLUpload.SQLQRUpdate sQLQR      = new SQLQRUpdate();
                                    DataTable             dtQRRecord = sQLQR.GetQuanityFromQRMES(mQCVariable.QRMES);

                                    if (dtQRRecord.Rows.Count == 1)
                                    {
                                        var OutputQty = Int16.Parse(dtQRRecord.Rows[0]["OutputQty"].ToString());
                                        var NGQty     = Int16.Parse(dtQRRecord.Rows[0]["NGQty"].ToString());
                                        var RWQty     = Int16.Parse(dtQRRecord.Rows[0]["RWQty"].ToString());
                                        var Total     = Int16.Parse(dtQRRecord.Rows[0]["TotalQty"].ToString());
                                        if (qRMQC_MES.quantity > (OutputQty + NGQty + RWQty) && qRMQC_MES.quantity > Total)
                                        {
                                            pLC.WriteMQCProducedQuantitytoPLC(OutputQty, NGQty, RWQty);
                                        }
                                        else
                                        {
                                            //Write to PLC values to know QR production finished
                                            pLC.WriteDinttoPLC(4, 181, 206, 2);//Completed QR MES
                                        }
                                    }
                                    else if (dtQRRecord.Rows.Count == 0)
                                    {
                                        pLC.WriteMQCProducedQuantitytoPLC(0, 0, 0);
                                    }

                                    List <int> ListMQCQty = pLC.ReadQuantityMQC();
                                    mQCVariable.ListMQCQty = ListMQCQty;
                                    List <int> ListMQCProduced = pLC.ReadQuantityMQCProduced();
                                    mQCVariable.ListQtyProduced = ListMQCProduced;
                                    List <int> ListNG38 = pLC.ReadAreaIntToListInt(3, 4, 76);
                                    mQCVariable.ListNG38 = ListNG38;
                                    List <int> ListRW38 = pLC.ReadAreaIntToListInt(4, 4, 76);
                                    mQCVariable.ListRW38 = ListRW38;
                                }
                            }
                        }

                        DicMQCVariableIP.Add(machine.IP, mQCVariable);
                        pLC.Diconnect();
                        qRMQC_MES = new QRMQC_MES();
                        qRMQC_MES = QRSpilittoClass.QRstring2MQCFormat(mQCVariable.QRMES);
                        qRIDMES   = QRSpilittoClass.QRstring2IDFormat(mQCVariable.QRID);
                        MachineOperation operation = new MachineOperation();
                        operation.IP        = machine.IP;
                        operation.Line      = machine.Line;
                        operation.Lot       = qRMQC_MES.PO;
                        operation.Inspector = qRIDMES.FullName;
                        operation.product   = qRMQC_MES.Product;

                        if (mQCVariable.ListMQCQty.Count == 3)
                        {
                            operation.Output = mQCVariable.ListMQCQty[0];
                            operation.NG     = mQCVariable.ListMQCQty[1];
                            operation.Rework = mQCVariable.ListMQCQty[2];
                            operation.Status = "Updating";
                        }
                        else if (mQCVariable.ListMQCQty.Count == 0)
                        {
                            operation.Output = 0;
                            operation.NG     = 0;
                            operation.Rework = 0;
                            operation.Status = "Waiting";
                        }
                        machineOperations.Add(operation);
                    }
                    datagridMachines.ItemsSource = machineOperations;
                }
            }
            catch (Exception ex)
            {
                SystemLog.Output(SystemLog.MSG_TYPE.Err, "Read PLC fail", ex.Message);
            }
        }