Пример #1
0
        private void btn_Update_Click(object sender, EventArgs e)
        {
            if (null == m_clsInterface)
            {
                MessageBox.Show("Error: Interface class is null.",
                                "Configuration - Error",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }



            if
            (
                MessageBox.Show("If you change the setting, The device will be restarted.\nAre you sure?",
                                "Configuration - Set communication port",
                                MessageBoxButtons.YesNo,
                                MessageBoxIcon.Question)

                ==

                DialogResult.Yes
            )
            {
                UInt32 oemData = 0;
                oemData =
                    (rBtn_USB.Checked == true) ? (uint)enumPORT.ENUM_PORT_USB : (uint)enumPORT.ENUM_PORT_UART;

                rfid.Constants.Result status = m_clsInterface.API_MacWriteOemData((ushort)enumOEM_ADDR.HOST_IF_SEL,
                                                                                  oemData);

                if (rfid.Constants.Result.OK != status)
                {
                    MessageBox.Show("Set communication port unsuccessfully",
                                    "Configuration - Set communication port",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    return;
                }



                if (rfid.Constants.Result.OK != m_clsInterface.API_ControlSoftReset())
                {
                    MessageBox.Show("Reset reader unsuccessfully",
                                    "Configuration - Reset reader",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    return;
                }


                m_dlgControlItem(ENUM_ITEM_TYPE.FUNC_DISCONNECT, null);

                this.Close();
            }//if
        }
Пример #2
0
//===========================Back Ground==========================================
        private void MonitorUpdate(object sender, DoWorkEventArgs e)
        {
            MacBootLoaderVersion Version = new MacBootLoaderVersion();
            string strFilePath           = textFilePath.Text;

            Result     result = Result.FAILURE;
            Updatedata strcData;
            int        iLast = 0;
            int        i;


#if _TRACE_OUT_PUT
            m_clsInterface.PrintMagToTxt("--MonitorUpdate---");
#endif

            //ControlItem(ENUM_ITEM_TYPE.TEXT_VER, "");

            //Clear buffer
            rfid.clsPacket.TRANS_API_ClearBuffer();

            //Compare OEMFile VersionNumber with Reader OEMVersionNumber
            if (sLine != ReaderOEMNumber)
            {
                ControlItem(ENUM_ITEM_TYPE.TEXT_STATUS, string.Format(" Write OEMCfg file failure."));
                //m_clsBackThread.ReportProgress(0);
                ControlItem(ENUM_ITEM_TYPE.PROG_SET_MAX, (int)m_lFileSize);
                ControlItem(ENUM_ITEM_TYPE.PROG_CLEAR, null);
                ControlItem(ENUM_ITEM_TYPE.LABEL_PERCENT_TEXT, string.Format("{0}%", 0));

                MessageBox.Show(string.Format("The browser file is invalid for this product.", result.ToString()),
                                " ",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }
            else//Write OEM File to the device
            {
                //ControlItem(ENUM_ITEM_TYPE.PROG_SET_MAX, (int)m_lFileSize);
                ControlItem(ENUM_ITEM_TYPE.PROG_SET_MAX, 100);
                ControlItem(ENUM_ITEM_TYPE.PROG_CLEAR, null);
                ControlItem(ENUM_ITEM_TYPE.LABEL_PERCENT_TEXT, string.Format("{0}%", 0));
                rfid.Constants.Result status;
                OEMPercentageFlag = false;
                StreamReader OEMReader = new StreamReader(m_fileStream);
                iRealReadCountOEM = (int)m_lFileSize;
                while ((addLine = OEMReader.ReadLine()) != null)
                {
                    iRealReadCountOEM = iRealReadCountOEM - (addLine.Length + 2);
                    if (addLine.Contains("0x"))
                    {
                        if (OEMPercentageFlag == false)
                        {
                            iRealReadCountOEMBtnHalf = iRealReadCountOEM + 23;//BtnHalf=Total-TopHalf
                            iRealReadCountOEMBtnHalf = iRealReadCountOEMBtnHalf / 23;
                            OEMPercentage            = Convert.ToInt16(Math.Ceiling((100.0 / iRealReadCountOEMBtnHalf)));
                            OEMPercentageFlag        = true;
                        }

                        iLast = iLast + (int)OEMPercentage;
                        if (iLast > 100)
                        {
                            i = 100 - (iLast - (int)OEMPercentage);
                            if (i > 0)
                            {
                                OEMPercentage = i;
                            }
                        }

                        OEMLine  = addLine.Split(',');
                        addLine  = OEMLine[0].Trim();
                        dataLine = OEMLine[1].Trim();
                        string[] SusaddLine = addLine.Split('x');
                        addLine    = SusaddLine[1].Trim();
                        OEMAddress = UInt16.Parse(addLine, System.Globalization.NumberStyles.HexNumber);
                        string[] SusdataLine = dataLine.Split('x');
                        dataLine = SusdataLine[1].Trim();
                        OEMData  = UInt32.Parse(dataLine, System.Globalization.NumberStyles.HexNumber);
                        switch (m_clsInterface.API_MacWriteOemData(OEMAddress, OEMData))
                        {
                        case rfid.Constants.Result.OK:
                            switch (m_clsInterface.API_MacReadOemData(OEMAddress, ref checkOEMData))
                            {
                            case rfid.Constants.Result.OK:
                                if (OEMData != checkOEMData)        //Compare Error
                                {
                                    MessageBox.Show("Write OEMData Failure.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    ControlItem(ENUM_ITEM_TYPE.PROG_CLEAR, null);
                                    ControlItem(ENUM_ITEM_TYPE.LABEL_PERCENT_TEXT, string.Format("{0}%", 0));
                                    return;
                                }
                                m_clsBackThread.ReportProgress((int)OEMPercentage);
                                UpdateOEMCfgCompleteFlag = true;
                                break;

                            case rfid.Constants.Result.INVALID_PARAMETER:
                                UpdateOEMCfgCompleteFlag = false;
                                MessageBox.Show("Invalid Parameter.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                ControlItem(ENUM_ITEM_TYPE.PROG_CLEAR, null);
                                ControlItem(ENUM_ITEM_TYPE.LABEL_PERCENT_TEXT, string.Format("{0}%", 0));
                                return;

                            case rfid.Constants.Result.FAILURE:
                                //Get error
                                result = m_clsInterface.API_MacGetError(ref uiCurError, ref uiLastError);
                                if (result == rfid.Constants.Result.OK)
                                {
                                    MessageBox.Show(string.Format("Error Code: 0x{0:X3}", uiCurError), " ", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    UpdateOEMCfgCompleteFlag = false;
                                    ControlItem(ENUM_ITEM_TYPE.PROG_CLEAR, null);
                                    ControlItem(ENUM_ITEM_TYPE.LABEL_PERCENT_TEXT, string.Format("{0}%", 0));
                                    return;
                                }
                                UpdateOEMCfgCompleteFlag = false;
                                ControlItem(ENUM_ITEM_TYPE.PROG_CLEAR, null);
                                ControlItem(ENUM_ITEM_TYPE.LABEL_PERCENT_TEXT, string.Format("{0}%", 0));
                                break;
                            }
                            break;

                        case rfid.Constants.Result.INVALID_PARAMETER:
                            MessageBox.Show(string.Format("Write OEM Address(h): 0x{0} Fail [INVALID_PARAMETER]", addLine), " ", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            UpdateOEMCfgCompleteFlag = false;
                            ControlItem(ENUM_ITEM_TYPE.PROG_CLEAR, null);
                            ControlItem(ENUM_ITEM_TYPE.LABEL_PERCENT_TEXT, string.Format("{0}%", 0));
                            return;

                        case rfid.Constants.Result.FAILURE:
                            //Get error
                            result = m_clsInterface.API_MacGetError(ref uiCurError, ref uiLastError);
                            if (result == rfid.Constants.Result.OK)
                            {
                                MessageBox.Show(string.Format("Error Code: 0x{0:X3}", uiCurError), " ", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                UpdateOEMCfgCompleteFlag = false;
                                ControlItem(ENUM_ITEM_TYPE.PROG_CLEAR, null);
                                ControlItem(ENUM_ITEM_TYPE.LABEL_PERCENT_TEXT, string.Format("{0}%", 0));
                                return;
                            }
                            UpdateOEMCfgCompleteFlag = false;
                            ControlItem(ENUM_ITEM_TYPE.PROG_CLEAR, null);
                            ControlItem(ENUM_ITEM_TYPE.LABEL_PERCENT_TEXT, string.Format("{0}%", 0));
                            break;
                        }
                    }
                }

                //m_lFileSize = m_lFileSize - 40;
                //m_clsBackThread.ReportProgress(40);
                //for (int filesize = 0; filesize<(int)m_lFileSize; filesize = filesize + 40)
                //{
                //Increase progress bar
                //m_clsBackThread.ReportProgress((int)m_lFileSize);
                //m_clsBackThread.ReportProgress(filesize);
                //}
                //System.Threading.Thread.Sleep(10);
            }
            //m_clsBackThread.ReportProgress(100);
            ControlItem(ENUM_ITEM_TYPE.TEXT_STATUS, "Update progress finished.");
            MessageBox.Show("Update OEMCfg successfully.");
            //initial Progress Bar
            ControlItem(ENUM_ITEM_TYPE.PROG_SET_MAX, 100);
            ControlItem(ENUM_ITEM_TYPE.PROG_CLEAR, null);
            ControlItem(ENUM_ITEM_TYPE.LABEL_PERCENT_TEXT, string.Format("{0}%", 0));
            m_clsInterface.API_ControlSoftReset();
//            OpenDevice();
//            Connect();
//            GetOEMVersion();
        }