Imports System.Diagnostics.Metrics
Imports System.IO
Imports System.IO.Ports
Imports System.Math
Imports System.Text
Imports AForge.Video.DirectShow
Imports Mysqlx.XDevAPI.Common
Imports OpenCvSharp
Imports uPLibrary.Networking.M2Mqtt

Public Class Main_Form
    Public Program_Name As String = "DUALSONIC_Multi_Function_Tester Ver."
    Public Program_Version As String = "2.2.4"

    ''데이터 베이스 테이블 목록

    Private TDTable As String = "jomtTesterDB.jomtCartridgeTbl"
    Private LDMTable As String = "jomtTesterDB.jomtLDMTbl"
    Private TDTestTable As String = "jomtTesterServerDB.jomtCartridgeTbl"

    Private hfDataTable As String = "jomtTesterDB.jomtHFTestTbl"
    Private hfDataTestTable As String = "jomtTesterServerDB.jomtHFTestTbl"

    Private ldmDataTable As String = "jomtTesterDB.jomtLDMTestTbl"
    Private ldmRfDataTable As String = "jomtTesterDB.jomtLDMRfTestTbl"

    Private rfDataTable As String = "jomtTesterDB.jomtRFTestTbl"
    Private rfDataTestTable As String = "jomtTesterServerDB.jomtRFTestTbl"

    Private pd1CntTable As String = "jomtTesterDB.jomtMES_PD1Tbl"
    Private pd1CntTestTable As String = "jomtTesterServerDB.jomtMES_PD1Tbl"

    Private iqcCntTable As String = "jomtTesterDB.jomtMES_IQCTbl"
    Private iqcCntTestTable As String = "jomtTesterServerDB.jomtMES_IQCTbl"

    Private NonTDTable As String = "jomtTesterDB.jomtNonTDTbl"
    Private NonTDTestTable As String = "jomtTesterServerDB.jomtNonTDTbl"

    Private Const mainModelInfoDB As String = "jomtTesterDB.jomtModelInfoTbl"
    Private Const testModelInfoDB As String = "jomtTesterServerDB.jomtModelInfoTbl"

    ''사용하고자 하는 데이터베이스
    Private TDTableNow As String = TDTable
    Private hfTableNow As String = hfDataTable
    Private rfTableNow As String = rfDataTable
    Private pd1CntTableNow As String = pd1CntTable
    Private iqcCntTableNow As String = iqcCntTable
    Private NonTDTableNow As String = NonTDTable
    Private ApplyModelInfoDB As String = mainModelInfoDB
    Private ldmTestTableNow As String = ldmDataTable
    Private ldmTableNow As String = LDMTable
    Private ldmRfTestTableNow As String = ldmRfDataTable

    Private ParaComport As String
    Private modeSaveSwitch As Boolean = False
    Private recentModelSwitch As Boolean = False

    Private Enum testRunningList
        Running
        Fail
        Success
        TDWritten
        Retry
    End Enum
    Private testState(testRunningList.Retry) As String

    Private Enum ConnectList
        USB
        GPIB
        MAXConnect
    End Enum
    Private ConnectName(ConnectList.GPIB) As String
    Private ConnectSelect As Int16

    Private Enum formTypeList
        full
        iqcHFRFEP
        iqcHF
        iqcRFEP
        iqcDsHF
        prdHF
        prdRFMCEP
        prdRFEP
        prdDsHF
        company
        iqcHFEP
        iqcEP
        iqcRFEPMC
        prdEP
        prdHFLDMEP
        prdLowHF
        prdRFMC
        iqcLDM
        iqcLDMEP
        prdLDM
        prdVRLDM
        prdLDMEP
        MAX_FORM_TYPE
    End Enum
    Private formType As Int16

    '현재 테스트하는 모델 정보
    Private ModelCode As String
    Private ModelName As String
    Private CartTypeName As String
    Private DeviceTypeCode As String
    Private TDUseYn As Boolean = False
    Private HifuUseYn As Boolean = False
    Private RfUseYn As Boolean = False
    Private EpUseYn As Boolean = False
    Private McUseYn As Boolean = False
    Private LdmUseYn As Boolean = False
    Private LowPriceUseYn As Boolean = False
    Private VerificationStep As String

    Private StartSwitch As Boolean

    Private TDSNHeadArray As String()

    Private Const TestCount As Int16 = 10

    Private Const RFTest_Count As Int16 = 2     ''0,1,2 = 세번 측정
    Private Const RFTest_Type As Int16 = 1    ''0,1 = 세번 측정
    Private Const MCTest_Count As Int16 = 1     ''0,1 = 두번 측정
    Private Const EPTest_Count As Int16 = 2     ''0,1,2 = 세 번 측정
    Private Const EPTest_WCount As Int16 = 1
    Private Const DataSaveCount As Int16 = 10
    Private Const LEDReTest As Int16 = 8   ''원하는 좌표 기준 8방위 = 총 9 차례 시도
    Private Const SuccessCode As Int16 = 23

    Private Const ImgSave As String = "ImgSave"
    Private Const ImgCvt As String = "ImgConvert"

    Private Const LEDColorCk As Int16 = 1
    Public LedColorName(LEDColorCk) As String
    Private LedCoordinate(LEDColorCk, LEDColorCk) As Int16
    Private LedCoordinate2(LEDColorCk, LEDColorCk) As Int16
    Private LedHueMin(LEDColorCk) As TextBox
    Private LedHueMax(LEDColorCk) As TextBox
    Private LedSaturMin(LEDColorCk) As TextBox
    Private LedSaturMax(LEDColorCk) As TextBox
    Private LedBrightMin(LEDColorCk) As TextBox
    Private LedBrightMax(LEDColorCk) As TextBox

    'ep config 각 3분류 설정 배열 변수
    Private EpTrigerMode(2, 1) As RadioButton
    Private EpChennal(2) As NumericUpDown
    Private EpScaleMode(2, 1) As RadioButton
    Private EpnudEPScale1(2) As NumericUpDown
    Private EpTimeScale(2) As TextBox
    Private EpDelay(2) As TextBox
    Private EpTriggerLv(2) As NumericUpDown
    Private EpRunTime(2) As NumericUpDown

    Private LedData(LEDColorCk, 2) As Int16

    Public HF_OutMIN As TextBox
    Public HF_OutMax As TextBox
    Public HF_OutRange As TextBox
    Public RF_VRMSMax(RFTest_Count) As TextBox
    Public RF_VRMSMin(RFTest_Count) As TextBox
    Public MC_VPPtxb(MCTest_Count + 1) As TextBox
    Public MC_Widthtxb(MCTest_Count + 1) As TextBox
    Public EP_VPPtxb(EPTest_Count) As TextBox
    Public EP_FREQtxb(EPTest_Count) As TextBox
    Public HF_Outtxb(HFTest_Count) As TextBox
    Public LDMt_WMin(2) As TextBox
    Public LDMt_WMax(2) As TextBox
    Public LDMt_VRMSMax(2) As TextBox
    Public LDMt_VRMSmin(2) As TextBox

    Public JIGON_Timeout As Int16
    Public JIGON_Delay As Int16
    Public JIGDT_Timeout As Int16
    Public StepDelay As Integer
    Public HFRunCount As Int16
    Public HFDataValid As Int16
    Public HFReCkCount As Int16
    Public HFLowShot As Int16

    Private XMoveCrd As Int16
    Private YMoveCrd As Int16

    Private textRunning(TestCount) As TextBox

    Public txbWindow As TextBox

    Private EPVppMin As TextBox
    Private EPVppMax As TextBox
    Private EPFreq(EPTest_Count) As TextBox
    Private EPWidthMin(EPTest_Count) As TextBox
    Private EPWidthMax(EPTest_Count) As TextBox
    Private FWVerNow As TextBox
    Private BatCapacityMin As TextBox
    Private BatCapacityMax As TextBox

    Private rxMessage, cmdMessage, tmpCmdMessage As String

    Private dupDATA As Int16 = 0
    Private Const td_name_size As Int16 = 8

    Private SetTimeScale As Single
    Private SetDelay As Single
    Private SetRunShot As Int16
    Private WebCamNum As Integer
    Private OLEDCamNum As Int16

    Private TestError As Boolean = False

    Private DBCmd As String
    Private InputCnt As Int16
    Private Const InputCntVal As Int16 = 10

    Private DataSaveName(DataSaveCount) As String
    Private ScopeList() As String
    Private SpecList() As String

    Private StartTime As Long
    Private EndTime As Long

    Private NowDate As String
    Private NowTime As String

    Public Structure TestDataList
        Public Test_Serial As String
        Public Test_Firmware As String
        Public Test_Battery As Single
        Public Test_Temperature() As Double
        Public Test_HFData() As Double
        Public Test_HFInterval() As Single
        Public Test_RFVRMS() As Single
        Public Test_RFFreq() As Double
        Public Test_RFPWidth() As Single
        Public Test_RFNWidth() As Single
        Public Test_MCVpp() As Single
        Public Test_MCWidth() As Single
        Public Test_MCFreq() As Single
        Public Test_EPVpp() As Single
        Public Test_EPFreq() As Single
        Public Test_EPPWidth() As Single
        Public Test_EPNWidth() As Single
    End Structure
    Private TestData As TestDataList

    Private Enum TestStepList
        HF_NewSuc = 21
        HF_NEWFail
        RF_NewSuc
        RF_NewFail
        HF_ReSuc
        HF_ReFail
        RF_ReSuc
        RF_ReFail
    End Enum
    Private processNum As Int16


    Private Enum TD_Data
        TestStep
        TestDate
        Freq
        Grade
        power
        motor
    End Enum
    Private TDDataSet(TD_Data.motor) As String

    Private Enum LDM_Data
        TestStep
        pvDate
        freq_1
        freq_2
        freq_3
        power_1
        power_2
        power_3
    End Enum
    Private LDM_DataSet(LDM_Data.power_3) As String

    Private Enum TestList
        Start
        HIFU
        RF
        MC
        EP
        Battey
        Temp
        DataWrite
        DataWritten
        MESreg
        DBWrite
        COUNT
        CSV

        Firmware
        Wait
    End Enum
    Private TestStep As Int16 = TestList.Wait

    Private Enum HifuTest_Step
        Step1   '6850
        Step2   '7000
        step3   '7150

        step4
        step5
    End Enum
    Private HifuStep(HifuTest_Step.step5) As Int16

    Private Enum HifuTest_Diff
        Step1_2
        Step2_3
    End Enum

    Private HFTest_Count As Int16 = HifuTest_Step.step3

    Private Enum TempData
        DivTemp
        CartTemp
        CPUTemp
    End Enum

    Private TmpMin(TempData.CartTemp) As TextBox
    Private TmpMax(TempData.CartTemp) As TextBox
    Private TempSet(TempData.CPUTemp) As TextBox

    ''MQTT

    Public MQTClient As MqttClient
    Public mqttBroker As String = String.Empty
    Public mqttTopic As String = String.Empty

    Private todayCount As Integer = 1   '' 금일 측정 개수
    Private newTDYnFlag As Boolean = False ''임시 td 생성 여부
    Private ResponseErrorCheck As Boolean = False ''ep 검사 계측기 오류 여부
    Private writeTDSNFlag As Boolean = False ''TD 계열 PCB 작성 여부

    Private Sub typeDataSetting()
        If formType = formTypeList.iqcRFEP Or formType = formTypeList.prdRFEP Then
            TmpMin(TempData.DivTemp) = txbTpDevMin_AL
            TmpMin(TempData.CartTemp) = txbTpCartMin_AL
            TmpMax(TempData.DivTemp) = txbTpDevMax_AL
            TmpMax(TempData.CartTemp) = txbTpCartMax_AL

            RF_VRMSMin(0) = txbRFVRmin1_AL
            RF_VRMSMin(1) = txbRFVRmin2_AL
            RF_VRMSMin(2) = txbRFVRmin3_AL

            RF_VRMSMax(0) = txbRFVRmax1_AL
            RF_VRMSMax(1) = txbRFVRmax2_AL
            RF_VRMSMax(2) = txbRFVRmax3_AL

            EPVppMin = txbEPVPmin_AL
            EPVppMax = txbEPVPmax_AL

            EPWidthMin(0) = txbEPDYmin1_AL
            EPWidthMin(1) = txbEPDYmin2_AL
            EPWidthMin(2) = txbEPDYmin3_AL

            EPWidthMax(0) = txbEPDYmax1_AL
            EPWidthMax(1) = txbEPDYmax2_AL
            EPWidthMax(2) = txbEPDYmax3_AL

            FWVerNow = txbFirmVer_AL

            BatCapacityMin = txbBatMin_AL
            BatCapacityMax = txbBatMax_AL

        ElseIf formType = formTypeList.iqcDsHF Or formType = formTypeList.prdDsHF Then
            TmpMin(TempData.DivTemp) = txbDSTmpDe_stMin
            TmpMin(TempData.CartTemp) = txbDSTmpCa_stMin
            TmpMax(TempData.DivTemp) = txbDSTmpDe_stMax
            TmpMax(TempData.CartTemp) = txbDSTmpCa_stMax

            BatCapacityMin = txbDSbat_stMin
            BatCapacityMax = txbDSbat_stMax

            FWVerNow = txbDSfw_st

            HF_OutMIN = txbDShfOut_stMin
            HF_OutMax = txbDShfOut_stMax
            HF_OutRange = txbDShfDif_st

        Else
            HF_OutMIN = txbHFOutMin
            HF_OutMax = txbHFOutMax
            HF_OutRange = txbHFMin

            TmpMin(TempData.DivTemp) = txbTpDevMin
            TmpMin(TempData.CartTemp) = txbTpCartMin
            TmpMax(TempData.DivTemp) = txbTpDevMax
            TmpMax(TempData.CartTemp) = txbTpCartMax

            RF_VRMSMin(0) = txbRFVRmin1
            RF_VRMSMin(1) = txbRFVRmin2
            RF_VRMSMin(2) = txbRFVRmin3

            RF_VRMSMax(0) = txbRFVRmax1
            RF_VRMSMax(1) = txbRFVRmax2
            RF_VRMSMax(2) = txbRFVRmax3

            EPVppMin = txbEPVPmin
            EPVppMax = txbEPVPmax

            EPWidthMin(0) = txbEPDYmin1
            EPWidthMin(1) = txbEPDYmin2
            EPWidthMin(2) = txbEPDYmin3

            EPWidthMax(0) = txbEPDYmax1
            EPWidthMax(1) = txbEPDYmax2
            EPWidthMax(2) = txbEPDYmax3

            LDMt_WMax(0) = txbHFLDMMax1
            LDMt_WMax(1) = txbHFLDMMax2
            LDMt_WMax(2) = txbHFLDMMax3

            LDMt_WMin(0) = txbHFLDMMin1
            LDMt_WMin(1) = txbHFLDMMin2
            LDMt_WMin(2) = txbHFLDMMin3

            LDMt_VRMSMax(0) = txbLDMVRmax1
            LDMt_VRMSMax(1) = txbLDMVRmax2
            LDMt_VRMSMax(2) = txbLDMVRmax3

            LDMt_VRMSmin(0) = txbLDMVRmin1
            LDMt_VRMSmin(1) = txbLDMVRmin2
            LDMt_VRMSmin(2) = txbLDMVRmin3

            FWVerNow = txbFirmVer

            BatCapacityMin = txbBatMin
            BatCapacityMax = txbBatMax

        End If

        If formType = formTypeList.company <> True Then

            If todayCountSet() Then
                txbWindow.AppendText("Today Count Setting Error ! " & vbCrLf)
                txbDayCount.Text = "0"
                txbOkCount.Text = "0"
                txbNgCount.Text = "0"
            End If

        End If

    End Sub


    Public Sub Data_Setting()
        typeDataSetting()

        testState(testRunningList.Running) = "Running"
        testState(testRunningList.Fail) = "F A I L"
        testState(testRunningList.Success) = "O K"
        testState(testRunningList.Retry) = "장 치 F A I L"
        testState(testRunningList.TDWritten) = "이 미 등 록 완 료 된 TD"

        HifuStep(HifuTest_Step.Step1) = txbFrStep1.Text
        HifuStep(HifuTest_Step.Step2) = txbFrStep2.Text
        HifuStep(HifuTest_Step.step3) = txbFrStep3.Text

        'HifuStep(HifuTest_Step.Step1) = "6850"
        'HifuStep(HifuTest_Step.Step2) = "6900"
        'HifuStep(HifuTest_Step.step3) = "7000"
        HifuStep(HifuTest_Step.step4) = "7100"
        HifuStep(HifuTest_Step.step5) = "7150"

        TempSet(TempData.DivTemp) = txbDevTmp
        TempSet(TempData.CartTemp) = txbCartTmp
        TempSet(TempData.CPUTemp) = txbCPUTemp

        EPFreq(0) = txbEPFreq1
        EPFreq(1) = txbEPFreq2
        EPFreq(2) = txbEPFreq3

        textRunning(1) = txbStep1
        textRunning(2) = txbStep2
        textRunning(3) = txbStep3
        textRunning(4) = txbStep4
        textRunning(5) = txbStep5
        textRunning(6) = txbStep6
        textRunning(7) = txbStep7
        textRunning(8) = txbStep8
        textRunning(9) = txbStep9
        textRunning(10) = txbStep10

        LedColorName(0) = "Red"
        LedColorName(1) = "Yellow"

        LedCoordinate(0, 0) = Val(txbRedCdn_X1.Text)   ''Red X
        LedCoordinate(0, 1) = Val(txbRedCdn_Y1.Text)    ''Red Y
        LedCoordinate(1, 0) = Val(txbYelCdn_X1.Text)   ''Red X
        LedCoordinate(1, 1) = Val(txbYelCdn_Y1.Text)    ''Red Y

        LedCoordinate2(0, 0) = Val(txbYelX1.Text)   ''Yellow X
        LedCoordinate2(0, 1) = Val(txbYelY1.Text)    ''Yellow Y
        LedCoordinate2(1, 0) = Val(txbYelX2.Text)   ''Yellow X
        LedCoordinate2(1, 1) = Val(txbYelY2.Text)    ''Yellow Y

        LedHueMin(0) = txbRHueMin
        LedHueMin(1) = txbYHueMin1
        LedHueMax(0) = txbRHueMax
        LedHueMax(1) = txbYHueMax1
        LedSaturMin(0) = txbRSatMin
        LedSaturMin(1) = txbYSatMin1
        LedSaturMax(0) = txbRSatMax
        LedSaturMax(1) = txbYSatMax1
        LedBrightMin(0) = txbRBgtMin
        LedBrightMin(1) = txbYBgtMin1
        LedBrightMax(0) = txbRBgtMax
        LedBrightMax(1) = txbYBgtMax1

        ''jig 관련 변수
        JIGON_Timeout = txbJgTimeout.Text
        JIGON_Delay = txbJgDelay.Text
        JIGDT_Timeout = txbDTTimeout.Text

        ''구간별 딜레이
        StepDelay = nudStepDelay.Text

        ''HIFU 관련 변수
        HFRunCount = txbHFReCnt.Text
        HFDataValid = txbHFeffect.Text
        HFReCkCount = txbHFReCkCnt.Text
        HFLowShot = txbHFLowShot.Text

        'TD Serial Head 구분 스트링 
        TDSNHeadArray = txbTDSNHead.Text.Split("/")

        'ep config 각 txb 담을 배열들
        For i = 0 To 2
            If i = 0 Then
                EpTrigerMode(i, 0) = rdbEPTrAuto1
                EpTrigerMode(i, 1) = rdbEPtrNormal1
                EpChennal(i) = nudEPCh1
                EpScaleMode(i, 0) = rdbEPUnitV1
                EpScaleMode(i, 1) = rdbEPUnitA1
                EpnudEPScale1(i) = nudEPScale1
                EpTimeScale(i) = txbEPFVtime1
                EpDelay(i) = txbEPFVDelay1
                EpTriggerLv(i) = nudEPFVTrgLv1
                EpRunTime(i) = nudEPFVRun1
            ElseIf i = 1 Then
                EpTrigerMode(i, 0) = rdbEPTrAuto2
                EpTrigerMode(i, 1) = rdbEPtrNormal2
                EpChennal(i) = nudEPCh2
                EpScaleMode(i, 0) = rdbEPUnitV2
                EpScaleMode(i, 1) = rdbEPUnitA2
                EpnudEPScale1(i) = nudEPScale2
                EpTimeScale(i) = txbEPFVtime2
                EpDelay(i) = txbEPFVDelay2
                EpTriggerLv(i) = nudEPFVTrgLv2
                EpRunTime(i) = nudEPFVRun2
            Else
                EpTrigerMode(i, 0) = rdbEPTrAuto3
                EpTrigerMode(i, 1) = rdbEPtrNormal3
                EpChennal(i) = nudEPCh3
                EpScaleMode(i, 0) = rdbEPUnitV3
                EpScaleMode(i, 1) = rdbEPUnitA3
                EpnudEPScale1(i) = nudEPScale3
                EpTimeScale(i) = txbEPFVtime3
                EpDelay(i) = txbEPFVDelay3
                EpTriggerLv(i) = nudEPFVTrgLv3
                EpRunTime(i) = nudEPFVRun3
            End If
        Next
    End Sub


    '' 바코드 스캐너 동작

    Private Sub SetInputCnt()
        InputCnt = InputCntVal
        BarTimer.Enabled = True
    End Sub

    Private Sub chbUseBarcode_CheckedChanged(sender As Object, e As EventArgs) Handles chbUseBarcode.CheckedChanged, chbAutoMeasure.CheckedChanged
        txbBarcode.Focus()
    End Sub

    Private Sub BarTimer_Tick(sender As Object, e As EventArgs) Handles BarTimer.Tick
        If InputCnt Then
            InputCnt -= 1
        Else
            BarTimer.Enabled = False
            If txbBarcode.Text.Replace(" ", "") <> "" Or chbAutoMeasure.Checked Then
                If CheckTDSNHead() = True Or InStr(txbBarcode.Text, "[START]") > 0 Then
                    btnRun_Click(sender, e)
                End If
                txbBarcode.Focus()
            Else
                btnRun.Focus()
            End If
            txbBarcode.Refresh()
            btnRun.Refresh()
        End If
    End Sub

    Private Sub txbBarcode_TextChanged(sender As Object, e As EventArgs) Handles txbBarcode.TextChanged
        Dim TmpStr As String

        If InputCnt = 0 And chbUseBarcode.Checked = True Then
            If TestStep = TestList.Wait Then
                TmpStr = txbBarcode.Text
                txbCmdWindow.AppendText(TmpStr)
                If (Len(TmpStr) > 1) Then
                    TmpStr = Mid(TmpStr, Len(TmpStr), 1)
                    txbBarcode.Clear()
                    txbBarcode.AppendText(TmpStr)
                End If
                SetInputCnt()
            End If
        End If
    End Sub

    Private Sub txbBarcode_Click(sender As Object, e As EventArgs) Handles txbBarcode.Click
        txbBarcode.BackColor = Color.White
        If chbUseBarcode.Checked = False Then
            txbBarcode.Clear()
        End If
    End Sub

    Private Function CheckTDSNHead() As Boolean
        For Each TDSNHead As String In TDSNHeadArray
            If InStr(txbBarcode.Text, TDSNHead) > 0 Then
                Return True
            End If
        Next TDSNHead

        Return False
    End Function
    '' ------------------------------------------------------

    Private Sub Main_Form_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        PositionSetting()
        txbWindow = txbCmdWindow
        txbWindow.AppendText("Config Data Loading...." & vbCrLf)
        WebCamNum = -1

        '' 연결 방식 관련
        ConnectName(ConnectList.USB) = "USB"
        ConnectName(ConnectList.GPIB) = "GPIB"

        TestDBCon()
        txbWindow.AppendText("Data Setting Loading...." & vbCrLf)
        Data_Setting()
        txbWindow.AppendText("Data Setting Loading Success" & vbCrLf)
        ComboBoxSetting()

        'ConfigIniLoad()
        loadLocalFile()

        txbWindow.AppendText("Config Data Loading Success" & vbCrLf)



        dgvID.Font = New Font("함초롱바탕", 11.25, FontStyle.Bold)
        'EquipSetting()
        'TestDBCon()
        'ComboBoxSetting()

        modeSaveSwitch = True
        txbBarcode.Focus()

    End Sub

    Private Sub ComboBoxSetting()
        comboBoxModel.Items.Clear()
        comboBoxModel.DisplayMember = "Key"
        comboBoxModel.ValueMember = "Value"

        DBCmd = "SELECT ModelName, ModelCode FROM " & ApplyModelInfoDB & " GROUP BY ModelCode"
        If DBQueryReader(DBCmd) Then
            Dim RowCount As Int16 = (sqlDataQuery.Length / 2) - 1
            Dim dataSetCount As Int32 = 0
            Dim ModelName As String
            Dim ModelCode As String

            For row = 0 To RowCount
                For col = 0 To 1
                    If col = 0 Then
                        ModelName = sqlDataQuery(dataSetCount)
                    ElseIf col = 1 Then
                        ModelCode = sqlDataQuery(dataSetCount)
                    End If
                    dataSetCount += 1
                Next
                comboBoxModel.Items.Add(New DictionaryEntry(ModelName, ModelCode))
            Next
        End If
        comboBoxModel.Text = "MAXIMUM"
    End Sub

    Private Function todayCountSet() As Boolean
        Dim NotChecked As Boolean = False
        NowDate = Format(Now, "yyyy-MM-dd")

        If formType = formTypeList.iqcHFRFEP Or formType = formTypeList.iqcRFEP Or formType = formTypeList.iqcHF Or formType = formTypeList.iqcHFEP Or formType = formTypeList.iqcEP Or formType = formTypeList.iqcRFEPMC Or formType = formTypeList.iqcLDM Or formType = formTypeList.iqcLDMEP Then
            DBCmd = "SELECT COUNT(NUMBER) FROM " & iqcCntTableNow & " WHERE IQC_Date = '" & NowDate & "'"
            If DBQueryScalar(DBCmd) = 0 Then
                DBCmd = "INSERT INTO " & iqcCntTableNow & " (IQC_Date) VALUES ('" & NowDate & "')"

                If DBCommand(DBCmd) = False Then
                    Return True
                End If
            End If
        Else
            DBCmd = "SELECT COUNT(NUMBER) FROM " & pd1CntTableNow & " WHERE PD1_Date = '" & NowDate & "'"
            If DBQueryScalar(DBCmd) = 0 Then
                DBCmd = "INSERT INTO " & pd1CntTableNow & " (PD1_Date) VALUES ('" & NowDate & "')"

                If DBCommand(DBCmd) = False Then
                    Return True
                End If
            End If
        End If

        If formType = formTypeList.prdRFEP Then
            DBCmd = "SELECT PD1_AltoCnt,PD1_AltoOkCnt,PD1_AltoNgCnt FROM " & pd1CntTableNow & " WHERE PD1_Date = '" & NowDate & "'"
        ElseIf formType = formTypeList.prdHF Then
            DBCmd = "SELECT PD1_MaxHFTotalCnt,PD1_MaxHFOkCnt,PD1_MaxHFNgCnt FROM " & pd1CntTableNow & " WHERE PD1_Date = '" & NowDate & "'"
        ElseIf formType = formTypeList.prdRFMCEP Then
            DBCmd = "SELECT PD1_MaxRFTotalCnt,PD1_MaxRFOkCnt,PD1_MaxRFNgCnt FROM " & pd1CntTableNow & " WHERE PD1_Date = '" & NowDate & "'"
        ElseIf formType = formTypeList.prdDsHF Then
            DBCmd = "SELECT PD1_DevTotalCnt,PD1_DevOkCnt,PD1_DevNgCnt FROM " & pd1CntTableNow & " WHERE PD1_Date = '" & NowDate & "'"
        ElseIf formType = formTypeList.iqcHFRFEP Then
            DBCmd = "SELECT IQC_MAXTotalCnt,IQC_MAXOkCnt,IQC_MAXNgCnt FROM " & iqcCntTableNow & " WHERE IQC_Date = '" & NowDate & "'"
        ElseIf formType = formTypeList.iqcLDM Or formType = formTypeList.iqcLDMEP Then
            DBCmd = "SELECT IQC_LDMTotalCnt,IQC_LDMOkCnt,IQC_LDMNgCnt FROM " & iqcCntTableNow & " WHERE IQC_Date = '" & NowDate & "'"
        ElseIf formType = formTypeList.iqcRFEP Or formType = formTypeList.iqcEP Or formType = formTypeList.iqcRFEPMC Then
            DBCmd = "SELECT IQC_ALTOTotalCnt,IQC_ALTOOkCnt,IQC_ALTONgCnt FROM " & iqcCntTableNow & " WHERE IQC_Date = '" & NowDate & "'"
        ElseIf formType = formTypeList.iqcHF Or formType = formTypeList.iqcHFEP Then
            DBCmd = "SELECT IQC_EFFECTTotalCnt,IQC_EFFECTOkCnt,IQC_EFFECTNgCnt FROM " & iqcCntTableNow & " WHERE IQC_Date = '" & NowDate & "'"
        ElseIf formType = formTypeList.prdLowHF Then ''저가형
            DBCmd = "SELECT PD1_LowPriceHFCnt,PD1_LowPriceHFOkCnt,PD1_LowPriceHFNgCnt FROM " & pd1CntTableNow & " WHERE PD1_Date = '" & NowDate & "'"
        ElseIf formType = formTypeList.prdHFLDMEP Or formType = formTypeList.prdEP Or formType = formTypeList.prdLDMEP Then ''저가형 ep
            DBCmd = "SELECT PD1_LowPriceEPCnt,PD1_LowPriceEPOkCnt,PD1_LowPriceEPNgCnt FROM " & pd1CntTableNow & " WHERE PD1_Date = '" & NowDate & "'"
        ElseIf formType = formTypeList.prdRFMC Or formType = formTypeList.prdVRLDM Then ''저가형 마름모, 세모rf
            DBCmd = "SELECT PD1_LowPriceRFCnt,PD1_LowPriceRFOKCnt,PD1_LowPriceRFNgCnt FROM " & pd1CntTableNow & " WHERE PD1_Date = '" & NowDate & "'"
        ElseIf formType = formTypeList.prdLDM Then ''세모 생산(ldm)
            DBCmd = "SELECT PD1_LowPriceLDMCnt,PD1_LowPriceLDMOkCnt,PD1_LowPriceLDMNgCnt FROM " & pd1CntTableNow & " WHERE PD1_Date = '" & NowDate & "'"
        Else
            NotChecked = True
        End If

        If (NotChecked = False) Then
            If DBQueryReader(DBCmd) Then

                txbDayCount.Text = sqlDataQuery(0)
                txbOkCount.Text = sqlDataQuery(1)
                txbNgCount.Text = sqlDataQuery(2)

                Return False
            Else
                Return True
            End If
        Else
            Return True
        End If

        Return False
    End Function

    Private Sub PositionSetting()
        MainSetting()
        TopPositonSet()
        BarcPositionSet()
        StatePosition()
        SituationPosition()
    End Sub

    Private Sub TestDBCon()
        DBCmd = "select database()"
        If DBQueryScalar(DBCmd) = "False" Then
            txbWindow.AppendText("DataBase Connection Error!!" & vbCrLf)
        End If

        txbWindow.AppendText("DataBase Connection Success!!" & vbCrLf)
    End Sub

    Private Sub btnReStart_Click(sender As Object, e As EventArgs) Handles btnReStart.Click
        StartSwitch = False

        loadLocalFile()
        Data_Setting()
        changeMode()
        txbBarcode.Focus()
    End Sub

    Private Sub EquipSetting()
        Dim ErrorSwitch As Boolean = False

        If EquipSet() Then
            txbWindow.AppendText("Scope Setting Fail!!" & vbCrLf)
            ErrorSwitch = True
        Else
            txbWindow.AppendText("Scope Setting Success!!" & vbCrLf)
        End If

        If SpecSet() Then
            txbWindow.AppendText("Spectrum Setting Fail!!" & vbCrLf)
            ErrorSwitch = True
        Else
            txbWindow.AppendText("Spectrum Setting Success!!" & vbCrLf)
        End If

        If ErrorSwitch = False Then
            StartSwitch = True
        End If

    End Sub

    Private Sub btnSerial_Click(sender As Object, e As EventArgs) Handles btnSerial.Click

        If btnSerial.Text = "스캔" Then
            If LoadComportName() Then
                btnSerial.Text = "연결"
            End If
        Else
            If cbbSerial.SelectedIndex = -1 Then
                MsgBox("포트를 선택하여 주십시오.", vbExclamation, Program_Name & Program_Version)
                Exit Sub
            End If

            If JigSerial.IsOpen Then
                JigSerial.Close()
            End If

            If cbbJgBaudRate.SelectedIndex = -1 Then
                cbbJgBaudRate.SelectedIndex = 1
            End If

            ParaComport = cbbSerial.SelectedItem
            OpenSerial(cbbJgBaudRate.SelectedItem)
            btnSerial.Text = "스캔"

            txbBarcode.Focus()
        End If
    End Sub

    Private Function LoadComportName() As Boolean
        Dim portname() As String
        Try
            cbbSerial.Items.Clear()
            portname = SerialPort.GetPortNames

            For i = 0 To portname.Length - 1
                cbbSerial.Items.Add(portname(i))
            Next
            cbbSerial.Text = "Select!"
            Return True

        Catch ex As Exception
            MsgBox("COM 포트 에러" & vbCrLf & "", vbOK + vbCritical, "DUALSONIC Cartridge Film Pressing")
            Return False
        End Try
    End Function

    Private Sub OpenSerial(baudNum As Integer)
        Try
            If JigSerial.IsOpen = False Then
                With JigSerial
                    .PortName = ParaComport
                    .BaudRate = baudNum
                    .DataBits = 8
                    .Parity = IO.Ports.Parity.None
                    .StopBits = IO.Ports.StopBits.One
                    .Handshake = IO.Ports.Handshake.None
                    .ReadTimeout = 0
                    .WriteTimeout = 1
                End With
                JigSerial.Open()
                txbWindow.AppendText("JIG Serial Port Open!!" & vbCrLf)

            Else
                MsgBox("열려있는 시리얼 포트가 존재합니다! 시리얼 포트를 끊고 다시 설정하여 주십시오." & vbCrLf & "", vbCritical, "DUALSONIC Cartridge Film Pressing")
            End If

        Catch ex As Exception
            MsgBox("COM 포트 에러" & vbCrLf & "", vbOK + vbCritical, "DUALSONIC Cartridge Film Pressing")
        End Try
    End Sub

    '' Spectrum Command------------------------------------------------------------------------------------------------------------------------------

    Private Function SpecConnectSelect(SpecID As String) As Int16

        If SpecID = "" Then
            Return -1
        End If

        Dim SpecConnect As String = Mid(SpecID, 1, InStr(1, SpecID, "0:") - 1)

        For i = ConnectList.USB To ConnectList.MAXConnect - 1
            If SpecConnect = ConnectName(i) Then
                Return i
            End If
        Next

        Return -1
    End Function

    Private Function SpecSet() As Boolean
        Dim ScopeData As String
        Dim ErrCheck As Boolean = False

        ConnectSelect = SpecConnectSelect(txbSpecID.Text)

        If ConnectSelect = -1 Then
            MsgBox("연결된 Spectrum 이 존재하지 않습니다. 연결을 확인하여 주십시오.", vbCritical)
            Return True
        End If
        ScopeData = SpecOpen(txbSpecID.Text, nudSpTimeout.Text)
        txbWindow.AppendText("Spectrum Data:" & ScopeData & vbCrLf)

        If ScopeData = "FAIL" Then
            MsgBox("Spectrum 연결에 실패했습니다.", vbCritical, Program_Name & Program_Version)
            Return True
        End If


        If ConnectSelect = ConnectList.USB Then

            ScopeData = RunCommand("*CLS")
            If ScopeData <> "PASS" Then
                txbWindow.AppendText("Spectrum Data initialization Error:" & ScopeData & vbCrLf)
                ErrCheck = True
            Else
                txbWindow.AppendText("Spectrum Data initialization:" & ScopeData & vbCrLf)
            End If

            ScopeData = RunCommand(":FREQuency:CENTer " & txbFrStep1.Text & "kHz")
            If ScopeData <> "PASS" Then
                txbWindow.AppendText("Spectrum Center Frequence Setting Error:" & ScopeData & vbCrLf)
                ErrCheck = True
            Else
                txbWindow.AppendText("Spectrum Center Frequence Setting :" & ScopeData & vbCrLf)
            End If

            ScopeData = RunCommand(":FREQuency:SPAN " & txbSpan.Text & "MHz")
            If ScopeData <> "PASS" Then
                txbWindow.AppendText("Spectrum Span Setting Error:" & ScopeData & vbCrLf)
                ErrCheck = True
            Else
                txbWindow.AppendText("Spectrum Span Setting :" & ScopeData & vbCrLf)
            End If

            ScopeData = RunCommand(":BANDwidth:AUTO OFF")
            If ScopeData <> "PASS" Then
                txbWindow.AppendText("Spectrum RBW Auto Setting Error:" & ScopeData & vbCrLf)
                ErrCheck = True
            Else
                txbWindow.AppendText("Spectrum RBW Auto Setting :" & ScopeData & vbCrLf)
            End If

            ScopeData = RunCommand(":BANDwidth " & txbRBW.Text & " MHz")
            If ScopeData <> "PASS" Then
                txbWindow.AppendText("Spectrum RBW Auto Setting Error:" & ScopeData & vbCrLf)
                ErrCheck = True
            Else
                txbWindow.AppendText("Spectrum RBW Auto Setting :" & ScopeData & vbCrLf)
            End If

            ScopeData = RunCommand(":BANDwidth:VIDeo:AUTO ON")
            If ScopeData <> "PASS" Then
                txbWindow.AppendText("Spectrum VBW Auto Setting Error:" & ScopeData & vbCrLf)
                ErrCheck = True
            Else
                txbWindow.AppendText("Spectrum VBW Auto Setting :" & ScopeData & vbCrLf)
            End If

            ScopeData = RunCommand(":DISPlay:WINDow:TRACe:Y:PDIVision 1")
            If ScopeData <> "PASS" Then
                txbWindow.AppendText("Spectrum Scale/Div Setting Error:" & ScopeData & vbCrLf)
                ErrCheck = True
            Else
                txbWindow.AppendText("Spectrum Scale/Div Setting :" & ScopeData & vbCrLf)
            End If

            ScopeData = RunCommand(":DISPlay:WINDow:TRACe:Y:SPACing LOGarithmic")
            If ScopeData <> "PASS" Then
                txbWindow.AppendText("Spectrum Scale Type Setting Error:" & ScopeData & vbCrLf)
                ErrCheck = True
            Else
                txbWindow.AppendText("Spectrum Scale Type Setting :" & ScopeData & vbCrLf)
            End If

            If ckbScopeZ.Checked = True Then
                ScopeData = RunCommand(":CORRection:IMPedance 50")
                If ScopeData <> "PASS" Then
                    txbWindow.AppendText("Spectrum Impedance Setting Error:" & ScopeData & vbCrLf)
                    ErrCheck = True
                Else
                    txbWindow.AppendText("Spectrum Impedance Setting :" & ScopeData & vbCrLf)
                End If
            End If

            'ScopeData = RunCommand(":POWer:ATTLimit:STATe ON")
            'If ScopeData <> "PASS" Then
            '    txbWindow.AppendText("Spectrum Att Limit Setting Error:" & ScopeData & vbCrLf)
            '    ErrCheck = True
            'Else
            '    txbWindow.AppendText("Spectrum Att Limit Setting :" & ScopeData & vbCrLf)
            'End If

            ScopeData = RunCommand(":UNIT:POWer W")
            If ScopeData <> "PASS" Then
                txbWindow.AppendText("Spectrum Y Axis Setting Error:" & ScopeData & vbCrLf)
                ErrCheck = True
            Else
                txbWindow.AppendText("Spectrum Y Axis Setting :" & ScopeData & vbCrLf)
            End If

            ScopeData = RunCommand(":POWer:ATTenuation:AUTO ON")
            If ScopeData <> "PASS" Then
                txbWindow.AppendText("Spectrum Attenuation Setting Error:" & ScopeData & vbCrLf)
                ErrCheck = True
            Else
                txbWindow.AppendText("Spectrum Attenuation Setting :" & ScopeData & vbCrLf)
            End If

            ScopeData = RunCommand(":POWer:ATTenuation 25dB")
            If ScopeData <> "PASS" Then
                txbWindow.AppendText("Spectrum Attenuation Number Setting Error:" & ScopeData & vbCrLf)
                ErrCheck = True
            Else
                txbWindow.AppendText("Spectrum Attenuation Number Setting :" & ScopeData & vbCrLf)
            End If

            ScopeData = RunCommand(":DISPlay:WINDow:TRACe:Y:RLEVel:OFFSet " & txbHFRefLev.Text & "")
            If ScopeData <> "PASS" Then
                txbWindow.AppendText("Spectrum Ref Level Setting Error:" & ScopeData & vbCrLf)
                ErrCheck = True
            Else
                txbWindow.AppendText("Spectrum Ref Level Setting :" & ScopeData & vbCrLf)
            End If

            ScopeData = RunCommand(":DISPlay:WINDow:TRACe:Y:RLEVel 28.18W")
            If ScopeData <> "PASS" Then
                txbWindow.AppendText("Spectrum Ref Level Setting Error:" & ScopeData & vbCrLf)
                ErrCheck = True
            Else
                txbWindow.AppendText("Spectrum Ref Level Setting :" & ScopeData & vbCrLf)
            End If

        ElseIf ConnectSelect = ConnectList.GPIB Then

        Else
            MsgBox("잘못된 연결 방식의 Spectrum 입니다. 확인하여 주십시오.", vbCritical)
            Return True
        End If




        If ErrCheck = True Then
            Return True
        End If

        Return False
    End Function

    Private Function CalMarker_Set() As Boolean
        Dim ScopeData As String = RunCommand(":CALCulate:MARKer1:MAXimum")
        If ScopeData <> "PASS" Then
            txbWindow.AppendText("Spectrum Trace1 CalCulate Marker1 Maximum Check Error:" & ScopeData & vbCrLf)
            Return False
        Else
            txbWindow.AppendText("Spectrum Trace1 CalCulate Marker1 Maximum Check : " & ScopeData & vbCrLf)
            Return True
        End If
    End Function

    Private Function SpecFreq_Set(cnt As Integer) As Boolean
        Dim specData As String
        'If formType = formTypeList.iqcLDM Or formType = formTypeList.prdLDM Then
        '    Dim flag As Int16
        '    If cnt = 0 Then
        '        flag = 3000
        '    ElseIf cnt = 1 Then
        '        flag = 10000
        '    Else
        '        'flag = 15000
        '        flag = 10000
        '    End If
        '    specData = RunCommand(":FREQuency:CENTer " & flag & "kHz")
        '    If specData <> "PASS" Then
        '        Return False
        '    Else
        '        Return True
        '    End If
        'End If

        specData = RunCommand(":FREQuency:CENTer " & HifuStep(cnt) & "kHz")
        If specData <> "PASS" Then
            Return False
        Else
            Return True
        End If
    End Function

    Private Function Clear_Set() As Boolean
        Dim ScopeData As String = RunCommand(":TRACe1:MODE WRITe")
        If ScopeData <> "PASS" Then
            Return False
        Else
            Return True
        End If
    End Function

    Private Function MaxHold_Set() As Boolean
        Dim ScopeData As String = RunCommand(":TRACe1:MODE MAXHold")
        If ScopeData <> "PASS" Then
            Return False
        Else
            Return True
        End If
    End Function


    Private Function TektronixReset() As Boolean
        Dim ScopeData As String = RunCommand(":TRACe1:AVERage:CLEar")
        If ScopeData <> "PASS" Then
            Return False
        Else
            Return True
        End If
    End Function

    ''' Scope Command------------------------------------------------------------------------------------------------------------------------------

    Private Function EquipSet() As Boolean
        Dim ScopeData As String
        Dim ErrCheck As Boolean = False
        ScopeData = ScopeOpen(txbScopeID.Text, nudScTimeout.Value)
        txbWindow.AppendText(vbCrLf & "Scope Data:" & ScopeData & vbCrLf)
        If ScopeData = "FAIL" Then
            MsgBox("Scope 연결에 실패했습니다.", vbCritical, Program_Name & Program_Version)
            Return True
        End If

        ScopeData = DoCommand("*RST")
        If ScopeData <> "PASS" Then
            txbWindow.AppendText("Scope Factory initialization Error:" & ScopeData & vbCrLf)
            ErrCheck = True
        Else
            txbWindow.AppendText("Scope Factory initialization:" & ScopeData & vbCrLf)
        End If

        ScopeData = DoCommand("*CLS")
        If ScopeData <> "PASS" Then
            txbWindow.AppendText("Scope Data initialization Error:" & ScopeData & vbCrLf)
            ErrCheck = True
        Else
            txbWindow.AppendText("Scope Data initialization:" & ScopeData & vbCrLf)
        End If

        ScopeData = DoCommand(":DISPlay:ANNotation 1")
        If ScopeData <> "PASS" Then
            txbWindow.AppendText("Scope Annotation use Error:" & ScopeData & vbCrLf)
            ErrCheck = True
        Else
            txbWindow.AppendText("Scope Annotation use:" & ScopeData & vbCrLf)
        End If

        ScopeData = DoCommand(":DISPlay:ANNotation:Text 'JION Meditech Function Tester'")
        If ScopeData <> "PASS" Then
            txbWindow.AppendText("Scope Annotation Text Error:" & ScopeData & vbCrLf)
            ErrCheck = True
        Else
            txbWindow.AppendText("Scope Annotation Text:" & ScopeData & vbCrLf)
        End If

        ScopeData = DoCommand(":DISPlay:ANNotation:COLor CH3")
        If ScopeData <> "PASS" Then
            txbWindow.AppendText("Scope Annotation Color Error:" & ScopeData & vbCrLf)
            ErrCheck = True
        Else
            txbWindow.AppendText("Scope Annotation Color:" & ScopeData & vbCrLf)
        End If

        ScopeData = DoCommand(":DISPlay:ANNotation:BACKground TRAN")
        If ScopeData <> "PASS" Then
            txbWindow.AppendText("Scope Annotation BackGround Error:" & ScopeData & vbCrLf)
            ErrCheck = True
        Else
            txbWindow.AppendText("Scope Annotation BackGround:" & ScopeData & vbCrLf)
        End If

        ScopeData = DoCommand(":CHANnel1:COUPling DC")
        If ScopeData <> "PASS" Then
            txbWindow.AppendText(vbCrLf & "Scope Coupling Set Error:" & ScopeData & vbCrLf)
            ErrCheck = True
        Else
            txbWindow.AppendText(vbCrLf & "Scope Coupling Set:" & ScopeData & vbCrLf)
        End If

        RF_Setting()  '' 50ms 단축을 위해 사용 - 안할시 170ms / 적용시 110ms

        If ErrCheck = True Then
            Return True
        End If

        Return False
    End Function



    Private Function RF_Setting() As Boolean
        Dim SetString As String

        If TrigSlope_Set("POS") = False Then
            Return True
        End If

        If rdbRFTrAuto.Checked = True Then
            SetString = "AUTO"
        Else
            SetString = "NORMal"
        End If

        If TriggerSet(SetString) = False Then
            Return True
        End If

        If TrigMod_Set() = False Then
            Return True
        End If

        If TrigLv_Set(nudRFTrgLv.Value) = False Then
            Return True
        End If

        If TimeScale_Set(CSng(txbRFtime.Text)) = False Then
            Return True
        End If

        If Delay_Select(Val(txbRFDelay.Text)) = False Then
            Return True
        End If

        If CH_Select(nudRFCh.Value) = False Then
            Return True
        End If

        If rdbRFUnitV.Checked = True Then
            SetString = "VOLT"
        Else
            SetString = "AMPere"
        End If

        If Unit_Select(SetString, nudRFCh.Value) = False Then
            Return True
        End If

        If Scale_Select(nudRFScale.Value, nudRFCh.Value) = False Then
            Return True
        End If

        If MeasClear() = False Then
            Return True
        End If

        If VRMS_Set(nudRFCh.Value) = False Then
            Return True
        End If

        If Freq_Set(nudRFCh.Value) = False Then
            Return True
        End If

        Return False
    End Function

    Private Function MC_Setting() As Boolean
        Dim SetString As String

        If TrigSlope_Set("POS") = False Then
            Return True
        End If

        If rdbMCTrAuto.Checked = True Then
            SetString = "AUTO"
        Else
            SetString = "NORMal"
        End If

        If TriggerSet(SetString) = False Then
            Return True
        End If

        If TrigLv_Set(nudMCFVTrgLv.Value) = False Then
            Return True
        End If

        If TrigMod_Set() = False Then
            Return True
        End If

        If CH_Select(nudMCCh.Value) = False Then
            Return True
        End If

        If rdbMCUnitV.Checked = True Then
            SetString = "VOLT"
        Else
            SetString = "AMPere"
        End If

        If Unit_Select(SetString, nudMCCh.Value) = False Then
            Return True
        End If

        If TimeScale_Set(Val(txbMCFVtime.Text)) = False Then
            Return True
        End If

        If Delay_Select(Val(txbMCFVDelay.Text)) = False Then
            Return True
        End If

        If Scale_Select(nudMCScale.Value, nudMCCh.Value) = False Then
            Return True
        End If

        If MeasClear() = False Then
            Return True
        End If

        If VPP_Set(nudMCCh.Value) = False Then
            Return True
        End If

        If Freq_Set(nudMCCh.Value) = False Then
            Return True
        End If

        If PWidth_Set(nudMCCh.Value) = False Then
            Return True
        End If

        If NWidth_Set(nudMCCh.Value) = False Then
            Return True
        End If

        Return False

    End Function

    Private Function EP_Setting(i As Int16) As Boolean
        Dim SetString As String

        DrainDeviceOutput()

        If TrigSlope_Set("POS") = False Then
            Return True
        End If

        If EpTrigerMode(i, 0).Checked = True Then
            SetString = "AUTO"
        Else
            SetString = "NORMal"
        End If

        If TriggerSet(SetString) = False Then
            Return True
        End If

        If TrigMod_Set() = False Then
            Return True
        End If

        If TrigLv_Set(EpTriggerLv(i).Value) = False Then
            Return True
        End If

        If TimeScale_Set(Val(EpTimeScale(i).Text)) = False Then
            Return True
        End If

        If Delay_Select(Val(EpDelay(i).Text)) = False Then
            Return True
        End If

        If CH_Select(EpChennal(i).Value) = False Then
            Return True
        End If

        If EpScaleMode(i, 0).Checked = True Then
            SetString = "VOLT"
        Else
            SetString = "AMPere"
        End If
        If Unit_Select(SetString, EpChennal(i).Value) = False Then
            Return True
        End If

        If Scale_Select(EpnudEPScale1(i).Value, EpChennal(i).Value) = False Then
            Return True
        End If

        If MeasClear() = False Then
            Return True
        End If

        If VPP_Set(EpChennal(i).Value) = False Then
            Return True
        End If

        If Freq_Set(EpChennal(i).Value) = False Then
            Return True
        End If

        If PWidth_Set(EpChennal(i).Value) = False Then
            Return True
        End If

        If NWidth_Set(EpChennal(i).Value) = False Then
            Return True
        End If

        Return False
    End Function

    Private Function TrigLv_Set(Tg_Lv As Single) As Boolean
        Dim ScopeData As String = DoCommand(":TRIGger:LEVel " & Tg_Lv)
        If ScopeData <> "PASS" Then
            txbWindow.AppendText("Scope Trigger Level Setting Error :" & ScopeData & vbCrLf)
            Return False
        Else
            txbWindow.AppendText("Scope Trigger Level Setting :" & ScopeData & vbCrLf)   '' TS_Value 값 출력되도록 변경해야 함
            Return True
        End If
    End Function


    Private Function TimeScale_Set(TS_Value As Single) As Boolean
        Dim ScopeData As String = DoCommand(":TIMebase:SCALe " & TS_Value)
        If ScopeData <> "PASS" Then
            txbWindow.AppendText("Scope Time Scale Setting Error :" & ScopeData & vbCrLf)
            Return False
        Else
            txbWindow.AppendText("Scope Time Scale Setting :" & ScopeData & vbCrLf)   '' TS_Value 값 출력되도록 변경해야 함
            Return True
        End If
    End Function

    Private Function TriggerSet(Trigger_Sweep As String) As Boolean
        Dim ScopeData As String = DoCommand(":TRIGger:SWEep " & Trigger_Sweep)
        If ScopeData <> "PASS" Then
            txbWindow.AppendText("Scope Trigger Mode Error:" & Trigger_Sweep & ScopeData & vbCrLf)
            Return False
        Else
            txbWindow.AppendText("Scope Trigger Mode Setting: " & Trigger_Sweep & "/ Success" & vbCrLf)
            Return True
        End If
    End Function

    Private Function CH_Select(chNum As Int16) As Boolean
        Dim ScopeData As String = DoCommand(":MEASure:SOURce CHANnel" & chNum)
        If ScopeData <> "PASS" Then
            txbWindow.AppendText("Scope Channel Select Error :" & ScopeData & vbCrLf)
            Return False
        Else
            txbWindow.AppendText("Scope Channel Select Setting : " & ScopeData & vbCrLf)
            Return True
        End If
    End Function

    Private Function Unit_Select(Scope_Unit As String, chNum As Int16) As Boolean
        Dim ScopeData As String = DoCommand(":CHANnel" & chNum & ":UNITs " & Scope_Unit)
        If ScopeData <> "PASS" Then
            txbWindow.AppendText("Scope Channel Units Error:" & ScopeData & vbCrLf)
            Return False
        Else
            txbWindow.AppendText("Scope Channel Units Setting: " & Scope_Unit & "/ Success" & vbCrLf)
            Return True
        End If
    End Function

    Private Function Scale_Select(ScaleValue As Single, chNum As Int16) As Boolean
        Dim ScopeData As String = DoCommand(":CHANnel" & chNum & ":SCALe " & ScaleValue)
        If ScopeData <> "PASS" Then
            txbWindow.AppendText("Scope Channel Scale Error:" & ScopeData & vbCrLf)
            Return False
        Else
            txbWindow.AppendText("Scope Channel Scale Setting: " & ScaleValue & "/" & ScopeData & vbCrLf)
            Return True
        End If
    End Function

    Private Function Delay_Select(DelayCount As String) As Boolean
        Dim ScopeData As String = DoCommand(":TIMebase:DELay " & DelayCount)
        If ScopeData <> "PASS" Then
            txbWindow.AppendText("Scope Time Delay Set Error:" & ScopeData & vbCrLf)
            Return False
        Else
            txbWindow.AppendText("Scope Time Delay Set Setting: " & DelayCount & "-" & ScopeData & "_Success" & vbCrLf)
            Return True
        End If
    End Function

    Private Function TrigMod_Set() As Boolean
        Dim ScopeData As String = DoCommand(":TRIGger:MODE EDGE")
        If ScopeData <> "PASS" Then
            txbWindow.AppendText("Scope Trigger Mode Set Error:" & ScopeData & vbCrLf)
            Return False
        Else
            txbWindow.AppendText("Scope Trigger Mode Set : Success" & vbCrLf)
            Return True
        End If
    End Function

    Private Function TrigSlope_Set(slope_Type As String) As Boolean
        Dim ScopeData As String = DoCommand(":TRIGger:EDGE:SLOPe " & slope_Type)
        If ScopeData <> "PASS" Then
            txbWindow.AppendText("Scope Trigger Edge Slope Set Error : " & ScopeData & vbCrLf)
            Return False
        Else
            txbWindow.AppendText("Scope Trigger Edge Slope Set: EDGE_Success" & vbCrLf)
            Return True
        End If
    End Function

    Private Function VPP_Set(chNum As Int16) As Boolean
        Dim ScopeData As String = DoCommand(":MEASure:VPP CHANnel" & chNum)
        If ScopeData <> "PASS" Then
            txbWindow.AppendText("Scope Measure VPP Set Error:" & ScopeData & vbCrLf)
            Return False
        Else
            txbWindow.AppendText("Scope  Measure VPP Set: Success" & vbCrLf)
            Return True
        End If
    End Function

    Private Function VRMS_Set(chNum As Int16) As Boolean
        Dim ScopeData As String = DoCommand(":MEASure:VRMS DISPlay,DC,CHANnel" & chNum)
        If ScopeData <> "PASS" Then
            txbWindow.AppendText("Scope Measure VRMS DC Set Error:" & ScopeData & vbCrLf)
            Return False
        Else
            txbWindow.AppendText("Scope  Measure VRMS DC Set: Success" & vbCrLf)
            Return True
        End If
    End Function

    Private Function Freq_Set(chNum As Int16) As Boolean
        Dim ScopeData As String = DoCommand(":MEASure:FREQuency CHANnel" & chNum)
        If ScopeData <> "PASS" Then
            txbWindow.AppendText("Scope Measure PWidth Set Error:" & ScopeData & vbCrLf)
            Return False
        Else
            txbWindow.AppendText("Scope  Measure PWidth Set: Success" & vbCrLf)
            Return True
        End If
    End Function

    Private Function MeasClear() As Boolean
        Dim ScopeData As String = DoCommand(":MEASure:CLEar")
        If ScopeData <> "PASS" Then
            txbWindow.AppendText("Scope Measure Clear Error:" & ScopeData & vbCrLf)
            Return False
        Else
            txbWindow.AppendText("Scope  Measure Clear Set: Success" & vbCrLf)
            Return True
        End If
    End Function

    Private Function PWidth_Set(chNum As Int16) As Boolean
        Dim ScopeData As String = DoCommand(":MEASure:PWIDth CHANnel" & chNum)
        If ScopeData <> "PASS" Then
            txbWindow.AppendText("Scope Measure PWidth Set Error:" & ScopeData & vbCrLf)
            Return False
        Else
            txbWindow.AppendText("Scope  Measure PWidth Set: Success" & vbCrLf)
            Return True
        End If
    End Function

    Private Function NWidth_Set(chNum As Int16) As Boolean
        Dim ScopeData As String = DoCommand(":MEASure:NWIDth CHANnel" & chNum)
        If ScopeData <> "PASS" Then
            txbWindow.AppendText("Scope Measure NWidth Set Error:" & ScopeData & vbCrLf)
            Return False
        Else
            txbWindow.AppendText("Scope  Measure NWidth Set: Success" & vbCrLf)
            Return True
        End If
    End Function

    '' JIG Command------------------------------------------------------------------------------------------------------------------------------

    Private Function SendData(SendMessage As String) As Boolean
        Try
            If retryPortOpen() Then
                JigSerial.DiscardInBuffer()
                JigSerial.DiscardOutBuffer()
                If JigSerial.BytesToRead Then
                    JigSerial.DiscardInBuffer()
                End If
                JigSerial.WriteTimeout = -1
                JigSerial.WriteLine(SendMessage)

                Return False
            Else
                MsgBox("통신 포트가 열리지 않았습니다.", vbCritical)
                Return True
            End If
        Catch ex As Exception
            Return True
        End Try
        Return True
    End Function

    Private Function PollingReceiveData(RdTimeout As Long) As String
        Try
            If retryPortOpen() Then
                rxMessage = ""
                JigSerial.ReadTimeout = RdTimeout
                rxMessage = JigSerial.ReadLine

                Return ParsingData()
            Else
                MsgBox("통신 포트가 열리지 않았습니다.", vbCritical)
                Return "close"
            End If
        Catch timeout As TimeoutException
            rxMessage = ""
            Return "timeout"
        Catch ex As Exception
            rxMessage = ""
            MsgBox(Err.Description, vbCritical)
            Return "pass"
        End Try
    End Function

    Private Function ParsingData() As String
        Dim cmdStr As String
        Dim cmdVal(0 To 8) As String
        Dim i As Integer

        Try
            cmdStr = "0"

            If rxMessage <> "" Then
                cmdMessage = ""

                If Mid(rxMessage, 1, 1) = "[" Then
                    cmdMessage = Mid(rxMessage, 2, Len(rxMessage))

                    cmdStr = Mid(cmdMessage, 1, (InStr(rxMessage, " ") - 2))
                    cmdMessage = Mid(rxMessage, InStr(rxMessage, " ") + 1, Len(cmdMessage))

                    For i = 1 To 7
                        If InStr(cmdMessage, ",") <> 0 Then
                            cmdVal(i) = Mid(cmdMessage, 1, InStr(cmdMessage, ",") - 1)
                            cmdMessage = Mid(cmdMessage, InStr(cmdMessage, ",") + 1, Len(cmdMessage))
                        ElseIf InStr(cmdMessage, "]") <> 0 Then
                            cmdVal(i) = Mid(cmdMessage, 1, InStr(cmdMessage, "]") - 1)
                            'cmdMessage = Mid(cmdMessage, InStr(cmdMessage, "]") + 1, Len(cmdMessage))
                        Else
                            Exit For
                        End If
                    Next i
                    rxMessage = ""

                    Select Case cmdStr

                        Case "deviceon"
                            cmdStr = cmdVal(1)
                            Return cmdStr
                        Case "entermft"
                            cmdStr = cmdVal(1)
                            Return cmdStr
                        Case "mftmode"
                            cmdStr = cmdVal(1)
                            Return cmdStr
                        Case "runmc"
                            cmdStr = cmdVal(1)
                            Return cmdStr
                        Case "runrf"
                            cmdStr = cmdVal(1)
                            Return cmdStr
                        Case "runep"
                            cmdStr = cmdVal(1)
                            Return cmdStr
                        Case "endmft"
                            cmdStr = cmdVal(1)
                            Return cmdStr
                        Case "runhifu"
                            cmdStr = cmdVal(1)
                            Return cmdStr
                        Case "dsfwver"
                            cmdStr = cmdVal(1)
                            Return cmdStr
                        Case "rdbattlv"
                            cmdStr = cmdVal(1)
                            Return cmdStr
                        Case "rdtemp"
                            cmdStr = cmdVal(1) & "," & cmdVal(2)
                            Return cmdStr
                        Case "resetinf"
                            cmdStr = cmdVal(1)
                            Return cmdStr
                        Case "settdsn"
                            cmdStr = cmdVal(1)
                            Return cmdStr
                        Case "settdcnf"
                            cmdStr = cmdVal(1) & "," & cmdVal(2)
                            Return cmdStr
                        Case "wrsconf1"
                            If ModelCode.Length = 2 Then    '16자리 시리얼번호
                                cmdStr = cmdVal(1) & "," & cmdVal(2) & "," & cmdVal(3) & "," & cmdVal(4) & "," & cmdVal(5) & "," & cmdVal(6) & "," & cmdVal(7)
                            Else                            '12자리 시리얼번호
                                cmdStr = cmdVal(1) & "," & cmdVal(2) & "," & cmdVal(3) & "," & cmdVal(4) & "," & cmdVal(5)
                            End If
                            Return cmdStr
                        Case "wrsconf9"
                            cmdStr = cmdVal(1) & "," & cmdVal(2) & "," & cmdVal(3) & "," & cmdVal(4) & "," & cmdVal(5) & "," & cmdVal(6) & "," & cmdVal(7)
                            Return cmdStr
                        Case "runled"
                            cmdStr = cmdVal(1)
                            Return cmdStr
                        Case "setmotor"
                            cmdStr = cmdVal(1) & "," & cmdVal(2) & "," & cmdVal(3) & "," & cmdVal(4) & "," & cmdVal(5)
                            Return cmdStr
                        Case "runbuzz"
                            cmdStr = cmdVal(1)
                            Return cmdStr
                        Case "runldm"
                            cmdStr = cmdVal(1)
                            Return cmdStr
                        Case "setldmsn"
                            cmdStr = cmdVal(1)
                            Return cmdStr
                        Case "setldmcnf"
                            cmdStr = cmdVal(1) & "," & cmdVal(2) & "," & cmdVal(3) & "," & cmdVal(4) & "," & cmdVal(5) & "," & cmdVal(6)
                            Return cmdStr
                    End Select
                End If
                rxMessage = ""
                Return True
            Else
                Return False
            End If

        Catch ex As Exception
            rxMessage = ""
            Return Err.Description
        End Try
    End Function

    Private Function DeviceOn() As Boolean
        Dim retVal As String

        tmpCmdMessage = "deviceon"
        cmdMessage = "[" & tmpCmdMessage & "]"

        If SendData(cmdMessage) Then
            Return True
        End If

        retVal = PollingReceiveData(JIGON_Timeout)

        If retVal = "success" Then
            Return False
        End If

        Return True
    End Function

    Private Function FirmVerCheck() As Boolean

        MeasureTimeFunc(MeasStart)
        MainTextChange("펌웨어 측정중")
        TestStep = TestList.Firmware
        TestData.Test_Firmware = String.Empty

        tmpCmdMessage = "dsfwver"
        cmdMessage = "[" & tmpCmdMessage & "]"

        If SendData(cmdMessage) Then
            txbVer.ForeColor = Color.Red
            txbWindow.AppendText("Product Firmware/ JIG Connecter ERROR!" & vbCrLf)
            Return True
        End If

        TestData.Test_Firmware = PollingReceiveData(JIGDT_Timeout)
        txbVer.Text = TestData.Test_Firmware
        txbVer.Refresh()

        If TestData.Test_Firmware = FWVerNow.Text Then
            txbVer.ForeColor = Color.Blue
            TestRunningState(testRunningList.Success, Color.Green)
            txbWindow.AppendText("Success Firmware version: " & TestData.Test_Firmware & "/Time(ms) : " & MeasureTimeFunc(MeasEnd) & vbCrLf)
            Return False
        Else
            txbVer.ForeColor = Color.Red
            TestRunningState(testRunningList.Fail, Color.Red)
            txbWindow.AppendText("Fail Firmware version: " & TestData.Test_Firmware & "/Time(ms) : " & MeasureTimeFunc(MeasEnd) & vbCrLf)
            Return True
        End If
    End Function

    Private Function TestMode_On(ModeNum As Int16) As Boolean
        Dim retVal As String

        tmpCmdMessage = "mftmode"
        cmdMessage = "[" & tmpCmdMessage & " " & ModeNum & "]"

        If SendData(cmdMessage) Then
            Return True
        End If

        retVal = PollingReceiveData(JIGDT_Timeout)

        If retVal = "sucess" Then
            Return False
        End If

        Return True
    End Function

    Private Function RunHifu(FreqUse As Boolean, Freq As Int16, Timeset As Int16) As Boolean
        Dim retVal As String

        tmpCmdMessage = "runhifu"
        cmdMessage = "[" & tmpCmdMessage & " " & Math.Abs(Val(FreqUse)) & "," & Freq & "," & Timeset & "]"

        If SendData(cmdMessage) Then
            Return True
        End If

        retVal = PollingReceiveData(JIGDT_Timeout)

        If retVal = "sucess" Then
            Return False
        End If

        Return True
    End Function
    Private Function RunLDM(count As Int16) As Boolean
        Dim retVal As String
        'Dim ldmMhzNum As Int16
        'If count = 0 Then
        '    ldmMhzNum = 3000
        'ElseIf count = 1 Then
        '    ldmMhzNum = 10000
        'Else
        '    'ldmMhzNum = 15000
        '    ldmMhzNum = 10000
        'End If

        'tmpCmdMessage = "runldm"
        tmpCmdMessage = "runhifu"
        'cmdMessage = "[" & tmpCmdMessage & " " & ldmMhzNum & "," & nudRFRun.Value & "]"
        cmdMessage = "[" & tmpCmdMessage & " " & 0 & "," & HifuStep(count) & "," & nudRFRun.Value & "]"

        If SendData(cmdMessage) Then
            Return True
        End If

        retVal = PollingReceiveData(JIGDT_Timeout)

        If retVal = "sucess" Then
            Return False
        End If

        Return True
    End Function

    Private Function RunRF(runType As Int16) As Boolean
        Dim retVal As String

        tmpCmdMessage = "runrf"
        cmdMessage = "[" & tmpCmdMessage & " " & runType & "," & nudRFRun.Value & "]"

        If SendData(cmdMessage) Then
            Return True
        End If

        retVal = PollingReceiveData(JIGDT_Timeout)

        If retVal = "sucess" Then
            Return False
        End If

        Return False
    End Function

    Private Function RunMC(runType As Int16, RunTime As Int16) As Boolean
        Dim retVal As String

        tmpCmdMessage = "runmc"
        cmdMessage = "[" & tmpCmdMessage & " " & runType & "," & RunTime & "]"

        If SendData(cmdMessage) Then
            Return True
        End If

        retVal = PollingReceiveData(JIGDT_Timeout)

        If retVal = "sucess" Then
            Return False
        End If

        Return True
    End Function

    Private Function RunEP(runType As Int32, i As Int16) As Boolean
        Dim retVal As String

        tmpCmdMessage = "runep"
        cmdMessage = "[" & tmpCmdMessage & " " & runType & "," & EpRunTime(i).Value & "]"

        If SendData(cmdMessage) Then
            Return True
        End If

        retVal = PollingReceiveData(JIGDT_Timeout)

        If retVal = "sucess" Then
            Return False
        End If

        Return True
    End Function

    Private Function RunTemp() As String
        Dim retVal As String

        tmpCmdMessage = "rdtemp"
        cmdMessage = "[" & tmpCmdMessage & "]"

        If SendData(cmdMessage) Then
            Return "conerror"
        End If

        retVal = PollingReceiveData(JIGDT_Timeout)

        Return retVal
    End Function

    Private Function RunBattery() As String
        Dim retVal As String

        tmpCmdMessage = "rdbattlv"
        cmdMessage = "[" & tmpCmdMessage & "]"

        If SendData(cmdMessage) Then
            Return "conerror"
        End If

        retVal = PollingReceiveData(JIGDT_Timeout)

        Return retVal
    End Function

    Private Function LEDRun(ColorNum As Int16, OnSet As Boolean) As Boolean
        Dim retVal As String

        tmpCmdMessage = "runled"
        cmdMessage = "[" & tmpCmdMessage & " " & ColorNum & "," & Abs(Val(OnSet)) & "]"

        If SendData(cmdMessage) Then
            Return True
        End If

        retVal = PollingReceiveData(JIGDT_Timeout)

        If retVal = "sucess" Then
            Return False
        End If

        Return True
    End Function

    Private Function SerialWrite(TDSN As String) As Boolean
        Dim retVal As String

        tmpCmdMessage = "settdsn"
        cmdMessage = "[" & tmpCmdMessage & " " & TDSN & "]"

        If SendData(cmdMessage) Then
            Return True
        End If

        retVal = PollingReceiveData(JIGDT_Timeout)
        txbWindow.AppendText("TD WRITE DATA :" & retVal & "" & vbCrLf)

        If retVal.ToLower = TDSN.ToLower Then
            Return False
        End If

        Return True
    End Function

    Private Function LDMSerialWrite(TDSN As String) As Boolean
        Dim retVal As String

        tmpCmdMessage = "setldmsn"
        cmdMessage = "[" & tmpCmdMessage & " " & TDSN & "]"

        If SendData(cmdMessage) Then
            Return True
        End If

        retVal = PollingReceiveData(JIGDT_Timeout)

        If retVal.ToLower = TDSN.ToLower Then
            Return False
        End If

        Return True
    End Function

    Private Function FreqWrite(Freq As Int16, Power As Int16) As Boolean
        Dim retVal As String

        tmpCmdMessage = "settdcnf"
        cmdMessage = "[" & tmpCmdMessage & " " & Freq & "," & Power & "]"

        If SendData(cmdMessage) Then
            Return True
        End If

        retVal = PollingReceiveData(JIGDT_Timeout)
        txbWindow.AppendText("TD FREQ & POWER WRITE DATA :" & retVal & vbCrLf)

        If retVal = Freq & "," & Power Then
            Return False
        End If

        Return True
    End Function

    Private Function LDMFreqWrite(Freq1 As Int16, Power1 As Int16, Freq2 As Int16, Power2 As Int16, Freq3 As Int16, Power3 As Int16) As Boolean
        Dim retVal As String

        tmpCmdMessage = "setldmcnf"
        cmdMessage = "[" & tmpCmdMessage & " " & Freq1 & "," & Freq2 & "," & Freq3 & "," & Power1 & "," & Power2 & "," & Power3 & "]"

        If SendData(cmdMessage) Then
            Return True
        End If

        retVal = PollingReceiveData(JIGDT_Timeout)
        Dim compareString = Freq1 & "," & Freq2 & "," & Freq3 & "," & Power1 & "," & Power2 & "," & Power3

        If retVal.Equals(compareString) Then
            Return False
        End If

        Return True
    End Function

    Private Function ResetData() As Boolean
        Dim retVal As String

        tmpCmdMessage = "resetinf"
        cmdMessage = "[" & tmpCmdMessage & "]"

        delay_run(300)

        If SendData(cmdMessage) Then
            Return True
        End If

        retVal = PollingReceiveData(JIGDT_Timeout)
        txbWindow.AppendText("PCB RESET RESPONSE :" & retVal & vbCrLf)

        If retVal = "ok" Then
            Return False
        End If

        txbWindow.AppendText(retVal & vbCrLf)

        Return True
    End Function

    Private Function EndTest() As Boolean
        Dim retVal As String

        tmpCmdMessage = "endmft"
        cmdMessage = "[" & tmpCmdMessage & "]"

        If SendData(cmdMessage) Then
            Return True
        End If

        retVal = PollingReceiveData(JIGDT_Timeout)

        If retVal = "ok" Then
            Return False
        End If

        Return True
    End Function

    ''----------------------------------------------------------------------------------------------------------------------------

    Private Function NonTDExist() As Boolean
        DBCmd = "SELECT COUNT(PV_SN) FROM " & NonTDTableNow & " WHERE PV_SN = '" & TestData.Test_Serial & "'"

        Dim sqlData As String = DBQueryScalar(DBCmd)

        If sqlData = "False" Then
            txbWindow.AppendText("DataBase TD DATA Connect Fail!!" & vbCrLf)
            TestError = False
            Return False
        End If

        If IsNumeric(sqlData) = False Then
            txbWindow.AppendText("DataBase TD DATA Numeric Fail!!" & vbCrLf)
            TestError = False
            Return False
        End If

        If Val(sqlData) > 0 Then  '' td 데이터가 db에 있을 경우
            Return False
        End If

        Return True
    End Function

    Private Function TDExist() As Boolean
        If formType = formTypeList.prdLDM Or formType = formTypeList.prdVRLDM Or formType = formTypeList.prdLDMEP Then
            TDTableNow = LDMTable
        Else
            TDTableNow = TDTable
        End If

        DBCmd = "SELECT COUNT(PV_SN) FROM " & TDTableNow & " WHERE PV_SN = '" & TestData.Test_Serial & "'"
        Dim sqlData As String = DBQueryScalar(DBCmd)

        If sqlData = "False" Then
            txbWindow.AppendText("DataBase TD DATA Connect Fail!!" & vbCrLf)
            TestError = False
            Return False
        End If

        If IsNumeric(sqlData) = False Then
            txbWindow.AppendText("DataBase TD DATA Numeric Fail!!" & vbCrLf)
            TestError = False
            Return False
        End If

        If Val(sqlData) < 1 Then
            txbWindow.AppendText("DataBase TD DATA Exist Fail!!" & vbCrLf)
            Return False
        End If

        txbWindow.AppendText("DataBase TD DATA Exist Success!!" & vbCrLf)

        Return True
    End Function

    Private Function LDMTestStepCheck() As Boolean
        DBCmd = "SELECT TestStep FROM " & ldmTableNow & "WHERE PV_SN ='" & TestData.Test_Serial & "'"
        Dim sqlData As String = DBQueryScalar(DBCmd)
        Dim teststep As Int16 = Val(sqlData)
        If Not (teststep = 23 Or 27 Or 21) Then
            Return True
        ElseIf teststep = 24 Or 28 Then
            txbWindow.AppendText("LDM 생산1 불합격 중 검사 진행 오류!" & vbCrLf)
            Return True
        End If

        Return False
    End Function

    Private Sub TDCompare()
        Dim tableName() As String
        Dim dupCount As Int16 = 0
        dupDATA = 0

        If formType = formTypeList.full Then
            ReDim tableName(1)

            tableName(0) = hfTableNow
            tableName(1) = rfTableNow

        ElseIf formType = formTypeList.prdHF Or formType = formTypeList.prdLowHF Then
            ReDim tableName(0)

            tableName(0) = hfTableNow

        ElseIf formType = formTypeList.prdRFMCEP Or formType = formTypeList.prdRFEP Or formType = formTypeList.prdHFLDMEP Or formType = formTypeList.prdEP Or formType = formTypeList.prdRFMC Then
            ReDim tableName(0)

            tableName(0) = rfTableNow
        ElseIf formType = formTypeList.prdLDM Then
            ReDim tableName(0)

            tableName(0) = ldmTestTableNow
        ElseIf formType = formTypeList.prdVRLDM Then
            ReDim tableName(0)

            tableName(0) = ldmRfTestTableNow
        ElseIf formType = formTypeList.prdLDMEP Then
            ReDim tableName(0)
            tableName(0) = ldmRfTestTableNow
        Else
            ReDim tableName(1)

            tableName(0) = hfTableNow
            tableName(1) = rfTableNow
        End If

        For i = 0 To tableName.Length - 1

            If formType = formTypeList.prdRFMC Then
                DBCmd = "SELECT IFNULL(RF_R1Vrms,0) FROM " & tableName(i) & " WHERE PV_SN = '" & TestData.Test_Serial & "'" & " AND DATE(TestDate) = CURDATE()"

            ElseIf formType = formTypeList.prdEP Then
                DBCmd = "SELECT IFNULL(EP_R1Vpp,0) FROM " & tableName(i) & " WHERE PV_SN = '" & TestData.Test_Serial & "'" & " AND DATE(TestDate) = CURDATE()"
            Else
                DBCmd = "SELECT COUNT(PV_SN) FROM " & tableName(i) & " WHERE PV_SN = '" & TestData.Test_Serial & "'" &
           " AND DATE(TestDate) = CURDATE()"
            End If

            Dim DupYn As Int16 = DBQueryScalar(DBCmd)

            If DupYn > 0 Then

                If tableName(i) = hfTableNow Then
                    dupCount = 1
                Else
                    dupCount = 2
                End If
            Else
                dupCount = 0
            End If

            dupDATA = dupDATA + dupCount

        Next

    End Sub

    Private Function StepSearch() As Boolean
        DBCmd = "SELECT TestStep FROM " & NonTDTableNow & " WHERE PV_SN = '" & TestData.Test_Serial & "'"
        TDDataSet(TD_Data.TestStep) = DBQueryScalar(DBCmd)

        If TDDataSet(TD_Data.TestStep) = "False" Then
            txbWindow.AppendText("DataBase TestStep DATA Load Fail!!" & vbCrLf)
            Return True
        End If

        Return False
    End Function

    Private Function TDTestNG() As Boolean

        DBCmd = "SELECT TestStep,QC_Date,QC_Frequency,QC_Grade,Ct_Power,Ct_Motor_Lv FROM " & TDTableNow & " WHERE PV_SN = '" & TestData.Test_Serial & "'"
        If DBQueryReader(DBCmd) Then
            For i = 0 To sqlDataQuery.Length - 1
                TDDataSet(i) = sqlDataQuery(i)
            Next

            txbWindow.AppendText("DataBase TD DATA Load Success!!" & vbCrLf)
            Return False
        End If

        txbWindow.AppendText("DataBase TD DATA Load Fail!!" & vbCrLf)
        Return True
    End Function

    Private Function LDMDBDataLoad() As Boolean

        DBCmd = "SELECT TestStep,PV_Date,PV_Frequency,PV_Frequency2,PV_Frequency3,Ct_Power,Ct_Power2,Ct_Power3 FROM " & ldmTableNow & " WHERE PV_SN = '" & TestData.Test_Serial & "'"
        If DBQueryReader(DBCmd) Then
            For i = 0 To sqlDataQuery.Length - 1
                LDM_DataSet(i) = sqlDataQuery(i)
            Next

            txbWindow.AppendText("DataBase TD DATA Load Success!!" & vbCrLf)
            Return False
        End If

        txbWindow.AppendText("DataBase TD DATA Load Fail!!" & vbCrLf)
        Return True
    End Function

    ''----------------------------------------------------------------------------------------------------------------------------

    Public Function HFTestRun() As Boolean

        If formType = formTypeList.iqcLDM Or formType = formTypeList.prdLDM Or formType = formTypeList.iqcLDMEP Then
            Return HFTestRunLDM()
        End If

        MeasureTimeFunc(MeasStart)
        MainTextChange("HIFU 측정중")
        TestStep = TestList.HIFU
        TestRunningState(testRunningList.Running, Color.Yellow)

        Dim ModCnt As Int16 = 1
        Dim ErrorCheck As Boolean = False
        Dim ForCnt As Int16 = 0
        Dim PlayCount As Int16 = nudHFCount.Value

        For cnt = 0 To HifuTest_Step.step3
            TestData.Test_HFData(cnt) = 0
            If cnt < HifuTest_Step.step3 Then
                TestData.Test_HFInterval(cnt) = 0
            End If
        Next

        If TestMode_On(ModCnt) Then
            txbWindow.AppendText("TestMode_HIFU Entrance Fail: " & ModCnt & vbCrLf)
            GoTo SettingFail
        End If

        For cnt = 0 To HifuTest_Step.step3
            ForCnt = cnt
            hfTestState(cnt)

            If ConnectSelect = ConnectList.GPIB Then
                If TektronixReset() = False Then
                    txbWindow.AppendText("Spectrum Reset Fail :" & cnt & vbCrLf)
                    GoTo ForSettingFail
                End If
            Else
                If SpecFreq_Set(cnt) = False Then
                    txbWindow.AppendText("Spectrum Center Frequence Fail :" & cnt & vbCrLf)
                    GoTo ForSettingFail
                End If

                If Clear_Set() = False Then
                    txbWindow.AppendText("Spectrum Trace Clear Fail : " & cnt & vbCrLf)
                    GoTo ForSettingFail
                End If

                If MaxHold_Set() = False Then
                    txbWindow.AppendText("Spectrum Trace MaxHold Fail : " & cnt & vbCrLf)
                    GoTo ForSettingFail
                End If

                txbWindow.AppendText("Run Hifu Spectrum setting : " & cnt & vbCrLf)
            End If

            delay_run(txbHFStDelay.Text)


            For i = 0 To PlayCount - 1
                If RunHifu(False, HifuStep(cnt), nudHFRun.Value) Then
                    txbWindow.AppendText("Run Hifu RESPONSE Fail : " & cnt & vbCrLf)
                    GoTo ForSettingFail
                End If

                txbWindow.AppendText("Run HIFU RESPONSE Success : " & cnt & vbCrLf)
                delay_run(nudHFwait.Value)
            Next


            If CalMarker_Set() = False Then
                txbWindow.AppendText("Spectrum CALCulate Marker Fail : " & cnt & vbCrLf)
                GoTo ForSettingFail
            End If

            Dim temp As Object = SpecQueryStr(":CALCulate:MARKer1:Y?")
            If Not Double.TryParse(temp, TestData.Test_HFData(cnt)) Then
                txbWindow.AppendText("잘못된 Y값 측정 : " & temp & vbCrLf)
                GoTo ForSettingFail
            End If

            TestData.Test_HFData(cnt) = Round(TestData.Test_HFData(cnt), 3)

            delay_run(nudHFwait.Value)

            If formType = formTypeList.iqcDsHF Or formType = formTypeList.prdDsHF Then

                If cnt Mod 2 = 0 Then
                    If TestData.Test_HFData(cnt) < Convert.ToDouble(Val(txbDSSub_Min.Text)) Or TestData.Test_HFData(cnt) > Convert.ToDouble(Val(txbDSSub_Max.Text)) Then
                        txbWindow.AppendText("Hifu MEASURE Fail " & cnt & ":  반환값: " & TestData.Test_HFData(cnt) & vbCrLf)
                        hfTestFail(cnt)
                        ErrorCheck = True
                    Else
                        txbWindow.AppendText("Hifu MEASURE SUCCESS" & cnt & ":  반환값: " & TestData.Test_HFData(cnt) & vbCrLf)
                        hfTestSuccess(cnt)
                    End If

                Else

                    If TestData.Test_HFData(cnt) < Convert.ToDouble(Val(txbDShfOut_stMin.Text)) Or TestData.Test_HFData(cnt) > Convert.ToDouble(Val(txbDShfOut_stMax.Text)) Then
                        txbWindow.AppendText("Hifu MEASURE Fail " & cnt & ":  반환값: " & TestData.Test_HFData(cnt) & vbCrLf)
                        hfTestFail(cnt)
                        ErrorCheck = True
                    Else
                        txbWindow.AppendText("Hifu MEASURE SUCCESS" & cnt & ":  반환값: " & TestData.Test_HFData(cnt) & vbCrLf)
                        hfTestSuccess(cnt)
                    End If

                End If

            Else

                If TestData.Test_HFData(cnt) < Convert.ToDouble(Val(HF_OutMIN.Text)) Or TestData.Test_HFData(cnt) > Convert.ToDouble(Val(HF_OutMax.Text)) Then
                    txbWindow.AppendText("Hifu MEASURE Fail " & cnt & ":  반환값: " & TestData.Test_HFData(cnt) & vbCrLf)
                    hfTestFail(cnt)
                    ErrorCheck = True
                Else
                    txbWindow.AppendText("Hifu MEASURE SUCCESS" & cnt & ":  반환값: " & TestData.Test_HFData(cnt) & vbCrLf)
                    hfTestSuccess(cnt)
                End If

            End If

        Next

        If formType = formTypeList.prdDsHF Or formType = formTypeList.iqcDsHF Then

            If TestData.Test_HFData(HifuTest_Step.Step1) > TestData.Test_HFData(HifuTest_Step.step3) Then
                TestData.Test_HFInterval(HifuTest_Diff.Step1_2) = TestData.Test_HFData(HifuTest_Step.Step1) - TestData.Test_HFData(HifuTest_Step.Step2)
                txbWindow.AppendText("Run Hifu Step1 - Step2 : " & TestData.Test_HFInterval(HifuTest_Diff.Step1_2) & vbCrLf)
                TestData.Test_HFInterval(HifuTest_Diff.Step2_3) = 0
                txbWindow.AppendText("Run Hifu Step2 - Step3 : " & TestData.Test_HFInterval(HifuTest_Diff.Step2_3) & vbCrLf)
            ElseIf TestData.Test_HFData(0) = TestData.Test_HFData(2) Then
                TestData.Test_HFInterval(HifuTest_Diff.Step1_2) = TestData.Test_HFData(HifuTest_Step.Step1) - TestData.Test_HFData(HifuTest_Step.Step2)
                txbWindow.AppendText("Run Hifu Step1 - Step2 : " & TestData.Test_HFInterval(HifuTest_Diff.Step1_2) & vbCrLf)
                TestData.Test_HFInterval(HifuTest_Diff.Step2_3) = 0
                txbWindow.AppendText("Run Hifu Step2 - Step3 : " & TestData.Test_HFInterval(HifuTest_Diff.Step2_3) & vbCrLf)
            Else
                TestData.Test_HFInterval(HifuTest_Diff.Step1_2) = 0
                txbWindow.AppendText("Run Hifu Step1 - Step2 : " & TestData.Test_HFInterval(HifuTest_Diff.Step1_2) & vbCrLf)
                TestData.Test_HFInterval(HifuTest_Diff.Step2_3) = TestData.Test_HFData(HifuTest_Step.Step2) - TestData.Test_HFData(HifuTest_Step.step3)
                txbWindow.AppendText("Run Hifu Step2 - Step3 : " & TestData.Test_HFInterval(HifuTest_Diff.Step2_3) & vbCrLf)
            End If

        Else

            TestData.Test_HFInterval(HifuTest_Diff.Step1_2) = TestData.Test_HFData(HifuTest_Step.Step1) - TestData.Test_HFData(HifuTest_Step.Step2)
            txbWindow.AppendText("Run Hifu Step1 - Step2 : " & TestData.Test_HFInterval(HifuTest_Diff.Step1_2) & vbCrLf)
            TestData.Test_HFInterval(HifuTest_Diff.Step2_3) = TestData.Test_HFData(HifuTest_Step.Step2) - TestData.Test_HFData(HifuTest_Step.step3)
            txbWindow.AppendText("Run Hifu Step2 - Step3 : " & TestData.Test_HFInterval(HifuTest_Diff.Step2_3) & vbCrLf)

        End If

        If Abs(TestData.Test_HFInterval(HifuTest_Diff.Step1_2)) >= Abs(Convert.ToDouble(HF_OutRange.Text)) Or Abs(TestData.Test_HFInterval(HifuTest_Diff.Step2_3)) >= Abs(Convert.ToDouble(HF_OutRange.Text)) Then
            txbWindow.AppendText("Run Hifu Range Value Fail" & vbCrLf)
            ErrorCheck = True
        End If

        If ErrorCheck = True Then
            TestRunningState(testRunningList.Fail, Color.Red)
            TestError = False
        Else
            TestRunningState(testRunningList.Success, Color.Green)
        End If

        txbWindow.AppendText("Hifu Test Full Time : " & MeasureTimeFunc(MeasEnd) & vbCrLf)
        Return False

        'ForSettingSucess:
        '        If TestData.Test_HFData(1) < Convert.ToDouble(Val(LDMt_WMin(2).Text)) Or TestData.Test_HFData(1) > Convert.ToDouble(Val(LDMt_WMax(2).Text)) Then
        '            txbWindow.AppendText("LDM MEASURE Fail " & 2 & ":  반환값: " & TestData.Test_HFData(1) & vbCrLf)
        '            hfTestFail(2)
        '            ErrorCheck = True
        '        Else
        '            txbWindow.AppendText("LDM MEASURE SUCCESS " & 2 & ":  반환값: " & TestData.Test_HFData(1) & vbCrLf)
        '            hfTestSuccess(2)
        '        End If
        '        Return False

ForSettingFail:
        hfTestFail(ForCnt)
        txbWindow.AppendText("measuring instrument response error!" & vbCrLf)
SettingFail:
        MeasureTimeFunc(MeasEnd)
        TestError = False
        TestRunningState(testRunningList.Fail, Color.Red)
        Return True

    End Function

    ''' <summary>iqcLDM / prdLDM / iqcLDMEP 전용: RunLDM 및 LDMt_WMin/Max 기준 판정, Interval 계산 없음</summary>
    Public Function HFTestRunLDM() As Boolean
        MeasureTimeFunc(MeasStart)
        MainTextChange("HIFU 측정중")
        TestStep = TestList.HIFU
        TestRunningState(testRunningList.Running, Color.Yellow)

        Dim ModCnt As Int16 = 1
        Dim ErrorCheck As Boolean = False
        Dim ForCnt As Int16 = 0
        Dim PlayCount As Int16 = nudHFCount.Value

        For cnt = 0 To HifuTest_Step.step3
            TestData.Test_HFData(cnt) = 0
            If cnt < HifuTest_Step.step3 Then
                TestData.Test_HFInterval(cnt) = 0
            End If
        Next

        If TestMode_On(ModCnt) Then
            txbWindow.AppendText("TestMode_HIFU Entrance Fail: " & ModCnt & vbCrLf)
            GoTo SettingFailLDM
        End If

        For cnt = 0 To HifuTest_Step.step3
            ForCnt = cnt
            hfTestState(cnt)

            If ConnectSelect = ConnectList.GPIB Then
                If TektronixReset() = False Then
                    txbWindow.AppendText("Spectrum Reset Fail :" & cnt & vbCrLf)
                    GoTo ForSettingFailLDM
                End If
            Else
                If SpecFreq_Set(cnt) = False Then
                    txbWindow.AppendText("Spectrum Center Frequence Fail :" & cnt & vbCrLf)
                    GoTo ForSettingFailLDM
                End If
                If Clear_Set() = False Then
                    txbWindow.AppendText("Spectrum Trace Clear Fail : " & cnt & vbCrLf)
                    GoTo ForSettingFailLDM
                End If
                If MaxHold_Set() = False Then
                    txbWindow.AppendText("Spectrum Trace MaxHold Fail : " & cnt & vbCrLf)
                    GoTo ForSettingFailLDM
                End If
                txbWindow.AppendText("Run Hifu Spectrum setting : " & cnt & vbCrLf)
            End If

            delay_run(txbHFStDelay.Text)

            For i = 0 To PlayCount - 1
                If RunLDM(cnt) Then
                    txbWindow.AppendText("Run LDM RESPONSE Fail : " & cnt & vbCrLf)
                    GoTo ForSettingFailLDM
                End If
                txbWindow.AppendText("Run LDM RESPONSE Success : " & cnt & vbCrLf)
                delay_run(nudHFwait.Value)
            Next

            If CalMarker_Set() = False Then
                txbWindow.AppendText("Spectrum CALCulate Marker Fail : " & cnt & vbCrLf)
                GoTo ForSettingFailLDM
            End If

            TestData.Test_HFData(cnt) = Round(Convert.ToDouble(SpecQueryStr(":CALCulate:MARKer1:Y?")), 3)
            delay_run(nudHFwait.Value)

            If TestData.Test_HFData(cnt) < Convert.ToDouble(Val(LDMt_WMin(cnt).Text)) Or TestData.Test_HFData(cnt) > Convert.ToDouble(Val(LDMt_WMax(cnt).Text)) Then
                txbWindow.AppendText("LDM MEASURE Fail " & cnt & ":  반환값: " & TestData.Test_HFData(cnt) & vbCrLf)
                hfTestFail(cnt)
                ErrorCheck = True
            Else
                txbWindow.AppendText("LDM MEASURE SUCCESS " & cnt & ":  반환값: " & TestData.Test_HFData(cnt) & vbCrLf)
                hfTestSuccess(cnt)
            End If
        Next

        If ErrorCheck = True Then
            TestRunningState(testRunningList.Fail, Color.Red)
            TestError = False
        Else
            TestRunningState(testRunningList.Success, Color.Green)
        End If

        txbWindow.AppendText("Hifu Test Full Time : " & MeasureTimeFunc(MeasEnd) & vbCrLf)
        Return False

ForSettingFailLDM:
        hfTestFail(ForCnt)
        txbWindow.AppendText("measuring instrument response error!" & vbCrLf)
SettingFailLDM:
        MeasureTimeFunc(MeasEnd)
        TestError = False
        TestRunningState(testRunningList.Fail, Color.Red)
        Return True
    End Function

    Private Sub hfTestState(cnt As Int16)
        If formType = formTypeList.prdHF Or formType = formTypeList.prdLowHF Or formType = formTypeList.prdHFLDMEP Or formType = formTypeList.prdEP Or formType = formTypeList.prdVRLDM Or formType = formTypeList.prdLDM Or formType = formTypeList.prdLDMEP Then
            If cnt = HifuTest_Step.Step1 Then
                txbHFtest1.Text = "측정중"
                txbHFtest1.BackColor = Color.Yellow
                txbHFtest1.Refresh()
            ElseIf cnt = HifuTest_Step.Step2 Then
                txbHFtest2.Text = "측정중"
                txbHFtest2.BackColor = Color.Yellow
                txbHFtest2.Refresh()
            Else
                txbHFtest3.Text = "측정중"
                txbHFtest3.BackColor = Color.Yellow
                txbHFtest3.Refresh()
            End If
        ElseIf formType = formTypeList.iqcDsHF Or formType = formTypeList.prdDsHF Then
            If cnt = HifuTest_Step.Step1 Then
                txbDSHifu_1.Text = "측정중"
                txbDSHifu_1.BackColor = Color.Yellow
                txbDSHifu_1.Refresh()
            ElseIf cnt = HifuTest_Step.Step2 Then
                txbDSHifu_2.Text = "측정중"
                txbDSHifu_2.BackColor = Color.Yellow
                txbDSHifu_2.Refresh()
            Else
                txbDSHifu_3.Text = "측정중"
                txbDSHifu_3.BackColor = Color.Yellow
                txbDSHifu_3.Refresh()
            End If
        Else
            If cnt = HifuTest_Step.Step1 Then
                txbIQCHF1.Text = "측정중"
                txbIQCHF1.BackColor = Color.Yellow
                txbIQCHF1.Refresh()
            ElseIf cnt = HifuTest_Step.Step2 Then
                txbIQCHF2.Text = "측정중"
                txbIQCHF2.BackColor = Color.Yellow
                txbIQCHF2.Refresh()
            Else
                txbIQCHF3.Text = "측정중"
                txbIQCHF3.BackColor = Color.Yellow
                txbIQCHF3.Refresh()
            End If
        End If
    End Sub

    Private Sub hfTestFail(cnt As Int16)
        If formType = formTypeList.prdHF Or formType = formTypeList.prdLowHF Or formType = formTypeList.prdHFLDMEP Or formType = formTypeList.prdEP Or formType = formTypeList.prdVRLDM Or formType = formTypeList.prdLDM Or formType = formTypeList.prdLDMEP Then
            If cnt = HifuTest_Step.Step1 Then
                txbHFtest1.Text = "FAIL"
                txbHFtest1.BackColor = Color.Red
                txbHFtest1.Refresh()
            ElseIf cnt = HifuTest_Step.Step2 Then
                txbHFtest2.Text = "FAIL"
                txbHFtest2.BackColor = Color.Red
                txbHFtest2.Refresh()
            Else
                txbHFtest3.Text = "FAIL"
                txbHFtest3.BackColor = Color.Red
                txbHFtest3.Refresh()
            End If
        ElseIf formType = formTypeList.iqcDsHF Or formType = formTypeList.prdDsHF Then
            If cnt = HifuTest_Step.Step1 Then
                txbDSHifu_1.Text = "FAIL"
                txbDSHifu_1.BackColor = Color.Red
                txbDSHifu_1.Refresh()
            ElseIf cnt = HifuTest_Step.Step2 Then
                txbDSHifu_2.Text = "FAIL"
                txbDSHifu_2.BackColor = Color.Red
                txbDSHifu_2.Refresh()
            Else
                txbDSHifu_3.Text = "FAIL"
                txbDSHifu_3.BackColor = Color.Red
                txbDSHifu_3.Refresh()
            End If
        Else
            If cnt = HifuTest_Step.Step1 Then
                txbIQCHF1.Text = "FAIL"
                txbIQCHF1.BackColor = Color.Red
                txbIQCHF1.Refresh()
            ElseIf cnt = HifuTest_Step.Step2 Then
                txbIQCHF2.Text = "FAIL"
                txbIQCHF2.BackColor = Color.Red
                txbIQCHF2.Refresh()
            Else
                txbIQCHF3.Text = "FAIL"
                txbIQCHF3.BackColor = Color.Red
                txbIQCHF3.Refresh()
            End If
        End If
    End Sub

    Private Sub hfTestSuccess(cnt As Int16)
        If formType = formTypeList.prdHF Or formType = formTypeList.prdLowHF Or formType = formTypeList.prdHFLDMEP Or formType = formTypeList.prdEP Or formType = formTypeList.prdVRLDM Or formType = formTypeList.prdLDM Or formType = formTypeList.prdLDMEP Then
            If cnt = HifuTest_Step.Step1 Then
                txbHFtest1.Text = "SUCCESS"
                txbHFtest1.BackColor = Color.Green
                txbHFtest1.Refresh()
            ElseIf cnt = HifuTest_Step.Step2 Then
                txbHFtest2.Text = "SUCCESS"
                txbHFtest2.BackColor = Color.Green
                txbHFtest2.Refresh()
            Else
                txbHFtest3.Text = "SUCCESS"
                txbHFtest3.BackColor = Color.Green
                txbHFtest3.Refresh()
            End If
        ElseIf formType = formTypeList.iqcDsHF Or formType = formTypeList.prdDsHF Then
            If cnt = HifuTest_Step.Step1 Then
                txbDSHifu_1.Text = "SUCCESS"
                txbDSHifu_1.BackColor = Color.Green
                txbDSHifu_1.Refresh()
            ElseIf cnt = HifuTest_Step.Step2 Then
                txbDSHifu_2.Text = "SUCCESS"
                txbDSHifu_2.BackColor = Color.Green
                txbDSHifu_2.Refresh()
            Else
                txbDSHifu_3.Text = "SUCCESS"
                txbDSHifu_3.BackColor = Color.Green
                txbDSHifu_3.Refresh()
            End If
        Else
            If cnt = HifuTest_Step.Step1 Then
                txbIQCHF1.Text = "SUCCESS"
                txbIQCHF1.BackColor = Color.Green
                txbIQCHF1.Refresh()
            ElseIf cnt = HifuTest_Step.Step2 Then
                txbIQCHF2.Text = "SUCCESS"
                txbIQCHF2.BackColor = Color.Green
                txbIQCHF2.Refresh()
            Else
                txbIQCHF3.Text = "SUCCESS"
                txbIQCHF3.BackColor = Color.Green
                txbIQCHF3.Refresh()
            End If
        End If
    End Sub

    Private Sub hfTestRetry(cnt As Int16)
        If formType = formTypeList.prdHF Or formType = formTypeList.prdLowHF Or formType = formTypeList.prdHFLDMEP Or formType = formTypeList.prdEP Or formType = formTypeList.prdVRLDM Or formType = formTypeList.prdLDM Or formType = formTypeList.prdLDMEP Then
            If cnt = HifuTest_Step.Step1 Then
                txbHFtest1.Text = "보 류"
                txbHFtest1.BackColor = Color.Gray
                txbHFtest1.Refresh()
            ElseIf cnt = HifuTest_Step.Step2 Then
                txbHFtest2.Text = "보 류"
                txbHFtest2.BackColor = Color.Gray
                txbHFtest2.Refresh()
            Else
                txbHFtest3.Text = "보 류"
                txbHFtest3.BackColor = Color.Gray
                txbHFtest3.Refresh()
            End If
        ElseIf formType = formTypeList.iqcDsHF Or formType = formTypeList.prdDsHF Then
            If cnt = HifuTest_Step.Step1 Then
                txbDSHifu_1.Text = "보 류"
                txbDSHifu_1.BackColor = Color.Gray
                txbDSHifu_1.Refresh()
            ElseIf cnt = HifuTest_Step.Step2 Then
                txbDSHifu_2.Text = "보 류"
                txbDSHifu_2.BackColor = Color.Gray
                txbDSHifu_2.Refresh()
            Else
                txbDSHifu_3.Text = "보 류"
                txbDSHifu_3.BackColor = Color.Gray
                txbDSHifu_3.Refresh()
            End If
        Else
            If cnt = HifuTest_Step.Step1 Then
                txbIQCHF1.Text = "보 류"
                txbIQCHF1.BackColor = Color.Gray
                txbIQCHF1.Refresh()
            ElseIf cnt = HifuTest_Step.Step2 Then
                txbIQCHF2.Text = "보 류"
                txbIQCHF2.BackColor = Color.Gray
                txbIQCHF2.Refresh()
            Else
                txbIQCHF3.Text = "보 류"
                txbIQCHF3.BackColor = Color.Gray
                txbIQCHF3.Refresh()
            End If
        End If
    End Sub


    Public Function RFTestRun() As Boolean
        Dim ForCnt, LdmCnt As Int16
        Dim ModCnt As Int16 = 2
        Dim chooseStatusFunc As Action(Of Int16)
        Dim chooseSuccessFunc As Action(Of Int16)
        Dim chooseFailFunc As Action(Of Int16)
        Try
            If formType = formTypeList.prdVRLDM Then
                chooseStatusFunc = AddressOf hfTestState
                chooseSuccessFunc = AddressOf hfTestSuccess
                chooseFailFunc = AddressOf hfTestFail
                TestStep = TestList.HIFU
                ModCnt = 1
            Else
                chooseStatusFunc = AddressOf rfTestState
                chooseSuccessFunc = AddressOf rfTestSuccess
                chooseFailFunc = AddressOf rfTestFail
                TestStep = TestList.RF
            End If

            MeasureTimeFunc(MeasStart)
            MainTextChange("RF 측정중")
            TestRunningState(testRunningList.Running, Color.Yellow)


            Dim ScopeData As String = String.Empty
            Dim ErrorCheck As Boolean = False

            For i = 0 To RFTest_Count
                TestData.Test_RFVRMS(i) = 0
                TestData.Test_RFFreq(i) = 0
            Next


            If RF_Setting() Then
                txbWindow.AppendText("RF Scope Setting Fail: " & ModCnt & vbCrLf)
                GoTo SettingFail
            End If

            If TestMode_On(ModCnt) Then
                txbWindow.AppendText("TestMode_RF Entrance Fail: " & ModCnt & vbCrLf)
                GoTo SettingFail
            End If

            For i = RFTest_Count To 0 Step -1
                ForCnt = i
                Dim freqCount As Int16 = 0

                If formType = formTypeList.iqcRFEP Or formType = formTypeList.prdRFEP Then
                    freqCount = (i * 2) + 2
                Else
                    freqCount = i
                End If

                If formType = formTypeList.prdVRLDM Then
                    chooseStatusFunc(LdmCnt)
                Else
                    chooseStatusFunc(i)
                End If

                DoCommand(":Single")

                If formType = formTypeList.prdVRLDM Then
                    If RunLDM(LdmCnt) Then
                        txbWindow.AppendText("LDM RESPONSE Fail : " & freqCount & vbCrLf)
                        GoTo forSettingFail
                    End If
                Else
                    If RunRF(freqCount) Then
                        txbWindow.AppendText("RF RESPONSE Fail : " & freqCount & vbCrLf)
                        GoTo forSettingFail
                    End If
                End If


                ScopeData = DoQueryString(":MEASure:VRMS? CHANnel" & nudRFCh.Value)

                If InStr(1, ScopeData.ToLower, "error") > 0 Then
                    txbWindow.AppendText("VRMS RESPONSE Fail : " & freqCount & vbCrLf)
                    GoTo forSettingFail
                End If

                TestData.Test_RFVRMS(i) = Convert.ToDouble(ScopeData).ToString("f12")

                ScopeData = DoQueryString(":MEASure:FREQuency? CHANnel" & nudRFCh.Value)

                If InStr(1, ScopeData.ToLower, "error") > 0 Then
                    txbWindow.AppendText("FREQ RESPONSE Fail : " & freqCount & vbCrLf)
                    GoTo forSettingFail
                End If

                TestData.Test_RFFreq(i) = Convert.ToDouble(ScopeData) / 1000000

                If formType = formTypeList.prdVRLDM Then
                    If (TestData.Test_RFVRMS(i) < CSng(LDMt_VRMSmin(i).Text) Or TestData.Test_RFVRMS(i) > CSng(LDMt_VRMSMax(i).Text)) Or Round(TestData.Test_RFFreq(i), 0) <> i + 1 Then
                        txbWindow.AppendText("Run LDM(RF) MEASURE FAIL" & LdmCnt & " : " & TestData.Test_RFVRMS(i) & vbCrLf)
                        chooseFailFunc(LdmCnt)
                        ErrorCheck = True
                    Else
                        txbWindow.AppendText("Run LDM(RF) MEASURE SUCCESS" & LdmCnt & " : " & TestData.Test_RFVRMS(i) & vbCrLf)
                        chooseSuccessFunc(LdmCnt)
                    End If

                Else
                    If (TestData.Test_RFVRMS(i) < CSng(RF_VRMSMin(i).Text) Or TestData.Test_RFVRMS(i) > CSng(RF_VRMSMax(i).Text)) Or Round(TestData.Test_RFFreq(i), 0) <> i + 1 Then
                        txbWindow.AppendText("Run RF MEASURE FAIL" & i & " : " & TestData.Test_RFVRMS(i) & vbCrLf)
                        chooseFailFunc(i)
                        ErrorCheck = True
                    Else
                        txbWindow.AppendText("Run RF MEASURE SUCCESS" & i & " : " & TestData.Test_RFVRMS(i) & vbCrLf)
                        chooseSuccessFunc(i)
                    End If
                End If

                LdmCnt += 1
            Next

            If ErrorCheck = True Then
                TestRunningState(testRunningList.Fail, Color.Red)
                TestError = False
            Else
                TestRunningState(testRunningList.Success, Color.Green)
            End If

            txbWindow.AppendText("RF Test Full Time : " & MeasureTimeFunc(MeasEnd) & vbCrLf)
            Return False

        Catch ex As Exception
            txbWindow.AppendText("Run RF Try Error : " & ex.Message & vbCrLf)
            GoTo SettingFail
        End Try

forSettingFail:
        If formType = formTypeList.prdVRLDM Then
            chooseFailFunc(LdmCnt)
        Else
            chooseFailFunc(ForCnt)
        End If

        txbWindow.AppendText("measuring instrument response error!" & vbCrLf)
SettingFail:
        txbWindow.AppendText("Run RF FAIL" & vbCrLf)
        TestRunningState(testRunningList.Fail, Color.Red)
        TestError = False
        MeasureTimeFunc(MeasEnd)
        Return True
    End Function

    Private Sub rfTestState(cnt As Int16)
        If formType = formTypeList.prdRFMCEP Or formType = formTypeList.prdRFMC Or formType = formTypeList.iqcRFEPMC Then
            If cnt = 2 Then
                txbRFtest1.Text = "측정중"
                txbRFtest1.BackColor = Color.Yellow
                txbRFtest1.Refresh()
            ElseIf cnt = 1 Then
                txbRFtest2.Text = "측정중"
                txbRFtest2.BackColor = Color.Yellow
                txbRFtest2.Refresh()
            Else
                txbRFtest3.Text = "측정중"
                txbRFtest3.BackColor = Color.Yellow
                txbRFtest3.Refresh()
            End If

        ElseIf formType = formTypeList.iqcRFEP Or formType = formTypeList.prdRFEP Or formType = formTypeList.company Then
            If cnt = 2 Then
                txbAlIQCRF_1.Text = "측정중"
                txbAlIQCRF_1.BackColor = Color.Yellow
                txbAlIQCRF_1.Refresh()
            ElseIf cnt = 1 Then
                txbAlIQCRF_2.Text = "측정중"
                txbAlIQCRF_2.BackColor = Color.Yellow
                txbAlIQCRF_2.Refresh()
            Else
                txbAlIQCRF_3.Text = "측정중"
                txbAlIQCRF_3.BackColor = Color.Yellow
                txbAlIQCRF_3.Refresh()
            End If

        Else
            If cnt = 2 Then
                txbIQCRF1.Text = "측정중"
                txbIQCRF1.BackColor = Color.Yellow
                txbIQCRF1.Refresh()
            ElseIf cnt = 1 Then
                txbIQCRF2.Text = "측정중"
                txbIQCRF2.BackColor = Color.Yellow
                txbIQCRF2.Refresh()
            Else
                txbIQCRF3.Text = "측정중"
                txbIQCRF3.BackColor = Color.Yellow
                txbIQCRF3.Refresh()
            End If
        End If
    End Sub

    Private Sub rfTestFail(cnt As Int16)
        If formType = formTypeList.prdRFMCEP Or formType = formTypeList.prdRFMC Or formType = formTypeList.iqcRFEPMC Then
            If cnt = 2 Then
                txbRFtest1.Text = "FAIL"
                txbRFtest1.BackColor = Color.Red
                txbRFtest1.Refresh()
            ElseIf cnt = 1 Then
                txbRFtest2.Text = "FAIL"
                txbRFtest2.BackColor = Color.Red
                txbRFtest2.Refresh()
            Else
                txbRFtest3.Text = "FAIL"
                txbRFtest3.BackColor = Color.Red
                txbRFtest3.Refresh()
            End If

        ElseIf formType = formTypeList.iqcRFEP Or formType = formTypeList.prdRFEP Or formType = formTypeList.company Then
            If cnt = 2 Then
                txbAlIQCRF_1.Text = "FAIL"
                txbAlIQCRF_1.BackColor = Color.Red
                txbAlIQCRF_1.Refresh()
            ElseIf cnt = 1 Then
                txbAlIQCRF_2.Text = "FAIL"
                txbAlIQCRF_2.BackColor = Color.Red
                txbAlIQCRF_2.Refresh()
            Else
                txbAlIQCRF_3.Text = "FAIL"
                txbAlIQCRF_3.BackColor = Color.Red
                txbAlIQCRF_3.Refresh()
            End If

        Else
            If cnt = 2 Then
                txbIQCRF1.Text = "FAIL"
                txbIQCRF1.BackColor = Color.Red
                txbIQCRF1.Refresh()
            ElseIf cnt = 1 Then
                txbIQCRF2.Text = "FAIL"
                txbIQCRF2.BackColor = Color.Red
                txbIQCRF2.Refresh()
            Else
                txbIQCRF3.Text = "FAIL"
                txbIQCRF3.BackColor = Color.Red
                txbIQCRF3.Refresh()
            End If
        End If
    End Sub

    Private Sub rfTestSuccess(cnt As Int16)
        If formType = formTypeList.prdRFMCEP Or formType = formTypeList.prdRFMC Or formType = formTypeList.iqcRFEPMC Then
            If cnt = 2 Then
                txbRFtest1.Text = "SUCCESS"
                txbRFtest1.BackColor = Color.Green
                txbRFtest1.Refresh()
            ElseIf cnt = 1 Then
                txbRFtest2.Text = "SUCCESS"
                txbRFtest2.BackColor = Color.Green
                txbRFtest2.Refresh()
            Else
                txbRFtest3.Text = "SUCCESS"
                txbRFtest3.BackColor = Color.Green
                txbRFtest3.Refresh()
            End If

        ElseIf formType = formTypeList.iqcRFEP Or formType = formTypeList.prdRFEP Or formType = formTypeList.company Then
            If cnt = 2 Then
                txbAlIQCRF_1.Text = "SUCCESS"
                txbAlIQCRF_1.BackColor = Color.Green
                txbAlIQCRF_1.Refresh()
            ElseIf cnt = 1 Then
                txbAlIQCRF_2.Text = "SUCCESS"
                txbAlIQCRF_2.BackColor = Color.Green
                txbAlIQCRF_2.Refresh()
            Else
                txbAlIQCRF_3.Text = "SUCCESS"
                txbAlIQCRF_3.BackColor = Color.Green
                txbAlIQCRF_3.Refresh()
            End If

        Else
            If cnt = 2 Then
                txbIQCRF1.Text = "SUCCESS"
                txbIQCRF1.BackColor = Color.Green
                txbIQCRF1.Refresh()
            ElseIf cnt = 1 Then
                txbIQCRF2.Text = "SUCCESS"
                txbIQCRF2.BackColor = Color.Green
                txbIQCRF2.Refresh()
            Else
                txbIQCRF3.Text = "SUCCESS"
                txbIQCRF3.BackColor = Color.Green
                txbIQCRF3.Refresh()
            End If
        End If
    End Sub

    Public Function MCTestRunSp() As Boolean

        Try
            MeasureTimeFunc(MeasStart)
            MainTextChange("미세전류 측정중")
            TestStep = TestList.MC
            TestRunningState(testRunningList.Running, Color.Yellow)

            Const ModCnt As Int16 = 3
            Dim ScopeData As String
            Dim CheckData As String = "NWIDth"
            Dim forCnt As Int16 = 0
            Dim ErrorCheck As Boolean = False

            For i = 0 To MCTest_Count
                TestData.Test_MCVpp(i) = 0
                TestData.Test_MCWidth(i) = 0
                TestData.Test_MCFreq(i) = 0
            Next

            If MC_Setting() Then
                txbWindow.AppendText("MC Scope Setting Fail" & vbCrLf)
                GoTo SettingFail
            End If

            If TestMode_On(ModCnt) Then
                txbWindow.AppendText("TestMode_MC Entrance Fail: " & ModCnt & vbCrLf)
                GoTo SettingFail
            End If

            For i = 0 To MCTest_Count
                forCnt = i

                If i = MCTest_Count Then

                    If Not TrigSlope_Set("NEG") Then
                        GoTo SettingFail
                    End If

                    CheckData = "PWIDth"
                End If

                DoCommand(":Single")

                If RunMC(i, nudMCFVRun.Value) Then
                    GoTo SettingFail
                End If

                ScopeData = DoQueryString(":MEASure:" & CheckData & "? CHANnel" & nudMCCh.Value)

                If InStr(1, ScopeData.ToLower, "error") > 0 Then
                    GoTo SettingFail
                End If
                TestData.Test_MCWidth(i) = Convert.ToDouble(ScopeData).ToString("f12") * 1000

                ScopeData = DoQueryString(":MEASure:VPP? CHANnel" & nudMCCh.Value)

                If InStr(1, ScopeData.ToLower, "error") > 0 Then
                    GoTo SettingFail
                End If

                TestData.Test_MCVpp(i) = Convert.ToDouble(ScopeData).ToString("f12")

                ScopeData = DoQueryString(":MEASure:FREQuency? CHANnel" & nudMCCh.Value)

                If InStr(1, ScopeData.ToLower, "error") > 0 Then
                    GoTo SettingFail
                End If

                TestData.Test_MCFreq(i) = Convert.ToDouble(ScopeData).ToString("f12")

                If (TestData.Test_MCVpp(i) < txbMCVPmin.Text Or TestData.Test_MCVpp(i) > txbMCVPmax.Text) Or (TestData.Test_MCFreq(i) < txbMCFrmin.Text Or TestData.Test_MCFreq(i) > txbMCFrmax.Text) Or ((TestData.Test_MCWidth(i) < txbMCDYmin.Text Or TestData.Test_MCWidth(i) > txbMCDYmax.Text)) Then
                    txbWindow.AppendText("Run MC FAIL" & i & " : " & TestData.Test_MCVpp(i) & "/" & TestData.Test_MCFreq(i) & "/" & TestData.Test_MCWidth(i) & vbCrLf)
                    ErrorCheck = True
                Else
                    txbWindow.AppendText("Run MC " & i & " : " & TestData.Test_MCVpp(i) & "/" & TestData.Test_MCFreq(i) & "/" & TestData.Test_MCWidth(i) & vbCrLf)
                End If

            Next

            If ErrorCheck = True Then
                TestRunningState(testRunningList.Fail, Color.Red)
                TestError = False
            Else
                TestRunningState(testRunningList.Success, Color.Green)
            End If

            txbWindow.AppendText("MC Test Full Time : " & MeasureTimeFunc(MeasEnd) & vbCrLf)

            Return False
        Catch ex As Exception
            txbWindow.AppendText("MC Try Error : " & ex.Message & vbCrLf)
            GoTo SettingFail
        End Try

SettingFail:
        txbWindow.AppendText("measuring instrument response error!" & vbCrLf)
        txbWindow.AppendText("Run MC FAIL" & vbCrLf)
        TestRunningState(testRunningList.Fail, Color.Red)
        TestError = False
        MeasureTimeFunc(MeasEnd)
        Return True

    End Function

    'Private Sub Jig_End()
    '    If EndTest() Then
    '        txbWindow.AppendText("JIG Serial Test End : FAIL" & vbCrLf)
    '        Exit Sub
    '    End If
    '    txbWindow.AppendText("JIG Serial Test End : Success" & vbCrLf)
    'End Sub

    Private Sub Jig_End()
        For retryCount As Integer = 0 To 2
            txbWindow.AppendText($"JIG 종료 시도 {retryCount + 1}/3" & vbCrLf)

            If EndTest() Then
                txbWindow.AppendText($"JIG Serial Test End : FAIL (시도 {retryCount + 1})" & vbCrLf)

                If retryCount < 2 Then
                    Threading.Thread.Sleep(1000)

                    If JigSerial IsNot Nothing AndAlso JigSerial.IsOpen Then
                        JigSerial.DiscardInBuffer()
                        JigSerial.DiscardOutBuffer()
                        Threading.Thread.Sleep(200)
                    End If
                    Continue For
                Else
                    txbWindow.AppendText("JIG 정상 종료 실패 - 강제 종료 실행" & vbCrLf)
                    ForceJigShutdown()
                    Exit Sub
                End If
            Else
                txbWindow.AppendText("JIG Serial Test End : Success" & vbCrLf)
                Exit For
            End If
        Next
    End Sub

    Private Sub ForceJigShutdown()
        Try
            txbWindow.AppendText("강제 JIG 종료 시작" & vbCrLf)

            If JigSerial IsNot Nothing AndAlso JigSerial.IsOpen Then
                Dim shutdownCommands() As String = {"[endmft]"}

                For Each cmd In shutdownCommands
                    Try
                        SendData(cmd)
                        Threading.Thread.Sleep(500)
                        txbWindow.AppendText($"강제 종료 명령 전송: {cmd}" & vbCrLf)
                    Catch

                    End Try
                Next

                Try
                    Dim portName As String = JigSerial.PortName
                    Dim baudRate As Integer = JigSerial.BaudRate

                    JigSerial.Close()
                    Threading.Thread.Sleep(1000)

                    JigSerial.PortName = portName
                    JigSerial.BaudRate = baudRate
                    JigSerial.Open()

                    txbWindow.AppendText("시리얼 포트 재연결 완료" & vbCrLf)
                Catch serialEx As Exception
                    txbWindow.AppendText($"시리얼 포트 재연결 실패: {serialEx.Message}" & vbCrLf)
                End Try
            End If

        Catch ex As Exception
            txbWindow.AppendText($"강제 종료 중 오류: {ex.Message}" & vbCrLf)
        End Try
    End Sub


    Public Function EPTestRun() As Boolean
        Dim ForCnt As Int16 = 0
        Dim chooseStatusFunc As Action(Of Int16)
        Dim chooseSuccessFunc As Action(Of Int16)
        Dim chooseFailFunc As Action(Of Int16)
        Dim chooseRetryFunc As Action(Of Int16)
        ResponseErrorCheck = False
        Try

            If formType = formTypeList.prdHFLDMEP Or formType = formTypeList.iqcEP Or formType = formTypeList.prdEP Or formType = formTypeList.prdLDMEP Then ''원/ 네모 / 마름모 /세모 플러스
                chooseStatusFunc = AddressOf hfTestState
                chooseSuccessFunc = AddressOf hfTestSuccess
                chooseFailFunc = AddressOf hfTestFail
                chooseRetryFunc = AddressOf hfTestRetry
                TestStep = TestList.HIFU
            Else
                chooseStatusFunc = AddressOf epTestState
                chooseSuccessFunc = AddressOf epTestSuccess
                chooseFailFunc = AddressOf epTestFail
                chooseRetryFunc = AddressOf epTestRetry
                TestStep = TestList.EP
            End If

            MeasureTimeFunc(MeasStart)
            MainTextChange("EP 측정중")

            TestRunningState(testRunningList.Running, Color.Yellow)

            Const ModCnt As Int16 = 4

            Dim ScopeData As String
            Dim ErrorCheck As Boolean = False

            ReDim TestData.Test_EPVpp(EPTest_Count)
            ReDim TestData.Test_EPFreq(EPTest_Count)
            ReDim TestData.Test_EPPWidth(EPTest_Count)
            ReDim TestData.Test_EPNWidth(EPTest_Count)

            For i = 0 To EPTest_Count
                TestData.Test_EPVpp(i) = 0
                TestData.Test_EPFreq(i) = 0
                TestData.Test_EPPWidth(i) = 0
                TestData.Test_EPNWidth(i) = 0
            Next


            If TestMode_On(ModCnt) Then
                txbWindow.AppendText("TestMode_EP Entrance Fail: " & ModCnt & vbCrLf)
                GoTo ForSettingFail
            End If

            For i = 0 To EPTest_Count

                If EP_Setting(i) Then
                    txbWindow.AppendText("EP Scope Setting Fail" & vbCrLf)
                    GoTo ForSettingFail
                End If

                ForCnt = i
                For n = 0 To nudEPRe.Value
                    chooseStatusFunc(i)

                    DoCommand(":Single")

                    If RunEP(Val(EPFreq(i).Text), i) Then
                        txbWindow.AppendText("Run EP RESPONSE Fail: " & i & vbCrLf)
                        If i = 0 And n = nudEPRe.Value Then
                            chooseRetryFunc(i)
                            GoTo ForSettingFail
                        ElseIf n = nudEPRe.Value Then
                            chooseRetryFunc(i)
                        End If
                        Continue For
                    End If

                    ScopeData = DoQueryString(":MEASure:VPP? CHANnel" & EpChennal(i).Value)

                    If InStr(1, ScopeData.ToLower, "error") > 0 Then
                        txbWindow.AppendText("EP VPP RESPONSE FAIL :" & i & vbCrLf)
                        If i = 0 And n = nudEPRe.Value Then
                            chooseRetryFunc(i)
                            GoTo ForSettingFail
                        ElseIf n = nudEPRe.Value Then
                            chooseRetryFunc(i)
                        End If
                        Continue For
                    End If

                    TestData.Test_EPVpp(i) = Convert.ToDouble(ScopeData).ToString("f12")

                    If TestData.Test_EPVpp(i) < EPVppMin.Text Or TestData.Test_EPVpp(i) > EPVppMax.Text Then
                        txbWindow.AppendText("EP VPP MEASURE FAIL:" & i & "(re:" & n & ") / 측정값: " & TestData.Test_EPVpp(i) & vbCrLf)

                        If n = nudEPRe.Value Then
                            chooseFailFunc(i)
                            ErrorCheck = True
                        End If

                    Else
                        ScopeData = DoQueryString(":MEASure:FREQuency? CHANnel" & EpChennal(i).Value)

                        If InStr(1, ScopeData.ToLower, "error") > 0 Then
                            txbWindow.AppendText("EP PREQ RESPONSE FAIL :" & i & vbCrLf)
                            If i = 0 And n = nudEPRe.Value Then
                                chooseRetryFunc(i)
                                GoTo ForSettingFail
                            ElseIf n = nudEPRe.Value Then
                                chooseRetryFunc(i)
                            End If
                            Continue For
                        End If

                        TestData.Test_EPFreq(i) = Convert.ToDouble(ScopeData).ToString("f12") / 10000

                        If Round(TestData.Test_EPFreq(i), 0) <> Round((CSng(EPFreq(i).Text) / 10000), 0) Then
                            txbWindow.AppendText("EP FREQ MEASURE FAIL:" & i & "(re:" & n & ") / 측정값: " & TestData.Test_EPFreq(i) & vbCrLf)

                            If n = nudEPRe.Value Then
                                chooseFailFunc(i)
                                ErrorCheck = True
                            End If

                        Else

                            ScopeData = DoQueryString(":MEASure:NWIDth? CHANnel" & EpChennal(i).Value)

                            If InStr(1, ScopeData.ToLower, "error") > 0 Then
                                txbWindow.AppendText("EP NWIDth RESPONSE FAIL :" & i & vbCrLf)
                                If i = 0 And n = nudEPRe.Value Then
                                    chooseRetryFunc(i)
                                    GoTo ForSettingFail
                                ElseIf n = nudEPRe.Value Then
                                    chooseRetryFunc(i)
                                End If
                                Continue For
                            End If

                            TestData.Test_EPNWidth(i) = Convert.ToDouble(ScopeData).ToString("f12") * 1000000

                            ScopeData = DoQueryString(":MEASure:PWIDth? CHANnel" & EpChennal(i).Value)

                            If InStr(1, ScopeData.ToLower, "error") > 0 Then
                                txbWindow.AppendText("EP PWIDth RESPONSE FAIL :" & i & vbCrLf)
                                If i = 0 And n = nudEPRe.Value Then
                                    chooseRetryFunc(i)
                                    GoTo ForSettingFail
                                ElseIf n = nudEPRe.Value Then
                                    chooseRetryFunc(i)
                                End If
                                Continue For
                            End If

                            TestData.Test_EPPWidth(i) = Convert.ToDouble(ScopeData).ToString("f12") * 1000000

                            If Abs(TestData.Test_EPPWidth(i) - TestData.Test_EPNWidth(i)) < Val(EPWidthMin(i).Text) Or Abs(TestData.Test_EPPWidth(i) - TestData.Test_EPNWidth(i)) > Val(EPWidthMax(i).Text) Then

                                txbWindow.AppendText("EP WIDTH MEASURE FAIL" & i & "(re:" & n & ") / 측정값: " & TestData.Test_EPNWidth(i) & "/" & TestData.Test_EPPWidth(i) & vbCrLf)

                                If n = nudEPRe.Value Then
                                    chooseFailFunc(i)
                                    ErrorCheck = True
                                End If

                            Else
                                txbWindow.AppendText("EP MEASURE SUCCESS " & i & " : " & TestData.Test_EPVpp(i) & "/" & TestData.Test_EPFreq(i) & "/" & TestData.Test_EPNWidth(i) & "/" & TestData.Test_EPPWidth(i) & vbCrLf)
                                chooseSuccessFunc(i)
                                Exit For
                            End If

                        End If

                    End If

                Next ''재측정

            Next

            If ErrorCheck = True Then
                TestRunningState(testRunningList.Fail, Color.Red)
                TestError = False
            Else ErrorCheck = False
                TestRunningState(testRunningList.Success, Color.Green)
            End If

            txbWindow.AppendText("EP Test Full Time : " & MeasureTimeFunc(MeasEnd) & vbCrLf)
            Return False

        Catch ex As Exception
            txbWindow.AppendText("EP Try Error : " & ex.Message & " : " & vbCrLf)
            GoTo ForSettingFail
        End Try

ForSettingFail:
        ResponseErrorCheck = True
        txbWindow.AppendText("measuring instrument response error!" & vbCrLf)
        txbWindow.AppendText("Run EP FAIL" & vbCrLf)
        TestRunningState(testRunningList.Retry, Color.Gray)
        MeasureTimeFunc(MeasEnd)
        Return True

    End Function

    Private Sub epTestState(cnt As Int16)
        If formType = formTypeList.prdRFMCEP Or formType = formTypeList.iqcRFEPMC Then
            If cnt = 0 Then
                txbEPtest1.Text = "진행중"
                txbEPtest1.BackColor = Color.Yellow
                txbEPtest1.Refresh()
            ElseIf cnt = 1 Then
                txbEPtest2.Text = "진행중"
                txbEPtest2.BackColor = Color.Yellow
                txbEPtest2.Refresh()
            Else
                txbEPtest3.Text = "진행중"
                txbEPtest3.BackColor = Color.Yellow
                txbEPtest3.Refresh()
            End If


        ElseIf formType = formTypeList.prdRFEP Or formType = formTypeList.iqcRFEP Or formType = formTypeList.company Then
            If cnt = 0 Then
                txbAlIQCEP_1.Text = "진행중"
                txbAlIQCEP_1.BackColor = Color.Yellow
                txbAlIQCEP_1.Refresh()
            ElseIf cnt = 1 Then
                txbAlIQCEP_2.Text = "진행중"
                txbAlIQCEP_2.BackColor = Color.Yellow
                txbAlIQCEP_2.Refresh()
            Else
                txbAlIQCEP_3.Text = "진행중"
                txbAlIQCEP_3.BackColor = Color.Yellow
                txbAlIQCEP_3.Refresh()
            End If
        Else
            If cnt = 0 Then
                txbIQCEP1.Text = "진행중"
                txbIQCEP1.BackColor = Color.Yellow
                txbIQCEP1.Refresh()
            ElseIf cnt = 1 Then
                txbIQCEP2.Text = "진행중"
                txbIQCEP2.BackColor = Color.Yellow
                txbIQCEP2.Refresh()
            Else
                txbIQCEP3.Text = "진행중"
                txbIQCEP3.BackColor = Color.Yellow
                txbIQCEP3.Refresh()
            End If
        End If
    End Sub

    Private Sub epTestFail(cnt As Int16)
        If formType = formTypeList.prdRFMCEP Or formType = formTypeList.iqcRFEPMC Then
            If cnt = 0 Then
                txbEPtest1.Text = "FAIL"
                txbEPtest1.BackColor = Color.Red
                txbEPtest1.Refresh()
            ElseIf cnt = 1 Then
                txbEPtest2.Text = "FAIL"
                txbEPtest2.BackColor = Color.Red
                txbEPtest2.Refresh()
            Else
                txbEPtest3.Text = "FAIL"
                txbEPtest3.BackColor = Color.Red
                txbEPtest3.Refresh()
            End If

        ElseIf formType = formTypeList.prdRFEP Or formType = formTypeList.iqcRFEP Or formType = formTypeList.company Then
            If cnt = 0 Then
                txbAlIQCEP_1.Text = "FAIL"
                txbAlIQCEP_1.BackColor = Color.Red
                txbAlIQCEP_1.Refresh()
            ElseIf cnt = 1 Then
                txbAlIQCEP_2.Text = "FAIL"
                txbAlIQCEP_2.BackColor = Color.Red
                txbAlIQCEP_2.Refresh()
            Else
                txbAlIQCEP_3.Text = "FAIL"
                txbAlIQCEP_3.BackColor = Color.Red
                txbAlIQCEP_3.Refresh()
            End If

        Else
            If cnt = 0 Then
                txbIQCEP1.Text = "FAIL"
                txbIQCEP1.BackColor = Color.Red
                txbIQCEP1.Refresh()
            ElseIf cnt = 1 Then
                txbIQCEP2.Text = "FAIL"
                txbIQCEP2.BackColor = Color.Red
                txbIQCEP2.Refresh()
            Else
                txbIQCEP3.Text = "FAIL"
                txbIQCEP3.BackColor = Color.Red
                txbIQCEP3.Refresh()
            End If
        End If
    End Sub

    Private Sub epTestSuccess(cnt As Int16)
        If formType = formTypeList.prdRFMCEP Or formType = formTypeList.iqcRFEPMC Then
            If cnt = 0 Then
                txbEPtest1.Text = "SUCCESS"
                txbEPtest1.BackColor = Color.Green
                txbEPtest1.Refresh()
            ElseIf cnt = 1 Then
                txbEPtest2.Text = "SUCCESS"
                txbEPtest2.BackColor = Color.Green
                txbEPtest2.Refresh()
            Else
                txbEPtest3.Text = "SUCCESS"
                txbEPtest3.BackColor = Color.Green
                txbEPtest3.Refresh()
            End If

        ElseIf formType = formTypeList.prdRFEP Or formType = formTypeList.iqcRFEP Or formType = formTypeList.company Then
            If cnt = 0 Then
                txbAlIQCEP_1.Text = "SUCCESS"
                txbAlIQCEP_1.BackColor = Color.Green
                txbAlIQCEP_1.Refresh()
            ElseIf cnt = 1 Then
                txbAlIQCEP_2.Text = "SUCCESS"
                txbAlIQCEP_2.BackColor = Color.Green
                txbAlIQCEP_2.Refresh()
            Else
                txbAlIQCEP_3.Text = "SUCCESS"
                txbAlIQCEP_3.BackColor = Color.Green
                txbAlIQCEP_3.Refresh()
            End If

        Else
            If cnt = 0 Then
                txbIQCEP1.Text = "SUCCESS"
                txbIQCEP1.BackColor = Color.Green
                txbIQCEP1.Refresh()
            ElseIf cnt = 1 Then
                txbIQCEP2.Text = "SUCCESS"
                txbIQCEP2.BackColor = Color.Green
                txbIQCEP2.Refresh()
            Else
                txbIQCEP3.Text = "SUCCESS"
                txbIQCEP3.BackColor = Color.Green
                txbIQCEP3.Refresh()
            End If
        End If
    End Sub
    Private Sub epTestRetry(cnt As Int16)
        If formType = formTypeList.prdRFMCEP Or formType = formTypeList.iqcRFEPMC Then
            If cnt = 0 Then
                txbEPtest1.Text = "보 류"
                txbEPtest1.BackColor = Color.Gray
                txbEPtest1.Refresh()
            ElseIf cnt = 1 Then
                txbEPtest2.Text = "보 류"
                txbEPtest2.BackColor = Color.Gray
                txbEPtest2.Refresh()
            Else
                txbEPtest3.Text = "보 류"
                txbEPtest3.BackColor = Color.Gray
                txbEPtest3.Refresh()
            End If

        ElseIf formType = formTypeList.prdRFEP Or formType = formTypeList.iqcRFEP Or formType = formTypeList.company Then
            If cnt = 0 Then
                txbAlIQCEP_1.Text = "보 류"
                txbAlIQCEP_1.BackColor = Color.Gray
                txbAlIQCEP_1.Refresh()
            ElseIf cnt = 1 Then
                txbAlIQCEP_2.Text = "보 류"
                txbAlIQCEP_2.BackColor = Color.Gray
                txbAlIQCEP_2.Refresh()
            Else
                txbAlIQCEP_3.Text = "보 류"
                txbAlIQCEP_3.BackColor = Color.Gray
                txbAlIQCEP_3.Refresh()
            End If

        Else
            If cnt = 0 Then
                txbIQCEP1.Text = "보 류"
                txbIQCEP1.BackColor = Color.Gray
                txbIQCEP1.Refresh()
            ElseIf cnt = 1 Then
                txbIQCEP2.Text = "보 류"
                txbIQCEP2.BackColor = Color.Gray
                txbIQCEP2.Refresh()
            Else
                txbIQCEP3.Text = "보 류"
                txbIQCEP3.BackColor = Color.Gray
                txbIQCEP3.Refresh()
            End If
        End If
    End Sub

    Private Function JigRun_On() As Boolean
        Try
            MeasureTimeFunc(MeasStart)
            TestStep = TestList.Start
            MainTextChange("전원 ON")

            If TestMode_On(0) = False Then
                Jig_End()
            End If

            If DeviceOn() Then
                txbWindow.AppendText("JIG Product Device ON : FAIL" & vbCrLf)
                MsgBox("제품과의 연결이 올바르지 않습니다. 연결 상태를 확인하여 주십시오.", vbCritical, Program_Name & Program_Version)
                MeasureTimeFunc(MeasEnd)
                Return True
            End If

            delay_run(JIGON_Delay)

            txbWindow.AppendText("JIG On Full Time(ms) : " & MeasureTimeFunc(MeasEnd) & vbCrLf)

            Return False
        Catch ex As Exception
            txbWindow.AppendText("JIG Product Device ON : FAIL" & vbCrLf)
            MsgBox("JIG ON_오류 발생 ! : " & ex.Message & vbCritical)
            Return True
        End Try
    End Function

    Private Function BatteryTest() As Boolean
        MeasureTimeFunc(MeasStart)
        MainTextChange("배터리 측정중")
        TestStep = TestList.Battey
        TestRunningState(testRunningList.Running, Color.Yellow)
        TestData.Test_Battery = 0

        Try
            Dim ResData As String = RunBattery()

            If ResData = "conerror" Then
                txbWindow.AppendText("JIG Serial Battery Test Connect Error " & vbCrLf)
                TestRunningState(testRunningList.Fail, Color.Red)
                MeasureTimeFunc(MeasEnd)
                Return True
            End If

            TestData.Test_Battery = CSng(ResData)
            txbVolt.Text = TestData.Test_Battery

            If TestData.Test_Battery >= CSng(BatCapacityMin.Text) And TestData.Test_Battery <= CSng(BatCapacityMax.Text) Then
                txbVolt.ForeColor = Color.Blue
                TestRunningState(testRunningList.Success, Color.Green)
                txbWindow.AppendText("Battery Volt Check : " & MeasureTimeFunc(MeasEnd) & vbCrLf)
                Return False
            Else
                txbVolt.ForeColor = Color.Red
                TestRunningState(testRunningList.Fail, Color.Red)
                txbWindow.AppendText("Battery Volt Check FAIL : " & MeasureTimeFunc(MeasEnd) & vbCrLf)
                Return True
            End If

        Catch ex As InvalidCastException
            txbWindow.AppendText("JIG Serial Battery Test Min Or Max Result Error : TimeOut" & vbCrLf)
            TestRunningState(testRunningList.Fail, Color.Red)
            MeasureTimeFunc(MeasEnd)
            Return True
        End Try

    End Function

    Private Function TempTest() As Boolean
        MeasureTimeFunc(MeasStart)
        MainTextChange("온도 데이터 측정중")
        TestStep = TestList.Temp
        TestRunningState(testRunningList.Running, Color.Yellow)

        Dim ResData As String = RunTemp()

        If ResData = "conerror" Then
            MsgBox("제품과의 연결이 올바르지 않습니다. 연결 상태를 확인하여 주십시오.", vbCritical, Program_Name & Program_Version)
            MeasureTimeFunc(MeasEnd)
            TestRunningState(testRunningList.Fail, Color.Red)
            Return True
        End If

        Dim ErrorStep As Boolean = False
        Dim DataCount As Int16 = UBound(Split(ResData, ","))

        If DataCount <> 0 And (DataCount = TempData.CartTemp Or DataCount = TempData.CPUTemp) Then

            For i = 0 To DataCount
                Dim resStr As String
                If i = DataCount Then
                    resStr = Mid(ResData, 1, ResData.Length)
                Else
                    resStr = Mid(ResData, 1, InStr(ResData, ",") - 1)
                    ResData = Mid(ResData, InStr(ResData, ",") + 1, ResData.Length)
                End If

                If resStr.Length > 5 Then
                    TestData.Test_Temperature(i) = 0
                Else
                    TestData.Test_Temperature(i) = resStr
                End If

                TempSet(i).Text = TestData.Test_Temperature(i)
            Next
        Else
            txbWindow.AppendText("Temperature Test Connecter Error : " & vbCrLf)
            MeasureTimeFunc(MeasEnd)
            TestRunningState(testRunningList.Fail, Color.Red)
            Return True
        End If

        If TempCheck() = True Then
            If TestData.Test_Temperature(TempData.DivTemp) <= CSng(TmpMin(TempData.DivTemp).Text) Or TestData.Test_Temperature(TempData.DivTemp) >= CSng(TmpMax(TempData.DivTemp).Text) Then
                TempSet(TempData.DivTemp).ForeColor = Color.Red
                ErrorStep = True
            Else
                TempSet(TempData.DivTemp).ForeColor = Color.Blue
            End If

            TestData.Test_Temperature(TempData.CartTemp) = 0
        Else
            For i = 0 To TempData.CartTemp
                If TestData.Test_Temperature(i) <= CSng(TmpMin(i).Text) Or TestData.Test_Temperature(i) >= CSng(TmpMax(i).Text) Then
                    TempSet(i).ForeColor = Color.Red
                    ErrorStep = True
                Else
                    TempSet(i).ForeColor = Color.Blue
                End If
            Next
        End If

        TempSet(TempData.DivTemp).Refresh()
        TempSet(TempData.CartTemp).Refresh()

        If ErrorStep = True Then
            txbWindow.AppendText("Temperature Full Time : " & MeasureTimeFunc(MeasEnd) & vbCrLf)
            TestRunningState(testRunningList.Fail, Color.Red)
            Return True
        End If

        txbWindow.AppendText("Temperature Full Time : " & MeasureTimeFunc(MeasEnd) & vbCrLf)
        TestRunningState(testRunningList.Success, Color.Green)
        Return False

    End Function

    Private Function TempCheck() As Boolean
        If formType = formTypeList.iqcHFRFEP Or formType = formTypeList.iqcRFEP Or formType = formTypeList.iqcHF Then
            Return True
        Else
            If formType = formTypeList.prdHF Or formType = formTypeList.iqcDsHF Or formType = formTypeList.prdDsHF Then
                If ckbModeV2.Checked = True Or formType = formTypeList.iqcDsHF Or formType = formTypeList.prdDsHF Then
                    Return True
                Else
                    Return False
                End If
            Else
                Return False
            End If
        End If
    End Function

    Private Function DataWriteAL() As Boolean
        MeasureTimeFunc(MeasStart)
        MainTextChange("정보입력중..")
        TestStep = TestList.DataWrite
        TestRunningState(testRunningList.Running, Color.Yellow)

        Dim sucSwitch As Boolean = False

        If ResetData() Then
            GoTo DataFail
        End If

        For i = 1 To nudSaveCk.Value
            If prod_reg_data("JOMT", "003000", ModelCode.PadRight(2, "0"c), "82", "0") Then
                GoTo DataFail
            End If
        Next

        For i = 1 To nudSaveCk.Value
            sucSwitch = False
            If SerialWrite(TestData.Test_Serial) Then
                GoTo DataFail
            End If

            Dim tdData As String = TD_name_load()

            If tdData = "0" Or tdData = "1" Then
                GoTo DataFail
            End If

            If tdData.ToUpper = TestData.Test_Serial Then
                sucSwitch = True
                Exit For
            End If
        Next

        If sucSwitch = False Then
            GoTo DataFail
        End If

        txbWindow.AppendText("DataWrite Full Time : " & MeasureTimeFunc(MeasEnd) & vbCrLf)
        TestRunningState(testRunningList.Success, Color.Green)
        Return False

DataFail:
        txbWindow.AppendText("Product Data Write Error" & vbCrLf)
        TestRunningState(testRunningList.Fail, Color.Red)
        TestError = False
        Return True

    End Function

    Private Function TestDataSearch(TDSerial As String) As Boolean
        DBCmd = "SELECT COUNT(PV_SN) FROM " & hfTableNow & " WHERE PV_SN = '" & TDSerial & "'"

        Dim SerialCount As Integer = DBQueryScalar(DBCmd)

        If SerialCount = 0 Then
            Return False
        Else
            Return True
        End If
    End Function

    Private Function MonthCodeChange(monthData As String) As String
        Select Case monthData
            Case "01"
                Return "1"
            Case "02"
                Return "2"
            Case "03"
                Return "3"
            Case "04"
                Return "4"
            Case "05"
                Return "5"
            Case "06"
                Return "6"
            Case "07"
                Return "7"
            Case "08"
                Return "8"
            Case "09"
                Return "9"
            Case "10"
                Return "A"
            Case "11"
                Return "B"
            Case "12"
                Return "C"
            Case Else
                Return "-1"
        End Select
    End Function

    Private Function NewSerialCreate() As Boolean
        Const SerialLength As Int16 = 4
        Dim CreateOK As Boolean = True
        Dim SerialNum As String = String.Empty

        DBCmd = "SELECT PD1_DevTotalCnt FROM " & pd1CntTableNow & " WHERE PD1_Date = '" & NowDate & "'"
        Dim TotalCount As Int16 = DBQueryScalar(DBCmd)
        Dim SerialMonth As String = MonthCodeChange(Format(Now, "MM"))
        Dim SerialYear As String = Format(Now, "yy")
        Dim SerialDay As String = Format(Now, "dd")
        Dim ProdCode As String = ModelCode

        If SerialMonth = "-1" Then
            Return False
        End If

        For i = 0 To 4  '' 새 번호 여부 확인 횟수 (5회 확인)
            TotalCount += 1
            SerialNum = TotalCount

            For cnt = TotalCount.ToString.Length To SerialLength - 1  ''시리얼 번호 뒷 자리 네 개는 일별 제작 순번
                SerialNum = "0" & SerialNum
            Next

            SerialNum = ProdCode & SerialYear & SerialMonth & SerialDay & SerialNum

            If TestDataSearch(SerialNum) = False Then
                TestData.Test_Serial = SerialNum
                Return False
            End If
        Next

        Return True
    End Function

    Private Function TDNullProdWrite() As Boolean

        dupDATA = 0
        Dim tdData As String = TD_name_load()

        If tdData = "1" Then
            GoTo DataFail
        End If

        If tdData = "0" Then
            GoTo TDNulllFunc
        Else
            If TestDataSearch(tdData) Then
                TestData.Test_Serial = tdData
                dupDATA = 1
                Return False
            Else
                GoTo TDNulllFunc
            End If
        End If

TDNulllFunc:
        If NewSerialCreate() Then
            txbWindow.AppendText("TD Null Product Serial Number Create Error" & vbCrLf)
            TestError = False
            Return True
        End If

        Return False
DataFail:
        txbWindow.AppendText("TD Null Product Serial Number Data Search Error" & vbCrLf)
        TestError = False
        Return True
    End Function

    Private Function DataWrite(ProdCode As String) As Boolean
        MeasureTimeFunc(MeasStart)
        MainTextChange("정보입력중..")
        TestStep = TestList.DataWrite
        TestRunningState(testRunningList.Running, Color.Yellow)

        Dim tdData As String = String.Empty
        Dim freqData As String = String.Empty
        Dim powerData As String = String.Empty
        Dim motorData As Int16 = 0
        Dim sucSwitch As Boolean = False

        If ResetData() Then
            txbWindow.AppendText("PCB initialize Error" & vbCrLf)
            GoTo DataFail
        End If

        For i = 1 To nudSaveCk.Value
            If prod_reg_data("JOMT", "000000", ProdCode, "82", "0") Then
                GoTo DataFail
            End If
        Next

        If TDUseYn = True Then

            For i = 1 To nudSaveCk.Value
                sucSwitch = False
                If SerialWrite(TestData.Test_Serial) Then
                    GoTo DataFail
                End If

                tdData = TD_name_load()

                If tdData = "0" Or tdData = "1" Then
                    GoTo DataFail
                End If

                If tdData.ToUpper = TestData.Test_Serial Then
                    sucSwitch = True
                    Exit For
                End If
            Next

            If sucSwitch = False Then
                GoTo DataFail
            Else
                txbWindow.AppendText("Product Serial Number : " & tdData & vbCrLf)
            End If

            For i = 1 To nudSaveCk.Value
                sucSwitch = False
                If FreqWrite(TDDataSet(TD_Data.Freq), TDDataSet(TD_Data.power)) Then
                    GoTo DataFail
                End If

                freqData = sett_data()

                If freqData = "0" Then
                    GoTo DataFail
                End If

                powerData = Mid(freqData, InStrRev(freqData, ",", freqData.Length) + 1, freqData.Length)
                freqData = Mid(freqData, 1, InStr(1, freqData, ",") - 1)

                If powerData = TDDataSet(TD_Data.power) And freqData = TDDataSet(TD_Data.Freq) Then
                    sucSwitch = True
                    Exit For
                End If
            Next

            If sucSwitch = False Then
                GoTo DataFail
            Else
                txbWindow.AppendText("Product Frequence : " & freqData & "/ Power : " & powerData & vbCrLf)
            End If
            If formType <> formTypeList.prdHFLDMEP Then
                For i = 1 To nudSaveCk.Value
                    sucSwitch = False
                    If Motor_reg(TDDataSet(TD_Data.motor)) Then
                        GoTo DataFail
                    End If

                    motorData = Motor_Read()

                    If motorData = 6 Then
                        GoTo DataFail
                    End If

                    If motorData = TDDataSet(TD_Data.motor) Then
                        sucSwitch = True
                        Exit For
                    End If
                Next
            End If

            If sucSwitch = False Then
                GoTo DataFail
            Else
                txbWindow.AppendText("Product Motor : " & motorData & vbCrLf)
            End If
        End If

        txbWindow.AppendText("DataWrite Full Time : " & MeasureTimeFunc(MeasEnd) & vbCrLf)
        TestRunningState(testRunningList.Success, Color.Green)
        Return False

DataFail:
        txbWindow.AppendText("Product Data PCB Write Error" & vbCrLf)
        TestRunningState(testRunningList.Fail, Color.Red)
        TestError = False
        Return True
    End Function

    Private Function LDMDataWrite(ProdCode As String) As Boolean
        MeasureTimeFunc(MeasStart)
        MainTextChange("정보입력중..")
        TestStep = TestList.DataWrite
        TestRunningState(testRunningList.Running, Color.Yellow)

        Dim tdData As String = String.Empty
        Dim freqData As String = String.Empty
        Dim sucSwitch As Boolean = False
        Dim returnData As String()

        If ResetData() Then
            txbWindow.AppendText("PCB initialize Error" & vbCrLf)
            GoTo DataFail
        End If

        For i = 1 To nudSaveCk.Value
            If prod_reg_data("JOMT", "000000", ProdCode, "82", "0") Then
                GoTo DataFail
            End If
        Next

        For i = 1 To nudSaveCk.Value
            If ldm_reg_data() Then
                txbWindow.AppendText("LDM PCB WRITE ERROR" & vbCrLf)
                GoTo DataFail
            End If
        Next

        If LdmUseYn = True Then

            For i = 1 To nudSaveCk.Value
                sucSwitch = False
                If LDMSerialWrite(TestData.Test_Serial) Then
                    txbWindow.AppendText("LDM PCB SN WRITE ERROR" & vbCrLf)
                    GoTo DataFail
                End If

                tdData = LDM_name_load()

                If tdData = "0" Or tdData = "1" Then
                    txbWindow.AppendText("LDM PCB SN READ ERROR" & vbCrLf)
                    GoTo DataFail
                End If

                If tdData.ToUpper = TestData.Test_Serial Then
                    sucSwitch = True
                    Exit For
                End If
            Next

            If sucSwitch = False Then
                GoTo DataFail
            Else
                txbWindow.AppendText("Product Serial Number : " & tdData & vbCrLf)
            End If

            For i = 1 To nudSaveCk.Value
                Dim loopFlag As Int16 = 2
                sucSwitch = False
                If LDMFreqWrite(LDM_DataSet(LDM_Data.freq_1), LDM_DataSet(LDM_Data.power_1), LDM_DataSet(LDM_Data.freq_2), LDM_DataSet(LDM_Data.power_2), LDM_DataSet(LDM_Data.freq_3), LDM_DataSet(LDM_Data.power_3)) Then
                    txbWindow.AppendText("LDM PCB FREQ & POWER WRITE ERROR" & vbCrLf)
                    GoTo DataFail
                End If

                freqData = LDM_load_data()

                If freqData = "0" Then
                    txbWindow.AppendText("LDM PCB FREQ & POWER READ ERROR" & vbCrLf)
                    GoTo DataFail
                End If

                returnData = Split(freqData, ",")

                If returnData.Length <> 6 Then
                    txbWindow.AppendText("LDM PCB FREQ & POWER READ ERROR" & vbCrLf)
                    GoTo DataFail
                End If

                For Each temp In returnData
                    If String.Equals(LDM_DataSet(loopFlag), temp, StringComparison.OrdinalIgnoreCase) Then
                        sucSwitch = True
                    Else
                        sucSwitch = False
                        Exit For
                    End If
                    loopFlag += 1
                Next

                If sucSwitch = True Then
                    Exit For
                End If
            Next

            If sucSwitch = False Then
                GoTo DataFail
            Else
                txbWindow.AppendText("Product Frequency Success" & vbCrLf)
            End If
        End If

        txbWindow.AppendText("DataWrite Full Time : " & MeasureTimeFunc(MeasEnd) & vbCrLf)
        TestRunningState(testRunningList.Success, Color.Green)
        Return False

DataFail:
        txbWindow.AppendText("Product Data Write Error" & vbCrLf)
        TestRunningState(testRunningList.Fail, Color.Red)
        TestError = False
        Return True
    End Function

    Private Function prod_reg_data(factory As String, prod_serial As String, prod_code As String, area As String, abroad As String) As Boolean
        Dim retVal As String
        Dim nowDate As String = Format(Now, "yy") & Format(Now, "MM")
        Dim BoardSN As String = nowDate & prod_serial
        tmpCmdMessage = "wrsconf1"

        If ModelCode.Length = 2 Then    '16자리 시리얼번호
            Dim ModelOpt As String = "1"
            Dim QcOpt As String = "100"

            cmdMessage = "[" & tmpCmdMessage & " " & factory & "," & BoardSN & "," & prod_code & "," & ModelOpt & "," & QcOpt & "," & area & "," & abroad & "]" + vbCrLf
            If SendData(cmdMessage) Then
                Return False
            End If

            retVal = PollingReceiveData(1000)

            If retVal <> factory & "," & BoardSN & "," & prod_code & "," & ModelOpt & "," & QcOpt & "," & area & "," & abroad Then
                Return False
            End If
        Else                            '12자리 시리얼번호
            cmdMessage = "[" & tmpCmdMessage & " " & factory & "," & BoardSN & "," & prod_code & "," & area & "," & abroad & "]" + vbCrLf
            If SendData(cmdMessage) Then
                Return False
            End If

            retVal = PollingReceiveData(1000)

            If retVal <> factory.ToLower & "," & BoardSN & "," & prod_code & "," & area & "," & abroad Then
                Return False
            End If
        End If

        Return True
    End Function

    Private Function ldm_reg_data() As Boolean
        Dim retVal As String
        tmpCmdMessage = "wrsconf9"

        cmdMessage = "[" & tmpCmdMessage & " " & TestData.Test_Serial & "," & LDM_DataSet(LDM_Data.freq_1) & "," & LDM_DataSet(LDM_Data.freq_2) & "," & LDM_DataSet(LDM_Data.freq_3) & "," & LDM_DataSet(LDM_Data.power_1) & "," & LDM_DataSet(LDM_Data.power_2) & "," & LDM_DataSet(LDM_Data.power_3) & "]" + vbCrLf
        If SendData(cmdMessage) Then
            Return True
        End If

        retVal = PollingReceiveData(1000)
        Dim compareData As String = TestData.Test_Serial & "," & LDM_DataSet(LDM_Data.freq_1) & "," & LDM_DataSet(LDM_Data.freq_2) & "," & LDM_DataSet(LDM_Data.freq_3) & "," & LDM_DataSet(LDM_Data.power_1) & "," & LDM_DataSet(LDM_Data.power_2) & "," & LDM_DataSet(LDM_Data.power_3)

        If Not String.Equals(retVal, compareData, StringComparison.OrdinalIgnoreCase) Then
            Return True
        End If

        Return False
    End Function

    Private Function TD_name_load() As String
        Dim retVal As String
        tmpCmdMessage = "settdsn"
        cmdMessage = "[" & tmpCmdMessage & "]" + vbCrLf
        If SendData(cmdMessage) Then
            Return "1"
        End If

        retVal = PollingReceiveData(500)
        txbWindow.AppendText("TD READ DATA: " & retVal & "" & vbCrLf)

        Dim c As Integer = Asc(retVal.Substring(0, 1))  ' 첫 글자 아스키값

        If Not ((c >= 48 And c <= 57) Or (c >= 65 And c <= 90) Or (c >= 97 And c <= 122)) Then
            Return "0"
        End If

        'If Not ((c >= 48 And c <= 57) And retVal.Length > td_name_size) Then
        '    Return "0"
        'End If

        If retVal.Length > td_name_size Then
            Return retVal
        Else
            Return "0"
        End If

    End Function
    Private Function LDM_name_load() As String
        Dim retVal As String
        tmpCmdMessage = "setldmsn"
        cmdMessage = "[" & tmpCmdMessage & "]" + vbCrLf
        If SendData(cmdMessage) Then
            Return "1"
        End If

        retVal = PollingReceiveData(500)
        txbWindow.AppendText("LDM RESPONSE DATA: " & retVal & "" & vbCrLf)

        If retVal.Length > td_name_size Then
            Return retVal
        Else
            Return "0"
        End If

    End Function

    Private Function Motor_Read() As Int16
        Dim retval As String

        tmpCmdMessage = "setmotor"
        cmdMessage = "[" & tmpCmdMessage & "]"

        If SendData(cmdMessage) Then
            Return 6
        End If

        retval = PollingReceiveData(1000)
        txbWindow.AppendText("TD MOTER READ DATA :" & retval & vbCrLf)

        If UBound(Split(retval, ",")) = 4 Then
            Return Mid(retval, 1, InStr(1, retval, ",") - 1)
        End If

        Return 6
    End Function

    Private Function sett_data() As String
        Dim retval As String

        tmpCmdMessage = "settdcnf"
        cmdMessage = "[" & tmpCmdMessage & "]" + vbCrLf
        If SendData(cmdMessage) Then
            Return "0"
        End If

        retval = PollingReceiveData(500)
        txbWindow.AppendText("TD FREQ & POWER READ DATA :" & retval & vbCrLf)

        If InStr(1, retval, ",") > 0 Then
            Return retval

        Else
            Return "0"
        End If

    End Function

    Private Function LDM_load_data() As String
        Dim retval As String

        tmpCmdMessage = "setldmcnf"
        cmdMessage = "[" & tmpCmdMessage & "]" + vbCrLf
        If SendData(cmdMessage) Then
            Return "0"
        End If

        retval = PollingReceiveData(500)
        txbWindow.AppendText("LDM FREQ & POWER READ DATA :" & retval & vbCrLf)

        If InStr(1, retval, ",") > 0 Then
            Return retval
        Else
            Return "0"
        End If

    End Function

    Private Function Motor_reg(pulse As Integer) As Boolean
        Dim retval As String

        tmpCmdMessage = "setmotor"
        cmdMessage = "[" & tmpCmdMessage & " " & pulse & ",0,0,0,0]"

        If SendData(cmdMessage) Then
            Return True
        End If

        retval = PollingReceiveData(1000)
        txbWindow.AppendText("TD MOTER WRITE DATA :" & retval & vbCrLf)

        If retval = pulse & ",0,0,0,0" Then
            Return False
        End If

        Return True
    End Function

    Private Sub StartClear()
        DataTextReset()
        DataColorReset()
        DataRefresh()

        txbForeColorReset()

        StepTextReset()
        StepColorReset()
        StepRefresh()

        SaveDataReset()

        rfmceptxbReset()
        rfmceptxbColorReset()
        rfmceptxbRefReset()

        hftxbReset()
        hfColorReset()
        hfRefReset()

        iqctxbReset()
        iqcColorReset()
        iqctxbRefresh()

        altoIQC_txbReset()
        altoIQC_ColorReset()
        altoIQC_RefReset()

        DstxbReset()
        DsColorReset()
        DstxbRefresh()
    End Sub

    Private Sub altoIQC_txbReset()
        txbAlIQCBody.Text = "대기"
        txbAlIQCBody_1.Text = "대기"
        txbAlIQCBody_2.Text = "대기"
        txbAlIQCBody_3.Text = "대기"

        txbAlIQCEP.Text = "대기"
        txbAlIQCEP_1.Text = "대기"
        txbAlIQCEP_2.Text = "대기"
        txbAlIQCEP_3.Text = "대기"

        txbAlIQCRF.Text = "대기"
        txbAlIQCRF_1.Text = "대기"
        txbAlIQCRF_2.Text = "대기"
        txbAlIQCRF_3.Text = "대기"
    End Sub

    Private Sub altoIQC_ColorReset()
        txbAlIQCBody.BackColor = Color.White
        txbAlIQCBody_1.BackColor = Color.White
        txbAlIQCBody_2.BackColor = Color.White
        txbAlIQCBody_3.BackColor = Color.White

        txbAlIQCEP.BackColor = Color.White
        txbAlIQCEP_1.BackColor = Color.White
        txbAlIQCEP_2.BackColor = Color.White
        txbAlIQCEP_3.BackColor = Color.White

        txbAlIQCRF.BackColor = Color.White
        txbAlIQCRF_1.BackColor = Color.White
        txbAlIQCRF_2.BackColor = Color.White
        txbAlIQCRF_3.BackColor = Color.White
    End Sub

    Private Sub altoIQC_RefReset()
        txbAlIQCBody.Refresh()
        txbAlIQCBody_1.Refresh()
        txbAlIQCBody_2.Refresh()
        txbAlIQCBody_3.Refresh()

        txbAlIQCEP.Refresh()
        txbAlIQCEP_1.Refresh()
        txbAlIQCEP_2.Refresh()
        txbAlIQCEP_3.Refresh()

        txbAlIQCRF.Refresh()
        txbAlIQCRF_1.Refresh()
        txbAlIQCRF_2.Refresh()
        txbAlIQCRF_3.Refresh()
    End Sub

    Private Sub txbForeColorReset()
        txbTDSN.ForeColor = Color.Black
        txbDate.ForeColor = Color.Black
        txbFreq.ForeColor = Color.Black
        txbGrade.ForeColor = Color.Black
        txbVer.ForeColor = Color.Black
        txbVolt.ForeColor = Color.Black
        txbDevTmp.ForeColor = Color.Black
        txbCartTmp.ForeColor = Color.Black

    End Sub

    Private Sub hftxbReset()
        txbBat.Text = "대기"
        txbTemp.Text = "대기"
        txbHFresult.Text = "대기"
        txbHFtest1.Text = "대기"
        txbHFtest2.Text = "대기"
        txbHFtest3.Text = "대기"
        txbTDreg.Text = "대기"
        txbDBreg.Text = "대기"
    End Sub

    Private Sub hfColorReset()
        txbBat.BackColor = Color.White
        txbTemp.BackColor = Color.White
        txbHFresult.BackColor = Color.White
        txbHFtest1.BackColor = Color.White
        txbHFtest2.BackColor = Color.White
        txbHFtest3.BackColor = Color.White
        txbTDreg.BackColor = Color.White
        txbDBreg.BackColor = Color.White
    End Sub

    Private Sub hfRefReset()
        txbBat.Refresh()
        txbTemp.Refresh()
        txbHFresult.Refresh()
        txbHFtest1.Refresh()
        txbHFtest2.Refresh()
        txbHFtest3.Refresh()
        txbTDreg.Refresh()
        txbDBreg.Refresh()
    End Sub

    Private Sub rfmceptxbReset()
        txbRFresult.Text = "대기"
        txbRFtest1.Text = "대기"
        txbRFtest2.Text = "대기"
        txbRFtest3.Text = "대기"

        txbMCresult.Text = "대기"

        txbEPresult.Text = "대기"
        txbEPtest1.Text = "대기"
        txbEPtest2.Text = "대기"
        txbEPtest3.Text = "대기"
    End Sub

    Private Sub rfmceptxbColorReset()
        txbRFresult.BackColor = Color.White
        txbRFtest1.BackColor = Color.White
        txbRFtest2.BackColor = Color.White
        txbRFtest3.BackColor = Color.White

        txbMCresult.BackColor = Color.White

        txbEPresult.BackColor = Color.White
        txbEPtest1.BackColor = Color.White
        txbEPtest2.BackColor = Color.White
        txbEPtest3.BackColor = Color.White
    End Sub

    Private Sub rfmceptxbRefReset()
        txbRFresult.Refresh()
        txbRFtest1.Refresh()
        txbRFtest2.Refresh()
        txbRFtest3.Refresh()

        txbMCresult.Refresh()

        txbEPresult.Refresh()
        txbEPtest1.Refresh()
        txbEPtest2.Refresh()
        txbEPtest3.Refresh()
    End Sub

    Private Sub iqctxbReset()
        txbIQCHF.Text = "대기"
        txbIQCRF.Text = "대기"
        txbIQCEP.Text = "대기"

        txbIQCHF1.Text = "대기"
        txbIQCHF2.Text = "대기"
        txbIQCHF3.Text = "대기"

        txbIQCRF1.Text = "대기"
        txbIQCRF2.Text = "대기"
        txbIQCRF3.Text = "대기"

        txbIQCEP1.Text = "대기"
        txbIQCEP2.Text = "대기"
        txbIQCEP3.Text = "대기"
    End Sub

    Private Sub iqcColorReset()
        txbIQCHF.BackColor = Color.White
        txbIQCRF.BackColor = Color.White
        txbIQCEP.BackColor = Color.White

        txbIQCHF1.BackColor = Color.White
        txbIQCHF2.BackColor = Color.White
        txbIQCHF3.BackColor = Color.White

        txbIQCRF1.BackColor = Color.White
        txbIQCRF2.BackColor = Color.White
        txbIQCRF3.BackColor = Color.White

        txbIQCEP1.BackColor = Color.White
        txbIQCEP2.BackColor = Color.White
        txbIQCEP3.BackColor = Color.White
    End Sub

    Private Sub iqctxbRefresh()
        txbIQCHF.Refresh()
        txbIQCRF.Refresh()
        txbIQCEP.Refresh()

        txbIQCHF1.Refresh()
        txbIQCHF2.Refresh()
        txbIQCHF3.Refresh()

        txbIQCRF1.Refresh()
        txbIQCRF2.Refresh()
        txbIQCRF3.Refresh()

        txbIQCEP1.Refresh()
        txbIQCEP2.Refresh()
        txbIQCEP3.Refresh()
    End Sub

    Private Sub DstxbReset()
        txbDSBasic.Text = "대기"
        txbDSFirm.Text = "대기"
        txbDSTemp.Text = "대기"
        txbDSBat.Text = "대기"
        txbDSHifu.Text = "대기"
        txbDSHifu_1.Text = "대기"
        txbDSHifu_2.Text = "대기"
        txbDSHifu_3.Text = "대기"
        txbDSSave.Text = "대기"
        txbDSWrite.Text = "대기"
        txbDSWrite_2.Text = "대기"
        txbDSWrite_3.Text = "대기"
    End Sub

    Private Sub DsColorReset()
        txbDSBasic.BackColor = Color.White
        txbDSFirm.BackColor = Color.White
        txbDSTemp.BackColor = Color.White
        txbDSBat.BackColor = Color.White
        txbDSHifu.BackColor = Color.White
        txbDSHifu_1.BackColor = Color.White
        txbDSHifu_2.BackColor = Color.White
        txbDSHifu_3.BackColor = Color.White
        txbDSSave.BackColor = Color.White
        txbDSWrite.BackColor = Color.White
        txbDSWrite_2.BackColor = Color.White
        txbDSWrite_3.BackColor = Color.White
    End Sub

    Private Sub DstxbRefresh()
        txbDSBasic.Refresh()
        txbDSFirm.Refresh()
        txbDSTemp.Refresh()
        txbDSBat.Refresh()
        txbDSHifu.Refresh()
        txbDSHifu_1.Refresh()
        txbDSHifu_2.Refresh()
        txbDSHifu_3.Refresh()
        txbDSSave.Refresh()
        txbDSWrite.Refresh()
        txbDSWrite_2.Refresh()
        txbDSWrite_3.Refresh()
    End Sub


    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        TestData.Test_Serial = txbBarcode.Text
        txbBarcode.Text = "[START]"

        btnRun_Click(sender, e)
    End Sub

    Private Sub btnRun_Click(sender As Object, e As EventArgs) Handles btnRun.Click
        txbBarcode.ReadOnly = True
        StartClear()
        NowDate = Format(Now, "yyyy-MM-dd")
        NowTime = Format(Now, "HH:mm:ss")
        TestError = True
        TestStep = TestList.Start

        Select Case formType
            Case formTypeList.full
                allFunction()
            Case formTypeList.iqcHFRFEP
                iqcFunction()
            Case formTypeList.iqcHF
                iqcHfFunction()
            Case formTypeList.iqcRFEP
                altoFunctionIQC()
            Case formTypeList.prdHF
                hfFunction()
            Case formTypeList.prdRFMCEP
                rfFunction()
            Case formTypeList.prdRFEP
                AltoFunctionPD()
            Case formTypeList.company
                CompanyFunction()
            Case formTypeList.iqcDsHF, formTypeList.prdDsHF
                DSTestFunction()
                '저가형
            Case formTypeList.iqcHFEP ''WON
                iqcHfEpFunction()
            Case formTypeList.iqcEP ''NEMO
                iqcEpFunction()
            Case formTypeList.iqcRFEPMC ''MAREUMMO
                iqcRfEpMcFunction()
            Case formTypeList.iqcLDM ''SEMO
                iqcHfFunction()
            Case formTypeList.iqcLDMEP ''semoplus   
                iqcLdmEpFunction()

                ''보급형 생산검사는 스코프 -> 스펙트럼 

            Case formTypeList.prdLDM ''ldm spectrum
                ldmFunction()
            Case formTypeList.prdVRLDM ''ldm scope
                'ldmVrmsFunction()
            Case formTypeList.prdLDMEP ''ldm (ep)
                ldmEPFunction()
            Case formTypeList.prdLowHF ''WON(HIFU)
                hfEpFunction()
            Case formTypeList.prdHFLDMEP ''WON(EP)
                hfLdmEpFunction()
            Case formTypeList.prdEP ''저가형 non td 계열
                epfunction()
            Case formTypeList.prdRFMC ''저가형 non td 계열
                rfMcfunction()
            Case Else
                MsgBox("잘못된 동작 모드가 입력되어 있습니다. 관리자에게 문의해주세요.", vbCritical)
        End Select

        txbBarcode.ReadOnly = False
        TestStep = TestList.Wait
        txbBarcode.Focus()
        txbBarcode.Select(txbBarcode.Text.Length, 0)

    End Sub

    Private Function altoNumAppoint(PlusCount As Int16) As String
        Try
            DBCmd = "SELECT PD1_AltoCnt FROM " & pd1CntTableNow & " WHERE PD1_Date = '" & NowDate & "'"

            Dim altoNum As String = DBQueryScalar(DBCmd)

            If altoNum = "" Then
                altoNum = "1"  '' 첫 시작일 경우
            Else
                altoNum = Val(altoNum) + PlusCount  '' 번호 업데이트
            End If

            For i = altoNum.Length To 4
                altoNum = "0" + altoNum
            Next

            altoNum = Mid(NowDate, 4, 1) & Mid(NowDate, 6, 2) & Mid(NowDate, 9, 2) & altoNum
            Return altoNum

        Catch ex As Exception
            MsgBox(ex.Message, vbCritical)
            Return "0"
        End Try
    End Function

    Private Function lowEPNumAppoint(PlusCount As Int16) As String
        Try
            DBCmd = "SELECT PD1_LowPriceEPCnt FROM " & pd1CntTableNow & " WHERE PD1_Date = '" & NowDate & "'"

            Dim altoNum As String = DBQueryScalar(DBCmd)

            If altoNum = "" Then
                altoNum = "1"  '' 첫 시작일 경우
            Else
                altoNum = Val(altoNum) + PlusCount  '' 번호 업데이트
            End If

            For i = altoNum.Length To 4
                altoNum = "0" + altoNum
            Next

            altoNum = Mid(NowDate, 4, 1) & Mid(NowDate, 6, 2) & Mid(NowDate, 9, 2) & altoNum
            Return altoNum

        Catch ex As Exception
            MsgBox(ex.Message, vbCritical)
            Return "0"
        End Try
    End Function

    Private Function NonTDSerial() As Boolean

        Dim TDSerial As String = TD_name_load()

        txbWindow.AppendText("Non TD SN READ : " & TDSerial & vbCrLf)

        If TDSerial = "1" Then
            TestError = False
            txbWindow.AppendText("Non TD SN PORT READ FAIL : " & vbCrLf)
            Return True
        End If

        If TDSerial = "0" Then
            Return True  '' TD 데이터가 없을 경우
        Else
            If IsNumeric(TDSerial) = False Then

                TestError = False
                txbWindow.AppendText("Non TD SN FORMAT(number) FAIL : " & TDSerial & vbCrLf)
                Return True  '' 잘못된 번호가 들어갈 경우

            Else

                TestData.Test_Serial = TDSerial
                Return False  '' TD 데이터가 있을 경우

            End If
        End If


    End Function

    Private Function AltoDataSetting() As Boolean
        Dim NewSerial As Boolean = False
        Dim AltoSerial As String = String.Empty
        Dim chooseFnc As Func(Of Int16, String)
        newTDYnFlag = False
        dupDATA = 0

        If formType = formTypeList.prdRFEP Then
            chooseFnc = AddressOf altoNumAppoint
        Else
            chooseFnc = AddressOf lowEPNumAppoint
        End If

        If NonTDSerial() Then
            If TestError = False Then
                MsgBox("제품의 시리얼 번호를 읽는 중 오류가 발생하였습니다.", vbCritical, Program_Name & Program_Version)
                MeasureTimeFunc(MeasEnd)
                Return True
            End If

            NewSerial = True
            newTDYnFlag = True

        Else
            If NonTDExist() Then
                NewSerial = True
                newTDYnFlag = True
            Else
                If StepSearch() Then
                    MsgBox("현 제품의 공정 순서를 확인할 수 없습니다. 데이터가 존재하지 않습니다.", vbCritical, Program_Name & Program_Version)
                    MeasureTimeFunc(MeasEnd)
                    Return True
                End If

                TDCompare()
                NewSerial = False
            End If
        End If

        If NewSerial = True Then
            Dim SerialCount As Int16 = 1
            Dim CountWhile As Boolean = True

            While CountWhile

                AltoSerial = chooseFnc(SerialCount)
                txbWindow.AppendText("Set Serial Number : " & AltoSerial & vbCrLf)

                If AltoSerial = "0" Then
                    MsgBox("시리얼 번호 생성 도중 오류가 발생하였습니다.", vbCritical, Program_Name & Program_Version)
                    MeasureTimeFunc(MeasEnd)
                    Return True
                End If

                If NonTDExist() Then
                    TestData.Test_Serial = AltoSerial
                    CountWhile = False
                    TDDataSet(TD_Data.TestStep) = "11"
                    dupDATA = 0
                End If

                If SerialCount = 5 Then
                    MsgBox("시리얼 번호 생성 도중 오류가 발생하였습니다.", vbCritical, Program_Name & Program_Version)
                    MeasureTimeFunc(MeasEnd)
                    Return True
                End If

                SerialCount += 1

            End While

        End If

        txbWindow.AppendText("TD Data Time(s) : " & MeasureTimeFunc(MeasEnd) & vbCrLf)
        Return False
    End Function

    Private Sub CompanyFunction()
        StartTime = MeasureTimeAll(MeasStart)

        If StartSwitch = True Then
            If retryPortOpen() Then

                txbWindow.AppendText("-1.OK" & vbCrLf)

                If txbBarcode.Text <> "[START]" Then
                    MsgBox("잘못된 시작 명령어를 입력하였습니다.", vbExclamation, Program_Name & Program_Version)
                    GoTo startFail
                End If

                For i = 0 To nudOnRe.Value

                    If JigRun_On() Then
                        GoTo processEnd
                    End If

                    If FirmVerCheck() Then

                        Dim ReadUni As Byte() = Encoding.Unicode.GetBytes(TestData.Test_Firmware)

                        If ReadUni(0) < 57 Then
                            MsgBox("잘못된 펌웨어 버전입니다. 버전을 확인하여 주십시오.", vbCritical, Program_Name & Program_Version)
                            GoTo processEnd
                        End If

                        If i = nudOnRe.Value Then
                            MsgBox("전원 ON에 실패하였습니다. 다시 시도하여 주십시오.", vbCritical, Program_Name & Program_Version)
                            GoTo processEnd
                        End If

                    Else
                        Exit For
                    End If

                Next

                'If JigRun_On() Then
                '    GoTo startFail
                'End If

                'If FirmVerCheck() Then
                '    MsgBox("최신 펌웨어로 동작하고 있지 않습니다. 펌웨어 버전을 확인하여 주십시오.", vbCritical, Program_Name & Program_Version)
                '    GoTo processEnd
                'End If

                If TempTest() Then
                    GoTo processEnd
                End If

                If BatteryTest() Then
                    GoTo processEnd
                End If

                If RFTestRun() Then
                    GoTo processEnd
                End If

                If EPTestRun() Then
                    GoTo processEnd
                End If

                GoTo processEnd

            Else
                FailMain()
                MsgBox("지그를 연결한 후 동작하여 주십시오.", vbCritical, Program_Name & Program_Version)
                GoTo startFail
            End If
        Else
            FailMain()
            MsgBox("스코프와 스펙트럼을 연결한 후 동작하여 주십시오.", vbCritical, Program_Name & Program_Version)
            GoTo startFail
        End If

processEnd:
        Jig_End()
NormalEnd:
        Dim csvData As String = "" & NowDate & "," & NowTime & "," & TestData.Test_Firmware & "," & TestData.Test_Temperature(TempData.DivTemp) & "," & TestData.Test_RFVRMS(0) & "," & TestData.Test_RFFreq(0) & "," & TestData.Test_RFVRMS(1) & "," & TestData.Test_RFFreq(1) & "," & TestData.Test_RFVRMS(2) & "," & TestData.Test_RFFreq(2) & "," & TestData.Test_EPVpp(0) & "," & TestData.Test_EPFreq(0) & "," & TestData.Test_EPPWidth(0) & "," & TestData.Test_EPNWidth(0) & "," & TestData.Test_EPVpp(1) & "," & TestData.Test_EPFreq(1) & "," & TestData.Test_EPPWidth(1) & "," & TestData.Test_EPNWidth(1) & "," & TestData.Test_EPVpp(2) & "," & TestData.Test_EPFreq(2) & "," & TestData.Test_EPPWidth(2) & "," & TestData.Test_EPNWidth(2) & ""

        If Save_Csv(csvData) Then
            txbWindow.AppendText("CSV Data Save : FAIL" & vbCrLf)
            GoTo processEnd
        Else
            If TestError = False Then
                FailMain()
            Else
                SuccessMain()
            End If
        End If

startFail:
        ScopeClear()
        SpecClear()
        txbWindow.AppendText("[" & MeasureTimeAll(MeasEnd) & "ms] Test Play" & vbCrLf)
    End Sub

    Private Sub AltoFunctionPD()
        StartTime = MeasureTimeAll(MeasStart)

        If StartSwitch = True Then
            If retryPortOpen() Then

                If txbBarcode.Text <> "[START]" Then
                    MsgBox("잘못된 시작 명령어를 입력하였습니다.", vbExclamation, Program_Name & Program_Version)
                    GoTo startFail
                End If

                For i = 0 To nudOnRe.Value

                    If JigRun_On() Then
                        GoTo processEnd
                    End If

                    If FirmVerCheck() Then

                        Dim ReadUni As Byte() = Encoding.Unicode.GetBytes(TestData.Test_Firmware)

                        If ReadUni(0) < 57 Then
                            MsgBox("잘못된 펌웨어 버전입니다. 버전을 확인하여 주십시오.", vbCritical, Program_Name & Program_Version)
                            GoTo processEnd
                        End If

                        If i = nudOnRe.Value Then
                            MsgBox("전원 ON에 실패하였습니다. 다시 시도하여 주십시오.", vbCritical, Program_Name & Program_Version)
                            GoTo processEnd
                        End If

                    Else
                        Exit For
                    End If

                Next

                'If JigRun_On() Then
                '    GoTo startFail
                'End If

                'If FirmVerCheck() Then
                '    MsgBox("최신 펌웨어로 동작하고 있지 않습니다. 펌웨어 버전을 확인하여 주십시오.", vbCritical, Program_Name & Program_Version)
                '    TestError = False
                '    GoTo processEnd
                'End If

                If AltoDataSetting() Then
                    TestError = False
                    GoTo processEnd
                End If

                If TempTest() Then
                    TestError = False
                    GoTo NormalEnd
                End If

                If BatteryTest() Then
                    TestError = False
                    GoTo NormalEnd
                End If

                If RFTestRun() Then
                    TestError = False
                    GoTo NormalEnd
                End If

                If EPTestRun() Then
                    GoTo NormalEnd
                End If

                If DataWriteAL() Then
                    TestError = False
                    GoTo NormalEnd
                End If

                GoTo NormalEnd

            Else
                FailMain()
                MsgBox("지그를 연결한 후 동작하여 주십시오.", vbCritical, Program_Name & Program_Version)
                GoTo startFail
            End If
        Else
            FailMain()
            MsgBox("스코프와 스펙트럼을 연결한 후 동작하여 주십시오.", vbCritical, Program_Name & Program_Version)
            GoTo startFail
        End If


NormalEnd:

        If ALPD_PostReg() Then
            If dbAltoSave() Then
                If CountChanage() Then
                    Dim csvData As String

                    csvData = "" & TestData.Test_Serial & "," & NowDate & "," & NowTime & "," & TestData.Test_Firmware & "," & TestData.Test_Temperature(TempData.DivTemp) & "," & TestData.Test_Temperature(TempData.CartTemp) & "," & TestData.Test_Battery & "," & TestData.Test_RFVRMS(0) & "," & TestData.Test_RFFreq(0) & "," & TestData.Test_RFVRMS(1) & "," & TestData.Test_RFFreq(1) & "," & TestData.Test_RFVRMS(2) & "," & TestData.Test_RFFreq(2) & "," & TestData.Test_EPVpp(0) & "," & TestData.Test_EPFreq(0) & "," & TestData.Test_EPPWidth(0) & "," & TestData.Test_EPNWidth(0) & "," & TestData.Test_EPVpp(1) & "," & TestData.Test_EPFreq(1) & "," & TestData.Test_EPPWidth(1) & "," & TestData.Test_EPNWidth(1) & "," & TestData.Test_EPVpp(2) & "," & TestData.Test_EPFreq(2) & "," & TestData.Test_EPPWidth(2) & "," & TestData.Test_EPNWidth(2) & ""

                    If Save_Csv(csvData) Then
                        txbWindow.AppendText("CSV Data Save : FAIL" & vbCrLf)
                        GoTo processEnd
                    Else
                        If TestError = False Then
                            FailMain()
                        Else
                            SuccessMain()
                        End If
                    End If

                Else
                    FailMain()
                End If
            Else
                FailMain()
            End If
        Else
            FailMain()
        End If

processEnd:
        If ResponseErrorCheck Then
            RetryMain()
        ElseIf TestError = False Then
            FailMain()
        End If
        Jig_End()

startFail:
        ScopeClear()
        SpecClear()
        txbWindow.AppendText("[" & MeasureTimeAll(MeasEnd) & "ms] Test Play" & vbCrLf)
    End Sub

    Private Function ALPD_PostReg() As Boolean

        If ckbPostgre.Checked = True Then
            DBCmd = "select exists(select 1 from prods where td_serial = '" & TestData.Test_Serial & "') AS A;"
            Dim TDExistBol As Boolean = pgDBQueryScalar(DBCmd)

            If TDExistBol = False Then
                DBCmd = "INSERT INTO prods(td_serial, p2_jignum, p2_testdate, p2_testtime, p2_result, p2_rf1_vrms, p2_rf1_freq, p2_rf2_vrms, p2_rf2_freq, p2_rf3_vrms, p2_rf3_freq, p2_mc1_vpp, p2_mc1_freq,p2_mc1_width, p2_mc2_vpp, p2_mc2_freq, p2_mc2_width, p2_ep1_vpp, p2_ep1_freq, p2_ep1_pwidth, p2_ep1_nwidth, p2_ep2_vpp, p2_ep2_freq, p2_ep2_pwidth, p2_ep2_nwidth, p2_ep3_vpp, p2_ep3_freq, p2_ep3_pwidth, p2_ep3_nwidth, created_at, updated_at) " &
                    "VALUES('" & TestData.Test_Serial & "', '" & nudJigNum.Value & "', '" & NowDate & "', '" & NowTime & "','" & TestError & "', '" & TestData.Test_RFVRMS(0) & "', '" & TestData.Test_RFFreq(0) & "', '" & TestData.Test_RFVRMS(1) & "', '" & TestData.Test_RFFreq(1) & "', '" & TestData.Test_RFVRMS(2) & "', '" & TestData.Test_RFFreq(2) & "', '" & TestData.Test_MCVpp(0) & "', '" & TestData.Test_MCFreq(0) & "', '" & TestData.Test_MCWidth(0) & "','" & TestData.Test_MCVpp(1) & "', '" & TestData.Test_MCFreq(1) & "', '" & TestData.Test_MCWidth(1) & "','" & TestData.Test_EPVpp(0) & "','" & TestData.Test_EPFreq(0) & "','" & TestData.Test_EPPWidth(0) & "','" & TestData.Test_EPNWidth(0) & "','" & TestData.Test_EPVpp(1) & "','" & TestData.Test_EPFreq(1) & "','" & TestData.Test_EPPWidth(1) & "','" & TestData.Test_EPNWidth(1) & "','" & TestData.Test_EPVpp(2) & "','" & TestData.Test_EPFreq(2) & "','" & TestData.Test_EPPWidth(2) & "','" & TestData.Test_EPNWidth(2) & "',NOW(),NOW());"
            Else
                DBCmd = "UPDATE prods SET td_serial = '" & TestData.Test_Serial & "', p2_jignum = '" & nudJigNum.Value & "', p2_testdate = '" & NowDate & "', p2_testtime = '" & NowTime & "', " &
                    "p2_result = '" & TestError & "', p2_rf1_vrms = '" & TestData.Test_RFVRMS(0) & "', p2_rf1_freq = '" & TestData.Test_RFFreq(0) & "', p2_rf2_vrms = '" & TestData.Test_RFVRMS(1) & "', " &
                    "p2_rf2_freq = '" & TestData.Test_RFFreq(1) & "', p2_rf3_vrms = '" & TestData.Test_RFVRMS(2) & "', p2_rf3_freq = '" & TestData.Test_RFFreq(2) & "', p2_mc1_vpp = '" & TestData.Test_MCVpp(0) & "', p2_mc1_freq = '" & TestData.Test_MCFreq(0) & "',p2_mc1_width = '" & TestData.Test_MCWidth(0) & "',p2_mc2_vpp = '" & TestData.Test_MCVpp(1) & "', p2_mc2_freq = '" & TestData.Test_MCFreq(1) & "',p2_mc2_width = '" & TestData.Test_MCWidth(1) & "',p2_ep1_vpp = '" & TestData.Test_EPVpp(0) & "',p2_ep1_freq = '" & TestData.Test_EPFreq(0) & "',p2_ep1_pwidth = '" & TestData.Test_EPPWidth(0) & "',p2_ep1_nwidth = '" & TestData.Test_EPNWidth(0) & "',p2_ep2_vpp = '" & TestData.Test_EPVpp(1) & "',p2_ep2_freq = '" & TestData.Test_EPFreq(1) & "',p2_ep2_pwidth = '" & TestData.Test_EPNWidth(1) & "',p2_ep2_nwidth = '" & TestData.Test_EPNWidth(1) & "',p2_ep3_vpp = '" & TestData.Test_EPVpp(2) & "',p2_ep3_freq = '" & TestData.Test_EPFreq(2) & "',p2_ep3_pwidth = '" & TestData.Test_EPPWidth(2) & "', p2_ep3_nwidth = '" & TestData.Test_EPNWidth(2) & "', updated_at = NOW() WHERE td_serial = '" & TestData.Test_Serial & "';"
            End If

            If pgDBCommand(DBCmd) Then
                Return True
            Else
                Return False
            End If
        Else
            Return True
        End If
    End Function

    Private Sub altoFunctionIQC()
        StartTime = MeasureTimeAll(MeasStart)

        If StartSwitch = True Then
            If retryPortOpen() Then

                If txbBarcode.Text <> "[START]" Then
                    MsgBox("잘못된 시작 명령어를 입력하였습니다.", vbExclamation, Program_Name & Program_Version)
                    GoTo NormalEnd
                End If

                For i = 0 To nudOnRe.Value

                    If JigRun_On() Then
                        GoTo ProcessEnd
                    End If

                    If FirmVerCheck() Then

                        Dim ReadUni As Byte() = Encoding.Unicode.GetBytes(TestData.Test_Firmware)

                        If ReadUni(0) < 57 Then
                            MsgBox("잘못된 펌웨어 버전입니다. 버전을 확인하여 주십시오.", vbCritical, Program_Name & Program_Version)
                            GoTo ProcessEnd
                        End If

                        If i = nudOnRe.Value Then
                            MsgBox("전원 ON에 실패하였습니다. 다시 시도하여 주십시오.", vbCritical, Program_Name & Program_Version)
                            GoTo ProcessEnd
                        End If

                    Else
                        Exit For
                    End If

                Next

                If BuzzerTestFunc(0) Then
                    TestError = False
                    GoTo ProcessEnd
                End If

                delay_run(100)

                If TempTest() Then
                    GoTo ProcessEnd
                End If

                If RFTestRun() Then
                    GoTo ProcessEnd
                End If

                If BuzzerTestFunc(1) Then
                    TestError = False
                    GoTo ProcessEnd
                End If

                delay_run(100)

                If EPTestRun() Then
                    GoTo ProcessEnd
                End If

                If BuzzerTestFunc(2) Then
                    TestError = False
                    GoTo ProcessEnd
                End If

                todayCount += 1
                If saveLocalFile() Then
                    GoTo ProcessEnd
                End If

                GoTo SuccessEnd

            Else
                MsgBox("지그를 연결한 후 동작하여 주십시오.", vbCritical, Program_Name & Program_Version)
                GoTo NormalEnd
            End If
        Else
            MsgBox("스코프와 스펙트럼을 연결한 후 동작하여 주십시오.", vbCritical, Program_Name & Program_Version)
            GoTo NormalEnd
        End If

SuccessEnd:
        If ALIQC_PostReg() Then

            txbWindow.AppendText("PostgreSQL Data Save : OK" & vbCrLf)
            Dim csvData As String = "" & NowDate & "," & NowTime & "," & TestData.Test_Firmware & "," & TestData.Test_Temperature(TempData.DivTemp) & "," & TestData.Test_Temperature(TempData.CartTemp) & "," & TestData.Test_Battery & "," & TestData.Test_RFVRMS(0) & "," & TestData.Test_RFFreq(0) & "," & TestData.Test_RFVRMS(1) & "," & TestData.Test_RFFreq(1) & "," & TestData.Test_RFVRMS(2) & "," & TestData.Test_RFFreq(2) & "," & TestData.Test_EPVpp(0) & "," & TestData.Test_EPFreq(0) & "," & TestData.Test_EPPWidth(0) & "," & TestData.Test_EPNWidth(0) & "," & TestData.Test_EPVpp(1) & "," & TestData.Test_EPFreq(1) & "," & TestData.Test_EPPWidth(1) & "," & TestData.Test_EPNWidth(1) & "," & TestData.Test_EPVpp(2) & "," & TestData.Test_EPFreq(2) & "," & TestData.Test_EPPWidth(2) & "," & TestData.Test_EPNWidth(2) & "," & TestError & ""

            If Save_Csv(csvData) Then

                txbWindow.AppendText("CSV Data Save : FAIL" & vbCrLf)
                FailMain()

            Else

                txbWindow.AppendText("CSV Data Save : OK" & vbCrLf)

                If CountChanage() Then

                    txbWindow.AppendText("Run Count Change Save : OK" & vbCrLf)

                    If TestError = False Then
                        FailMain()
                    Else
                        SuccessMain()
                    End If

                Else

                    txbWindow.AppendText("Run Count Change Save : FAIL" & vbCrLf)
                    FailMain()

                End If

            End If

        Else
            txbWindow.AppendText("PostgreSQL Data Save : FAIL" & vbCrLf)
            FailMain()
        End If


ProcessEnd:
        If ResponseErrorCheck Then
            RetryMain()
        ElseIf TestError = False Then
            FailMain()
        End If
        Jig_End()

NormalEnd:
        ScopeClear()
        SpecClear()
        txbWindow.AppendText("[" & MeasureTimeAll(MeasEnd) & "ms] Test Play" & vbCrLf)
    End Sub

    Private Function ALIQC_PostReg() As Boolean

        If ckbPostgre.Checked = True Then

            DBCmd = "INSERT INTO pcbs(
                                      jig_num
                                    , test_date
                                    , test_time
                                    , board_num
                                    , test_result
                                    , fw_ver
                                    , rf1_vrms
                                    , rf1_freq
                                    , rf2_vrms
                                    , rf2_freq
                                    , rf3_vrms
                                    , rf3_freq
                                    , ep1_vpp
                                    , ep1_freq
                                    , ep1_pwidth
                                    , ep1_nwidth
                                    , ep2_vpp
                                    , ep2_freq
                                    , ep2_pwidth
                                    , ep2_nwidth
                                    , ep3_vpp
                                    , ep3_freq
                                    , ep3_pwidth
                                    , ep3_nwidth
                                    , created_at, updated_at) " &
                             "VALUES('" &
                                      nudJigNum.Value &
                             "', '" & NowDate &
                             "', '" & NowTime &
                             "', '" & todayCount &
                             "', '" & TestError &
                             "', '" & TestData.Test_Firmware &
                             "', '" & TestData.Test_RFVRMS(0) &
                             "', '" & TestData.Test_RFFreq(0) &
                             "', '" & TestData.Test_RFVRMS(1) &
                             "', '" & TestData.Test_RFFreq(1) &
                             "', '" & TestData.Test_RFVRMS(2) &
                             "', '" & TestData.Test_RFFreq(2) &
                             "', '" & TestData.Test_EPVpp(0) &
                             "', '" & TestData.Test_EPFreq(0) &
                             "', '" & TestData.Test_EPPWidth(0) &
                             "', '" & TestData.Test_EPNWidth(0) &
                             "', '" & TestData.Test_EPVpp(1) &
                             "', '" & TestData.Test_EPFreq(1) &
                             "', '" & TestData.Test_EPPWidth(1) &
                             "', '" & TestData.Test_EPNWidth(1) &
                             "', '" & TestData.Test_EPVpp(2) &
                             "', '" & TestData.Test_EPFreq(2) &
                             "', '" & TestData.Test_EPPWidth(2) &
                             "', '" & TestData.Test_EPNWidth(2) &
                             "', NOW(), NOW());"

            If pgDBCommand(DBCmd) Then
                Return True
            Else
                Return False
            End If
        Else
            Return True
        End If

    End Function

    Private Sub iqcFunction()
        StartTime = MeasureTimeAll(MeasStart)

        If StartSwitch = True Then
            If retryPortOpen() Then

                If txbBarcode.Text = "[START]" Then

                    For i = 0 To nudOnRe.Value

                        If JigRun_On() Then
                            GoTo processEnd
                        End If

                        delay_run(StepDelay)

                        If FirmVerCheck() Then

                            Dim ReadUni As Byte() = Encoding.Unicode.GetBytes(TestData.Test_Firmware)

                            If ReadUni(0) < 57 Then
                                MsgBox("잘못된 펌웨어 버전입니다. 버전을 확인하여 주십시오.", vbCritical, Program_Name & Program_Version)
                                GoTo processEnd
                            End If

                            If i = nudOnRe.Value Then
                                MsgBox("전원 ON에 실패하였습니다. 다시 시도하여 주십시오.", vbCritical, Program_Name & Program_Version)
                                GoTo processEnd
                            End If

                        Else
                            Exit For
                        End If

                        delay_run(StepDelay)

                    Next

                    If BuzzerTestFunc(0) Then
                        TestError = False
                        GoTo processEnd
                    End If

                    delay_run(StepDelay)

                    If TempTest() Then
                        TestError = False
                        GoTo processEnd
                    End If

                    delay_run(StepDelay)

                    If HFTestRun() Then
                        TestError = False
                        GoTo processEnd
                    End If

                    delay_run(StepDelay)

                    If BuzzerTestFunc(1) Then
                        TestError = False
                        GoTo processEnd
                    End If

                    delay_run(StepDelay)

                    If RFTestRun() Then
                        TestError = False
                        GoTo processEnd
                    End If

                    delay_run(StepDelay)

                    If BuzzerTestFunc(2) Then
                        TestError = False
                        GoTo processEnd
                    End If

                    delay_run(StepDelay)

                    If EPTestRun() Then
                        GoTo processEnd
                    End If

                    delay_run(StepDelay)

                    todayCount += 1
                    If saveLocalFile() Then
                        GoTo processEnd
                    End If

                    GoTo SuccessEnd

                Else
                    MsgBox("잘못된 시작 명령어를 입력하였습니다.", vbExclamation, Program_Name & Program_Version)
                    GoTo ErrorEnd
                End If
            Else
                MsgBox("지그를 연결한 후 동작하여 주십시오.", vbCritical, Program_Name & Program_Version)
                GoTo ErrorEnd
            End If
        Else
            MsgBox("스코프와 스펙트럼을 연결한 후 동작하여 주십시오.", vbCritical, Program_Name & Program_Version)
            GoTo ErrorEnd
        End If


SuccessEnd:

        Dim csvData As String = "" & NowDate & "," & NowTime & "," & TestData.Test_Firmware & "," & TestData.Test_Temperature(TempData.DivTemp) & "," & TestData.Test_HFData(HifuTest_Step.Step1) & "," & TestData.Test_HFData(HifuTest_Step.Step2) & "," & TestData.Test_HFData(HifuTest_Step.step3) & "," & TestData.Test_RFVRMS(0) & "," & TestData.Test_RFFreq(0) & "," & TestData.Test_RFVRMS(1) & "," & TestData.Test_RFFreq(1) & "," & TestData.Test_RFVRMS(2) & "," & TestData.Test_RFFreq(2) & "," & TestData.Test_EPVpp(0) & "," & TestData.Test_EPFreq(0) & "," & TestData.Test_EPPWidth(0) & "," & TestData.Test_EPNWidth(0) & "," & TestData.Test_EPVpp(1) & "," & TestData.Test_EPFreq(1) & "," & TestData.Test_EPPWidth(1) & "," & TestData.Test_EPNWidth(1) & "," & TestData.Test_EPVpp(2) & "," & TestData.Test_EPFreq(2) & "," & TestData.Test_EPPWidth(2) & "," & TestData.Test_EPNWidth(2) & "," & TestError & ""

        If Save_Csv(csvData) Then

            txbWindow.AppendText("CSV Data Save : FAIL" & vbCrLf)
            FailMain()

        Else
            txbWindow.AppendText("CSV Data Save : OK" & vbCrLf)

            If IQC_PostReg() Then
                txbWindow.AppendText("PostgreSQL Data Save : OK" & vbCrLf)

                If CountChanage() Then

                    txbWindow.AppendText("Run Count Change Save : OK" & vbCrLf)

                    If TestError = False Then
                        FailMain()
                    Else
                        SuccessMain()
                    End If

                Else

                    txbWindow.AppendText("Run Count Change Save : FAIL" & vbCrLf)
                    FailMain()

                End If
            Else
                txbWindow.AppendText("PostgreSQL Data Save : FAIL" & vbCrLf)
                FailMain()
            End If

        End If

processEnd:
        If ResponseErrorCheck Then
            RetryMain()
        ElseIf TestError = False Then
            FailMain()
        End If
        Jig_End()

ErrorEnd:
        ScopeClear()
        SpecClear()
        txbWindow.AppendText("[" & MeasureTimeAll(MeasEnd) & "ms] Test Play" & vbCrLf)
    End Sub


    Private Sub iqcLdmEpFunction()
        StartTime = MeasureTimeAll(MeasStart)

        If StartSwitch = True Then
            If retryPortOpen() Then

                If txbBarcode.Text = "[START]" Then

                    For i = 0 To nudOnRe.Value

                        If JigRun_On() Then
                            GoTo processEnd
                        End If

                        delay_run(StepDelay)

                        If FirmVerCheck() Then

                            Dim ReadUni As Byte() = Encoding.Unicode.GetBytes(TestData.Test_Firmware)

                            If ReadUni(0) < 57 Then
                                MsgBox("잘못된 펌웨어 버전입니다. 버전을 확인하여 주십시오.", vbCritical, Program_Name & Program_Version)
                                GoTo processEnd
                            End If

                            If i = nudOnRe.Value Then
                                MsgBox("전원 ON에 실패하였습니다. 다시 시도하여 주십시오.", vbCritical, Program_Name & Program_Version)
                                GoTo processEnd
                            End If

                        Else
                            Exit For
                        End If

                        delay_run(StepDelay)

                    Next

                    If BuzzerTestFunc(0) Then
                        TestError = False
                        GoTo processEnd
                    End If

                    delay_run(StepDelay)

                    If TempTest() Then
                        TestError = False
                        GoTo processEnd
                    End If

                    delay_run(StepDelay)

                    If HFTestRunLDM() Then
                        TestError = False
                        GoTo processEnd
                    End If

                    delay_run(StepDelay)

                    If BuzzerTestFunc(1) Then
                        TestError = False
                        GoTo processEnd
                    End If

                    delay_run(StepDelay)

                    If EPTestRun() Then
                        GoTo processEnd
                    End If

                    delay_run(StepDelay)

                    todayCount += 1
                    If saveLocalFile() Then
                        GoTo processEnd
                    End If

                    GoTo SuccessEnd

                Else
                    MsgBox("잘못된 시작 명령어를 입력하였습니다.", vbExclamation, Program_Name & Program_Version)
                    GoTo ErrorEnd
                End If
            Else
                MsgBox("지그를 연결한 후 동작하여 주십시오.", vbCritical, Program_Name & Program_Version)
                GoTo ErrorEnd
            End If
        Else
            MsgBox("스코프와 스펙트럼을 연결한 후 동작하여 주십시오.", vbCritical, Program_Name & Program_Version)
            GoTo ErrorEnd
        End If


SuccessEnd:

        Dim csvData As String = "" & NowDate & "," & NowTime & "," & TestData.Test_Firmware & "," & TestData.Test_Temperature(TempData.DivTemp) & "," & TestData.Test_HFData(HifuTest_Step.Step1) & "," & TestData.Test_HFData(HifuTest_Step.Step2) & "," & TestData.Test_HFData(HifuTest_Step.step3) & "," & TestData.Test_RFVRMS(0) & "," & TestData.Test_RFFreq(0) & "," & TestData.Test_RFVRMS(1) & "," & TestData.Test_RFFreq(1) & "," & TestData.Test_RFVRMS(2) & "," & TestData.Test_RFFreq(2) & "," & TestData.Test_EPVpp(0) & "," & TestData.Test_EPFreq(0) & "," & TestData.Test_EPPWidth(0) & "," & TestData.Test_EPNWidth(0) & "," & TestData.Test_EPVpp(1) & "," & TestData.Test_EPFreq(1) & "," & TestData.Test_EPPWidth(1) & "," & TestData.Test_EPNWidth(1) & "," & TestData.Test_EPVpp(2) & "," & TestData.Test_EPFreq(2) & "," & TestData.Test_EPPWidth(2) & "," & TestData.Test_EPNWidth(2) & "," & TestError & ""

        If Save_Csv(csvData) Then

            txbWindow.AppendText("CSV Data Save : FAIL" & vbCrLf)
            FailMain()

        Else
            txbWindow.AppendText("CSV Data Save : OK" & vbCrLf)

            If IQC_PostReg() Then
                txbWindow.AppendText("PostgreSQL Data Save : OK" & vbCrLf)

                If CountChanage() Then

                    txbWindow.AppendText("Run Count Change Save : OK" & vbCrLf)

                    If TestError = False Then
                        FailMain()
                    Else
                        SuccessMain()
                    End If

                Else

                    txbWindow.AppendText("Run Count Change Save : FAIL" & vbCrLf)
                    FailMain()

                End If
            Else
                txbWindow.AppendText("PostgreSQL Data Save : FAIL" & vbCrLf)
                FailMain()
            End If

        End If

processEnd:
        If ResponseErrorCheck Then
            RetryMain()
        ElseIf TestError = False Then
            FailMain()
        End If
        Jig_End()
ErrorEnd:
        ScopeClear()
        SpecClear()
        txbWindow.AppendText("[" & MeasureTimeAll(MeasEnd) & "ms] Test Play" & vbCrLf)
    End Sub






    Private Function BuzzerTestFunc(TypeNum As Int16) As Boolean
        MeasureTimeFunc(MeasStart)
        tmpCmdMessage = "runbuzz"
        cmdMessage = "[" & tmpCmdMessage & " " & TypeNum & "]"

        If SendData(cmdMessage) Then
            txbWindow.AppendText("BUZZER Send Error !" & vbCrLf)
            Return True
        End If

        Dim BzResult As String = PollingReceiveData(JIGDT_Timeout)

        If BzResult = "sucess" Then
            txbWindow.AppendText("BUZZER " & TypeNum & " OK !" & vbCrLf)
            Return False
        Else
            txbWindow.AppendText("BUZZER Receive Error !" & vbCrLf)
            Return True
        End If
    End Function

    Private Function IQC_PostReg() As Boolean

        If ckbPostgre.Checked = True And TestError = True Then

            DBCmd = "INSERT INTO pcbs(
                                      jig_num
                                    , test_date
                                    , test_time
                                    , board_num
                                    , test_result
                                    , fw_ver
                                    , hf1_value
                                    , hf2_value
                                    , hf3_value
                                    , rf1_vrms
                                    , rf1_freq
                                    , rf2_vrms
                                    , rf2_freq
                                    , rf3_vrms
                                    , rf3_freq
                                    , ep1_vpp
                                    , ep1_freq
                                    , ep1_pwidth
                                    , ep1_nwidth
                                    , ep2_vpp
                                    , ep2_freq
                                    , ep2_pwidth
                                    , ep2_nwidth
                                    , ep3_vpp
                                    , ep3_freq
                                    , ep3_pwidth
                                    , ep3_nwidth
                                    , created_at, updated_at) " &
                             "VALUES('" &
                                      nudJigNum.Value &
                             "', '" & NowDate &
                             "', '" & NowTime &
                             "', '" & todayCount &
                             "', '" & TestError &
                             "', '" & TestData.Test_Firmware &
                             "', '" & TestData.Test_HFData(HifuTest_Step.Step1) &
                             "', '" & TestData.Test_HFData(HifuTest_Step.Step2) &
                             "', '" & TestData.Test_HFData(HifuTest_Step.step3) &
                             "', '" & TestData.Test_RFVRMS(0) &
                             "', '" & TestData.Test_RFFreq(0) &
                             "', '" & TestData.Test_RFVRMS(1) &
                             "', '" & TestData.Test_RFFreq(1) &
                             "', '" & TestData.Test_RFVRMS(2) &
                             "', '" & TestData.Test_RFFreq(2) &
                             "', '" & TestData.Test_EPVpp(0) &
                             "', '" & TestData.Test_EPFreq(0) &
                             "', '" & TestData.Test_EPPWidth(0) &
                             "', '" & TestData.Test_EPNWidth(0) &
                             "', '" & TestData.Test_EPVpp(1) &
                             "', '" & TestData.Test_EPFreq(1) &
                             "', '" & TestData.Test_EPPWidth(1) &
                             "', '" & TestData.Test_EPNWidth(1) &
                             "', '" & TestData.Test_EPVpp(2) &
                             "', '" & TestData.Test_EPFreq(2) &
                             "', '" & TestData.Test_EPPWidth(2) &
                             "', '" & TestData.Test_EPNWidth(2) &
                             "', NOW(), NOW());"

            If pgDBCommand(DBCmd) Then
                Return True
            Else
                Return False
            End If
        Else
            Return True
        End If

    End Function

    Private Sub iqcEpFunction()
        StartTime = MeasureTimeAll(MeasStart)

        If StartSwitch = True Then
            If retryPortOpen() Then
                If txbBarcode.Text = "[START]" Then
                    For i = 0 To nudOnRe.Value
                        If JigRun_On() Then
                            GoTo processEnd
                        End If

                        delay_run(StepDelay)

                        If FirmVerCheck() Then
                            Dim readUni As Byte() = Encoding.Unicode.GetBytes(TestData.Test_Firmware)
                            If readUni(0) < 57 Then
                                MsgBox("잘못된 펌웨어 버전입니다. 버전을 확인하여 주십시오.", vbCritical, Program_Name & Program_Version)
                                GoTo processEnd
                            End If

                            If i = nudOnRe.Value Then
                                MsgBox("전원 ON에 실패하였습니다. 다시 시도하여 주십시오.", vbCritical, Program_Name & Program_Version)
                                GoTo processEnd
                            End If
                        Else
                            Exit For
                        End If

                        delay_run(StepDelay)
                    Next

                    If BuzzerTestFunc(0) Then
                        TestError = False
                        GoTo processEnd
                    End If

                    delay_run(StepDelay)

                    If TempTest() Then
                        TestError = False
                        GoTo processEnd
                    End If

                    delay_run(StepDelay)

                    If EPTestRun() Then
                        GoTo processEnd
                    End If

                    todayCount += 1
                    If saveLocalFile() Then
                        GoTo processEnd
                    End If
                    GoTo SuccessEnd

                Else
                    MsgBox("잘못된 시작 명령어를 입력하였습니다.", vbExclamation, Program_Name & Program_Version)
                    GoTo ErrorEnd
                End If
            Else
                MsgBox("지그를 연결한 후 동작하여 주십시오.", vbCritical, Program_Name & Program_Version)
                GoTo ErrorEnd
            End If
        Else
            MsgBox("스코프와 스펙트럼을 연결한 후 동작하여 주십시오.", vbCritical, Program_Name & Program_Version)
            GoTo ErrorEnd
        End If

SuccessEnd:
        Dim csvData As String = "" & NowDate & "," & NowTime & "," & TestData.Test_Firmware & "," & TestData.Test_Temperature(TempData.DivTemp) & "," & TestData.Test_EPVpp(0) & "," & TestData.Test_EPFreq(0) & "," & TestData.Test_EPPWidth(0) & "," & TestData.Test_EPNWidth(0) & "," & TestData.Test_EPVpp(1) & "," & TestData.Test_EPFreq(1) & "," & TestData.Test_EPPWidth(1) & "," & TestData.Test_EPNWidth(1) & "," & TestData.Test_EPVpp(2) & "," & TestData.Test_EPFreq(2) & "," & TestData.Test_EPPWidth(2) & "," & TestData.Test_EPNWidth(2) & "," & TestError & ""
        If Save_Csv(csvData) Then

            txbWindow.AppendText("CSV Data Save : FAIL" & vbCrLf)
            FailMain()
        Else
            txbWindow.AppendText("CSV Data Save : OK" & vbCrLf)
            If IQC_PostReg() Then
                txbWindow.AppendText("PostgreSQL Data Save : OK" & vbCrLf)

                If CountChanage() Then

                    txbWindow.AppendText("Run Count Change Save : OK" & vbCrLf)

                    If TestError = False Then
                        FailMain()
                    Else
                        SuccessMain()
                    End If

                Else

                    txbWindow.AppendText("Run Count Change Save : FAIL" & vbCrLf)
                    FailMain()

                End If
            Else
                txbWindow.AppendText("PostgreSQL Data Save : FAIL" & vbCrLf)
                FailMain()
            End If
        End If
processEnd:
        If ResponseErrorCheck Then
            RetryMain()
        ElseIf TestError = False Then
            FailMain()
        End If
        Jig_End()
ErrorEnd:
        ScopeClear()
        SpecClear()
        txbWindow.AppendText("[" & MeasureTimeAll(MeasEnd) & "ms] Test Play" & vbCrLf)
    End Sub

    Private Sub iqcHfEpFunction()
        StartTime = MeasureTimeAll(MeasStart)

        If StartSwitch = True Then
            If retryPortOpen() Then

                If txbBarcode.Text = "[START]" Then

                    For i = 0 To nudOnRe.Value

                        If JigRun_On() Then
                            GoTo processEnd
                        End If

                        delay_run(StepDelay)

                        If FirmVerCheck() Then

                            Dim ReadUni As Byte() = Encoding.Unicode.GetBytes(TestData.Test_Firmware)

                            If ReadUni(0) < 57 Then
                                MsgBox("잘못된 펌웨어 버전입니다. 버전을 확인하여 주십시오.", vbCritical, Program_Name & Program_Version)
                                GoTo processEnd
                            End If

                            If i = nudOnRe.Value Then
                                MsgBox("전원 ON에 실패하였습니다. 다시 시도하여 주십시오.", vbCritical, Program_Name & Program_Version)
                                GoTo processEnd
                            End If

                        Else
                            Exit For
                        End If

                        delay_run(StepDelay)

                    Next

                    If BuzzerTestFunc(0) Then
                        TestError = False
                        GoTo processEnd
                    End If

                    delay_run(StepDelay)

                    If TempTest() Then
                        TestError = False
                        GoTo processEnd
                    End If

                    delay_run(StepDelay)

                    If HFTestRun() Then
                        TestError = False
                        GoTo processEnd
                    End If

                    delay_run(StepDelay)

                    If BuzzerTestFunc(1) Then
                        TestError = False
                        GoTo processEnd
                    End If

                    delay_run(StepDelay)

                    If EPTestRun() Then
                        GoTo processEnd
                    End If

                    todayCount += 1
                    If saveLocalFile() Then
                        GoTo processEnd
                    End If

                    GoTo SuccessEnd

                Else
                    MsgBox("잘못된 시작 명령어를 입력하였습니다.", vbExclamation, Program_Name & Program_Version)
                    GoTo ErrorEnd
                End If
            Else
                MsgBox("지그를 연결한 후 동작하여 주십시오.", vbCritical, Program_Name & Program_Version)
                GoTo ErrorEnd
            End If
        Else
            MsgBox("스코프와 스펙트럼을 연결한 후 동작하여 주십시오.", vbCritical, Program_Name & Program_Version)
            GoTo ErrorEnd
        End If


SuccessEnd:

        Dim csvData As String = "" & NowDate & "," & NowTime & "," & TestData.Test_Firmware & "," & TestData.Test_Temperature(TempData.DivTemp) & "," & TestData.Test_HFData(HifuTest_Step.Step1) & "," & TestData.Test_HFData(HifuTest_Step.Step2) & "," & TestData.Test_HFData(HifuTest_Step.step3) & "," & TestData.Test_EPVpp(0) & "," & TestData.Test_EPFreq(0) & "," & TestData.Test_EPPWidth(0) & "," & TestData.Test_EPNWidth(0) & "," & TestData.Test_EPVpp(1) & "," & TestData.Test_EPFreq(1) & "," & TestData.Test_EPPWidth(1) & "," & TestData.Test_EPNWidth(1) & "," & TestData.Test_EPVpp(2) & "," & TestData.Test_EPFreq(2) & "," & TestData.Test_EPPWidth(2) & "," & TestData.Test_EPNWidth(2) & "," & TestError & ""

        If Save_Csv(csvData) Then
            txbWindow.AppendText("CSV Data Save : FAIL" & vbCrLf)
            FailMain()
        Else
            txbWindow.AppendText("CSV Data Save : OK" & vbCrLf)

            If IQC_PostReg() Then
                txbWindow.AppendText("PostgreSQL Data Save : OK" & vbCrLf)

                If CountChanage() Then
                    txbWindow.AppendText("Run Count Change Save : OK" & vbCrLf)

                    If TestError = False Then
                        FailMain()
                        txbWindow.AppendText("Total Process Fail" & vbCrLf)
                    Else
                        SuccessMain()
                        txbWindow.AppendText("Total Process Success" & vbCrLf)
                    End If
                Else
                    txbWindow.AppendText("Run Count Change Save : FAIL" & vbCrLf)
                    FailMain()
                End If
            Else
                txbWindow.AppendText("PostgreSQL Data Save : FAIL" & vbCrLf)
                FailMain()
            End If
        End If

processEnd:
        If ResponseErrorCheck Then
            RetryMain()
        ElseIf TestError = False Then
            FailMain()
        End If
        Jig_End()

ErrorEnd:
        ScopeClear()
        SpecClear()
        txbWindow.AppendText("[" & MeasureTimeAll(MeasEnd) & "ms] Test Play" & vbCrLf)
    End Sub

    Private Sub iqcRfEpMcFunction()
        Try
            StartTime = MeasureTimeAll(MeasStart)

            If StartSwitch = True Then
                If retryPortOpen() Then

                    If txbBarcode.Text = "[START]" Then
                        For i = 0 To nudOnRe.Value

                            If JigRun_On() Then
                                GoTo ProcessEnd
                            End If

                            If FirmVerCheck() Then

                                Dim ReadUni As Byte() = Encoding.Unicode.GetBytes(TestData.Test_Firmware)

                                If ReadUni(0) < 57 Then
                                    MsgBox("잘못된 펌웨어 버전입니다. 버전을 확인하여 주십시오.", vbCritical, Program_Name & Program_Version)
                                    GoTo ProcessEnd
                                End If

                                If i = nudOnRe.Value Then
                                    MsgBox("전원 ON에 실패하였습니다. 다시 시도하여 주십시오.", vbCritical, Program_Name & Program_Version)
                                    GoTo ProcessEnd
                                End If

                            Else
                                Exit For
                            End If
                            delay_run(StepDelay)
                        Next

                        If BuzzerTestFunc(0) Then
                            TestError = False
                            GoTo ProcessEnd
                        End If

                        delay_run(StepDelay)

                        If TempTest() Then
                            TestError = False
                            GoTo ProcessEnd
                        End If


                        If RFTestRun() Then
                            TestError = False
                            GoTo ProcessEnd
                        End If

                        If BuzzerTestFunc(1) Then
                            TestError = False
                            GoTo ProcessEnd
                        End If

                        delay_run(StepDelay)

                        If MCTestRunSp() Then
                            TestError = False
                            GoTo ProcessEnd
                        End If

                        If BuzzerTestFunc(2) Then
                            TestError = False
                            GoTo ProcessEnd
                        End If

                        delay_run(StepDelay)

                        If EPTestRun() Then
                            GoTo ProcessEnd
                        End If

                        todayCount += 1
                        If saveLocalFile() Then
                            GoTo ProcessEnd
                        End If

                        GoTo RunSuccess

                    Else
                        MsgBox("잘못된 시작 명령어를 입력하였습니다.", vbExclamation, Program_Name & Program_Version)
                        GoTo NormalEnd
                    End If
                Else
                    MsgBox("지그를 연결한 후 동작하여 주십시오.", vbCritical, Program_Name & Program_Version)
                    GoTo NormalEnd
                End If

            Else
                MsgBox("스코프와 스펙트럼을 연결한 후 동작하여 주십시오.", vbCritical, Program_Name & Program_Version)
                GoTo NormalEnd
            End If

        Catch ex As Exception
            MsgBox("ERR!! :: " & ex.Message, vbCritical)
            GoTo ProcessEnd
        End Try

RunSuccess:
        Dim csvData As String = "" & NowDate & "," & NowTime & "," & TestData.Test_Firmware & "," & TestData.Test_Temperature(TempData.DivTemp) & "," & TestData.Test_RFVRMS(0) & "," & TestData.Test_RFFreq(0) & "," & TestData.Test_RFVRMS(1) & "," & TestData.Test_RFFreq(1) & "," & TestData.Test_RFVRMS(2) & "," & TestData.Test_RFFreq(2) & "," & TestData.Test_MCWidth(0) & "," & TestData.Test_MCVpp(0) & "," & TestData.Test_MCFreq(0) & "," & TestData.Test_MCWidth(1) & "," & TestData.Test_MCVpp(1) & "," & TestData.Test_MCFreq(1) & "," & TestData.Test_EPVpp(0) & "," & TestData.Test_EPFreq(0) & "," & TestData.Test_EPPWidth(0) & "," & TestData.Test_EPNWidth(0) & "," & TestData.Test_EPVpp(1) & "," & TestData.Test_EPFreq(1) & "," & TestData.Test_EPPWidth(1) & "," & TestData.Test_EPNWidth(1) & "," & TestData.Test_EPVpp(2) & "," & TestData.Test_EPFreq(2) & "," & TestData.Test_EPPWidth(2) & "," & TestData.Test_EPNWidth(2) & "," & TestError & ""
        If Save_Csv(csvData) Then

            txbWindow.AppendText("CSV Data Save : FAIL" & vbCrLf)
            FailMain()
        Else
            txbWindow.AppendText("CSV Data Save : OK" & vbCrLf)

            If IQC_PostReg() Then
                txbWindow.AppendText("PostgreSQL Data Save : OK" & vbCrLf)

                If CountChanage() Then

                    txbWindow.AppendText("Run Count Change Save : OK" & vbCrLf)

                    If TestError = False Then
                        FailMain()
                    Else
                        SuccessMain()
                    End If

                Else

                    txbWindow.AppendText("Run Count Change Save : FAIL" & vbCrLf)
                    FailMain()

                End If
            Else
                txbWindow.AppendText("PostgreSQL Data Save : FAIL" & vbCrLf)
                FailMain()
            End If
        End If

ProcessEnd:
        If ResponseErrorCheck Then
            RetryMain()
        ElseIf TestError = False Then
            FailMain()
        End If
        Jig_End()
NormalEnd:
        ScopeClear()
        SpecClear()
        Try
            If TestError = False Then
                Jig_End()  ' 지그 전원 차단
                TestMode_On(0)  ' MFT 모드 초기화
                txbWindow.AppendText("비정상 종료로 인한 전원 차단" & vbCrLf)
            End If
        Catch normalEx As Exception
            txbWindow.AppendText("정상 종료 처리 중 오류: " & normalEx.Message & vbCrLf)
        End Try

        txbWindow.AppendText("[" & MeasureTimeAll(MeasEnd) & "ms] Test Play" & vbCrLf)
    End Sub

    Private Sub iqcHfFunction()
        StartTime = MeasureTimeAll(MeasStart)

        If StartSwitch = True Then
            If retryPortOpen() Then

                If txbBarcode.Text = "[START]" Then

                    For i = 0 To nudOnRe.Value

                        If JigRun_On() Then
                            GoTo processEnd
                        End If

                        delay_run(StepDelay)

                        If FirmVerCheck() Then

                            Dim ReadUni As Byte() = Encoding.Unicode.GetBytes(TestData.Test_Firmware)

                            If ReadUni(0) < 57 Then
                                MsgBox("잘못된 펌웨어 버전입니다. 버전을 확인하여 주십시오.", vbCritical, Program_Name & Program_Version)
                                GoTo processEnd
                            End If

                            If i = nudOnRe.Value Then
                                MsgBox("전원 ON에 실패하였습니다. 다시 시도하여 주십시오.", vbCritical, Program_Name & Program_Version)
                                GoTo processEnd
                            End If

                        Else
                            Exit For
                        End If

                        delay_run(StepDelay)

                    Next

                    If BuzzerTestFunc(0) Then
                        TestError = False
                        GoTo processEnd
                    End If

                    delay_run(StepDelay)

                    If TempTest() Then
                        TestError = False
                        GoTo processEnd
                    End If

                    delay_run(StepDelay)

                    If HFTestRun() Then
                        TestError = False
                        GoTo processEnd
                    End If

                    delay_run(StepDelay)

                    If BuzzerTestFunc(1) Then
                        TestError = False
                        GoTo processEnd
                    End If

                    delay_run(StepDelay)

                    If BuzzerTestFunc(2) Then
                        TestError = False
                        GoTo processEnd
                    End If

                    delay_run(StepDelay)

                    todayCount += 1
                    If saveLocalFile() Then
                        GoTo processEnd
                    End If

                    GoTo SuccessEnd

                Else
                    MsgBox("잘못된 시작 명령어를 입력하였습니다.", vbExclamation, Program_Name & Program_Version)
                    GoTo ErrorEnd
                End If
            Else
                MsgBox("지그를 연결한 후 동작하여 주십시오.", vbCritical, Program_Name & Program_Version)
                GoTo ErrorEnd
            End If
        Else
            MsgBox("스펙트럼을 연결한 후 동작하여 주십시오.", vbCritical, Program_Name & Program_Version)
            GoTo ErrorEnd
        End If


SuccessEnd:

        Dim csvData As String = "" & NowDate & "," & NowTime & "," & TestData.Test_Firmware & "," & TestData.Test_Temperature(TempData.DivTemp) & "," & TestData.Test_HFData(HifuTest_Step.Step1) & "," & TestData.Test_HFData(HifuTest_Step.Step2) & "," & TestData.Test_HFData(HifuTest_Step.step3) & "," & TestError & ""

        If Save_Csv(csvData) Then

            txbWindow.AppendText("CSV Data Save : FAIL" & vbCrLf)
            FailMain()

        Else
            txbWindow.AppendText("CSV Data Save : OK" & vbCrLf)

            If IQCHF_PostReg() Then
                txbWindow.AppendText("PostgreSQL Data Save : OK" & vbCrLf)

                If CountChanage() Then

                    txbWindow.AppendText("Run Count Change Save : OK" & vbCrLf)

                    If TestError = False Then
                        FailMain()
                    Else
                        SuccessMain()
                    End If

                Else

                    txbWindow.AppendText("Run Count Change Save : FAIL" & vbCrLf)
                    FailMain()

                End If
            Else
                txbWindow.AppendText("PostgreSQL Data Save : FAIL" & vbCrLf)
                FailMain()
            End If

        End If

processEnd:
        If TestError = False Then
            FailMain()
        End If
        Jig_End()
ErrorEnd:
        ScopeClear()
        SpecClear()
        txbWindow.AppendText("[" & MeasureTimeAll(MeasEnd) & "ms] Test Play" & vbCrLf)
    End Sub

    Private Function IQCHF_PostReg() As Boolean

        If ckbPostgre.Checked = True And TestError = True Then

            DBCmd = "INSERT INTO pcbs(
                                      jig_num
                                    , test_date
                                    , test_time
                                    , board_num
                                    , test_result
                                    , fw_ver
                                    , hf1_value
                                    , hf2_value
                                    , hf3_value
                                    , created_at, updated_at) " &
                             "VALUES('" &
                                      nudJigNum.Value &
                             "', '" & NowDate &
                             "', '" & NowTime &
                             "', '" & todayCount &
                             "', '" & TestError &
                             "', '" & TestData.Test_Firmware &
                             "', '" & TestData.Test_HFData(HifuTest_Step.Step1) &
                             "', '" & TestData.Test_HFData(HifuTest_Step.Step2) &
                             "', '" & TestData.Test_HFData(HifuTest_Step.step3) &
                             "', NOW(), NOW());"

            If pgDBCommand(DBCmd) Then
                Return True
            Else
                Return False
            End If
        Else
            Return True
        End If

    End Function

    Private Sub InitializeDeviceState()
        Try
            txbWindow.AppendText("기기 상태 초기화 시작..." & vbCrLf)

            Try
                TestMode_On(0)  ' MFT 모드를 0으로 초기화
                Threading.Thread.Sleep(300)
            Catch

            End Try

            txbWindow.AppendText("기기 상태 초기화 완료" & vbCrLf)

        Catch ex As Exception
            txbWindow.AppendText("기기 초기화 중 오류 (무시하고 계속): " & ex.Message & vbCrLf)
        End Try
    End Sub

    Private Sub rfFunction()
        Try
            StartTime = MeasureTimeAll(MeasStart)

            TestData.Test_Serial = txbBarcode.Text

            InitializeDeviceState()

            If StartSwitch = True Then
                If retryPortOpen() Then

                    If TDDataSearch() Then
                        FailMain()
                        GoTo NormalEnd
                    End If

                    For i = 0 To nudOnRe.Value

                        If JigRun_On() Then
                            GoTo ProcessEnd
                        End If

                        If FirmVerCheck() Then

                            Dim ReadUni As Byte() = Encoding.Unicode.GetBytes(TestData.Test_Firmware)

                            If ReadUni(0) < 57 Then
                                MsgBox("잘못된 펌웨어 버전입니다. 버전을 확인하여 주십시오.", vbCritical, Program_Name & Program_Version)
                                GoTo ProcessEnd
                            End If

                            If i = nudOnRe.Value Then
                                MsgBox("전원 ON에 실패하였습니다. 다시 시도하여 주십시오.", vbCritical, Program_Name & Program_Version)
                                GoTo ProcessEnd
                            End If

                        Else
                            Exit For
                        End If

                    Next

                    If TDSetCheck() Then
                        FailMain()
                        GoTo ProcessEnd
                    End If

                    If RFTestRun() Then
                        FailMain()
                        GoTo ProcessEnd
                    End If

                    If MCTestRunSp() Then
                        FailMain()
                        GoTo ProcessEnd
                    End If

                    If EPTestRun() Then
                        GoTo ProcessEnd
                    End If

                    If writeTDSNFlag Then
                        TestStep = TestList.DataWritten
                        TestRunningState(testRunningList.TDWritten, Color.Green)
                    End If

                    GoTo RunSuccess

                Else
                    MsgBox("지그를 연결한 후 동작하여 주십시오.", vbCritical, Program_Name & Program_Version)
                    GoTo NormalEnd
                End If
            Else
                MsgBox("스코프와 스펙트럼을 연결한 후 동작하여 주십시오.", vbCritical, Program_Name & Program_Version)
                GoTo NormalEnd
            End If

        Catch ex As Exception
            MsgBox("ERR!! :: " & ex.Message, vbCritical)
            GoTo ProcessEnd
        End Try

RunSuccess:
        If RF_PostReg() Then

            txbWindow.AppendText("PostgreSQL Data Save : OK" & vbCrLf)

            If dbRFSave() Then
                txbWindow.AppendText("DB Data Save : OK" & vbCrLf)

                If CountChanage() Then

                    txbWindow.AppendText("Run Count Change Save : OK" & vbCrLf)
                    Dim csvData As String = "" & TestData.Test_Serial & "," & NowDate & "," & NowTime & "," & TestData.Test_Firmware & "," & TestData.Test_RFVRMS(0) & "," & TestData.Test_RFFreq(0) & "," & TestData.Test_RFVRMS(1) & "," & TestData.Test_RFFreq(1) & "," & TestData.Test_RFVRMS(2) & "," & TestData.Test_RFFreq(2) & "," & TestData.Test_MCWidth(0) & "," & TestData.Test_MCVpp(0) & "," & TestData.Test_MCFreq(0) & "," & TestData.Test_MCWidth(1) & "," & TestData.Test_MCVpp(1) & "," & TestData.Test_MCFreq(1) & "," & TestData.Test_EPVpp(0) & "," & TestData.Test_EPFreq(0) & "," & TestData.Test_EPPWidth(0) & "," & TestData.Test_EPNWidth(0) & "," & TestData.Test_EPVpp(1) & "," & TestData.Test_EPFreq(1) & "," & TestData.Test_EPPWidth(1) & "," & TestData.Test_EPNWidth(1) & "," & TestData.Test_EPVpp(2) & "," & TestData.Test_EPFreq(2) & "," & TestData.Test_EPPWidth(2) & "," & TestData.Test_EPNWidth(2) & "," & TestError & ""

                    If Save_Csv(csvData) Then

                        txbWindow.AppendText("CSV Data Save : FAIL" & vbCrLf)
                        FailMain()

                    Else

                        txbWindow.AppendText("Run Count Change Save : OK" & vbCrLf)

                        If TestError = False Then
                            FailMain()
                        Else
                            SuccessMain()
                        End If

                    End If
                Else

                    txbWindow.AppendText("Run Count Change Save : FAIL" & vbCrLf)
                    FailMain()

                End If

            Else
                txbWindow.AppendText("DB Data Save : FAIL" & vbCrLf)
                FailMain()
            End If

        Else
            txbWindow.AppendText("PostgreSQL Data Save : FAIL" & vbCrLf)
            FailMain()
        End If

ProcessEnd:
        If ResponseErrorCheck Then
            RetryMain()
        End If
        Jig_End()
NormalEnd:
        ScopeClear()
        SpecClear()

        Try
            If TestError = False Then
                Jig_End()  ' 지그 전원 차단
                TestMode_On(0)  ' MFT 모드 초기화
                txbWindow.AppendText("비정상 종료로 인한 전원 차단" & vbCrLf)
            End If
        Catch normalEx As Exception
            txbWindow.AppendText("정상 종료 처리 중 오류: " & normalEx.Message & vbCrLf)
        End Try

        txbWindow.AppendText("[" & MeasureTimeAll(MeasEnd) & "ms] Test Play" & vbCrLf)
    End Sub
    Private Sub ldmVrmsFunction()
        Try
            StartTime = MeasureTimeAll(MeasStart)

            TestData.Test_Serial = txbBarcode.Text

            If StartSwitch = True Then
                If retryPortOpen() Then

                    If LDMDataSearch() Then
                        FailMain()
                        GoTo NormalEnd
                    End If

                    For i = 0 To nudOnRe.Value

                        If JigRun_On() Then
                            GoTo ProcessEnd
                        End If

                        If FirmVerCheck() Then

                            Dim ReadUni As Byte() = Encoding.Unicode.GetBytes(TestData.Test_Firmware)

                            If ReadUni(0) < 57 Then
                                MsgBox("잘못된 펌웨어 버전입니다. 버전을 확인하여 주십시오.", vbCritical, Program_Name & Program_Version)
                                GoTo ProcessEnd
                            End If

                            If i = nudOnRe.Value Then
                                MsgBox("전원 ON에 실패하였습니다. 다시 시도하여 주십시오.", vbCritical, Program_Name & Program_Version)
                                GoTo ProcessEnd
                            End If

                        Else
                            Exit For
                        End If

                    Next

                    If BatteryTest() Then
                        FailMain()
                        GoTo ProcessEnd
                    End If

                    If TempTest() Then
                        FailMain()
                        GoTo ProcessEnd
                    End If

                    If RFTestRun() Then
                        FailMain()
                        GoTo ProcessEnd
                    End If

                    'If LDMDataWrite() Then
                    '    FailMain()
                    '    GoTo ProcessEnd
                    'End If

                    GoTo RunSuccess

                Else
                    MsgBox("지그를 연결한 후 동작하여 주십시오.", vbCritical, Program_Name & Program_Version)
                    GoTo NormalEnd
                End If
            Else
                MsgBox("스코프와 스펙트럼을 연결한 후 동작하여 주십시오.", vbCritical, Program_Name & Program_Version)
                GoTo NormalEnd
            End If

        Catch ex As Exception
            MsgBox("ERR!! :: " & ex.Message, vbCritical)
            GoTo ProcessEnd
        End Try

RunSuccess:
        If RF_PostReg() Then

            txbWindow.AppendText("PostgreSQL Data Save : OK" & vbCrLf)

            If dbRFLDMSave() Then
                txbWindow.AppendText("DB Data Save : OK" & vbCrLf)

                If CountChanage() Then

                    txbWindow.AppendText("Run Count Change Save : OK" & vbCrLf)
                    Dim csvData As String = "" & TestData.Test_Serial & "," & NowDate & "," & NowTime & "," & TestData.Test_Firmware & "," & TestData.Test_Temperature(0) & "," & TestData.Test_Temperature(1) & "," & TestData.Test_Battery & "," & TestData.Test_RFVRMS(0) & "," & TestData.Test_RFFreq(0) & "," & TestData.Test_RFVRMS(1) & "," & TestData.Test_RFFreq(1) & "," & TestData.Test_RFVRMS(2) & "," & TestData.Test_RFFreq(2) & "," & TestError & ""

                    If Save_Csv(csvData) Then

                        txbWindow.AppendText("CSV Data Save : FAIL" & vbCrLf)
                        FailMain()

                    Else

                        txbWindow.AppendText("Run Count Change Save : OK" & vbCrLf)

                        If TestError = False Then
                            FailMain()
                        Else
                            SuccessMain()
                        End If

                    End If
                Else

                    txbWindow.AppendText("Run Count Change Save : FAIL" & vbCrLf)
                    FailMain()

                End If

            Else
                txbWindow.AppendText("DB Data Save : FAIL" & vbCrLf)
                FailMain()
            End If

        Else
            txbWindow.AppendText("PostgreSQL Data Save : FAIL" & vbCrLf)
            FailMain()
        End If

ProcessEnd:
        Jig_End()
NormalEnd:
        ScopeClear()
        SpecClear()

        Try
            If TestError = False Then
                Jig_End()  ' 지그 전원 차단
                TestMode_On(0)  ' MFT 모드 초기화
                txbWindow.AppendText("비정상 종료로 인한 전원 차단" & vbCrLf)
            End If
        Catch normalEx As Exception
            txbWindow.AppendText("정상 종료 처리 중 오류: " & normalEx.Message & vbCrLf)
        End Try

        'ScopeClear()
        txbWindow.AppendText("[" & MeasureTimeAll(MeasEnd) & "ms] Test Play" & vbCrLf)
    End Sub

    Private Function TDSetCheck() As Boolean
        Dim TDResult As String
        writeTDSNFlag = False
        If formType = formTypeList.prdLDM Then
            TDResult = LDM_name_load()
        Else
            TDResult = TD_name_load()
        End If

        If TDResult = "1" Then
            txbWindow.AppendText("Send 중 오류가 발생하였습니다." & "" & vbCrLf)
            txbTDSN.ForeColor = Color.Red
            Return True
        End If

        If TDResult = "0" Then
            txbWindow.AppendText("작성된 TD 정보 없음" & "" & vbCrLf)
            Return True
        End If

        If TDResult.Length <> 10 Then
            txbWindow.AppendText("TDResult Length ERROR !! : " & TDResult & "" & vbCrLf)
            txbTDSN.ForeColor = Color.Red
            Return True
        End If

        If TestData.Test_Serial.ToUpper = TDResult.ToUpper Then
            txbWindow.AppendText("TD INPUT : " & TestData.Test_Serial & ", TD WRITTEN : " & TDResult & "" & vbCrLf)
            txbTDSN.ForeColor = Color.Blue
            writeTDSNFlag = True
            Return False
        Else
            txbWindow.AppendText("입력된 TD 번호와 일치하지 않습니다.(" & TDResult & ")" & vbCrLf)
            txbTDSN.ForeColor = Color.Red
            Return True
        End If

    End Function

    Private Function RF_PostReg() As Boolean

        If ckbPostgre.Checked = True Then
            DBCmd = "select exists(select 1 from prods where td_serial = '" & TestData.Test_Serial & "') AS A;"
            Dim TDExistBol As Boolean = pgDBQueryScalar(DBCmd)

            If TDExistBol = False Then
                DBCmd = "INSERT INTO prods(td_serial, p2_jignum, p2_testdate, p2_testtime, p2_result, p2_rf1_vrms, p2_rf1_freq, p2_rf2_vrms, p2_rf2_freq, p2_rf3_vrms, p2_rf3_freq, p2_mc1_vpp, p2_mc1_freq,p2_mc1_width, p2_mc2_vpp, p2_mc2_freq, p2_mc2_width, p2_ep1_vpp, p2_ep1_freq, p2_ep1_pwidth, p2_ep1_nwidth, p2_ep2_vpp, p2_ep2_freq, p2_ep2_pwidth, p2_ep2_nwidth, p2_ep3_vpp, p2_ep3_freq, p2_ep3_pwidth, p2_ep3_nwidth, created_at, updated_at) " &
                    "VALUES('" & TestData.Test_Serial & "', '" & nudJigNum.Value & "', '" & NowDate & "', '" & NowTime & "','" & TestError & "', '" & TestData.Test_RFVRMS(0) & "', '" & TestData.Test_RFFreq(0) & "', '" & TestData.Test_RFVRMS(1) & "', '" & TestData.Test_RFFreq(1) & "', '" & TestData.Test_RFVRMS(2) & "', '" & TestData.Test_RFFreq(2) & "', '" & TestData.Test_MCVpp(0) & "', '" & TestData.Test_MCFreq(0) & "', '" & TestData.Test_MCWidth(0) & "','" & TestData.Test_MCVpp(1) & "', '" & TestData.Test_MCFreq(1) & "', '" & TestData.Test_MCWidth(1) & "','" & TestData.Test_EPVpp(0) & "','" & TestData.Test_EPFreq(0) & "','" & TestData.Test_EPPWidth(0) & "','" & TestData.Test_EPNWidth(0) & "','" & TestData.Test_EPVpp(1) & "','" & TestData.Test_EPFreq(1) & "','" & TestData.Test_EPPWidth(1) & "','" & TestData.Test_EPNWidth(1) & "','" & TestData.Test_EPVpp(2) & "','" & TestData.Test_EPFreq(2) & "','" & TestData.Test_EPPWidth(2) & "','" & TestData.Test_EPNWidth(2) & "',NOW(),NOW());"
            Else
                DBCmd = "UPDATE prods SET td_serial = '" & TestData.Test_Serial & "', p2_jignum = '" & nudJigNum.Value & "', p2_testdate = '" & NowDate & "', p2_testtime = '" & NowTime & "', " &
                    "p2_result = '" & TestError & "', p2_rf1_vrms = '" & TestData.Test_RFVRMS(0) & "', p2_rf1_freq = '" & TestData.Test_RFFreq(0) & "', p2_rf2_vrms = '" & TestData.Test_RFVRMS(1) & "', " &
                    "p2_rf2_freq = '" & TestData.Test_RFFreq(1) & "', p2_rf3_vrms = '" & TestData.Test_RFVRMS(2) & "', p2_rf3_freq = '" & TestData.Test_RFFreq(2) & "', p2_mc1_vpp = '" & TestData.Test_MCVpp(0) & "', p2_mc1_freq = '" & TestData.Test_MCFreq(0) & "',p2_mc1_width = '" & TestData.Test_MCWidth(0) & "',p2_mc2_vpp = '" & TestData.Test_MCVpp(1) & "', p2_mc2_freq = '" & TestData.Test_MCFreq(1) & "',p2_mc2_width = '" & TestData.Test_MCWidth(1) & "',p2_ep1_vpp = '" & TestData.Test_EPVpp(0) & "',p2_ep1_freq = '" & TestData.Test_EPFreq(0) & "',p2_ep1_pwidth = '" & TestData.Test_EPPWidth(0) & "',p2_ep1_nwidth = '" & TestData.Test_EPNWidth(0) & "',p2_ep2_vpp = '" & TestData.Test_EPVpp(1) & "',p2_ep2_freq = '" & TestData.Test_EPFreq(1) & "',p2_ep2_pwidth = '" & TestData.Test_EPNWidth(1) & "',p2_ep2_nwidth = '" & TestData.Test_EPNWidth(1) & "',p2_ep3_vpp = '" & TestData.Test_EPVpp(2) & "',p2_ep3_freq = '" & TestData.Test_EPFreq(2) & "',p2_ep3_pwidth = '" & TestData.Test_EPPWidth(2) & "', p2_ep3_nwidth = '" & TestData.Test_EPNWidth(2) & "', updated_at = NOW() WHERE td_serial = '" & TestData.Test_Serial & "';"
            End If

            txbWindow.AppendText(DBCmd & vbCrLf)

            If pgDBCommand(DBCmd) Then
                Return True
            Else
                Return False
            End If
        Else
            Return True
        End If
    End Function

    Private Function RFMc_PostReg() As Boolean

        If ckbPostgre.Checked = True Then
            DBCmd = "select exists(select 1 from prods where td_serial = '" & TestData.Test_Serial & "') AS A;"
            Dim TDExistBol As Boolean = pgDBQueryScalar(DBCmd)

            If TDExistBol = False Then
                DBCmd = "INSERT INTO prods(td_serial, p2_jignum, p2_testdate, p2_testtime, p2_result, p2_rf1_vrms, p2_rf1_freq, p2_rf2_vrms, p2_rf2_freq, p2_rf3_vrms, p2_rf3_freq, created_at, updated_at) " &
                    "VALUES('" & TestData.Test_Serial & "', '" & nudJigNum.Value & "', '" & NowDate & "', '" & NowTime & "','" & TestError & "', '" & TestData.Test_RFVRMS(0) & "', '" & TestData.Test_RFFreq(0) & "', '" & TestData.Test_RFVRMS(1) & "', '" & TestData.Test_RFFreq(1) & "', '" & TestData.Test_RFVRMS(2) & "', '" & TestData.Test_RFFreq(2) & "', NOW(), NOW());"
            Else
                DBCmd = "UPDATE prods SET td_serial = '" & TestData.Test_Serial & "', p2_jignum = '" & nudJigNum.Value & "', p2_testdate = '" & NowDate & "', p2_testtime = '" & NowTime & "', " &
                    "p2_result = '" & TestError & "', p2_rf1_vrms = '" & TestData.Test_RFVRMS(0) & "', p2_rf1_freq = '" & TestData.Test_RFFreq(0) & "', p2_rf2_vrms = '" & TestData.Test_RFVRMS(1) & "', " &
                    "p2_rf2_freq = '" & TestData.Test_RFFreq(1) & "', p2_rf3_vrms = '" & TestData.Test_RFVRMS(2) & "', p2_rf3_freq = '" & TestData.Test_RFFreq(2) & "',updated_at = NOW() WHERE td_serial = '" & TestData.Test_Serial & "';"
            End If

            txbWindow.AppendText(DBCmd & vbCrLf)

            If pgDBCommand(DBCmd) Then
                Return True
            Else
                Return False
            End If
        Else
            Return True
        End If
    End Function

    Private Function EP_PostReg() As Boolean

        If ckbPostgre.Checked = True Then
            DBCmd = "select exists(select 1 from prods where td_serial = '" & TestData.Test_Serial & "') AS A;"
            Dim TDExistBol As Boolean = pgDBQueryScalar(DBCmd)

            If TDExistBol = False Then
                DBCmd = "INSERT INTO prods(td_serial, p2_jignum, p2_testdate, p2_testtime, p2_result, p2_ep1_vpp, p2_ep1_freq, p2_ep1_pwidth, p2_ep1_nwidth, p2_ep2_vpp, p2_ep2_freq, p2_ep2_pwidth, p2_ep2_nwidth, p2_ep3_vpp, p2_ep3_freq, p2_ep3_pwidth, p2_ep3_nwidth, created_at, updated_at) " &
                    "VALUES('" & TestData.Test_Serial & "', '" & nudJigNum.Value & "', '" & NowDate & "', '" & NowTime & "','" & TestError & "', '" & TestData.Test_EPVpp(0) & "','" & TestData.Test_EPFreq(0) & "','" & TestData.Test_EPPWidth(0) & "','" & TestData.Test_EPNWidth(0) & "','" & TestData.Test_EPVpp(1) & "','" & TestData.Test_EPFreq(1) & "','" & TestData.Test_EPPWidth(1) & "','" & TestData.Test_EPNWidth(1) & "','" & TestData.Test_EPVpp(2) & "','" & TestData.Test_EPFreq(2) & "','" & TestData.Test_EPPWidth(2) & "','" & TestData.Test_EPNWidth(2) & "',NOW(),NOW());"
            Else
                DBCmd = "UPDATE prods SET td_serial = '" & TestData.Test_Serial & "', p2_jignum = '" & nudJigNum.Value & "', p2_testdate = '" & NowDate & "', p2_testtime = '" & NowTime & "', " &
                    "p2_result = '" & TestError & "',p2_ep1_vpp = '" & TestData.Test_EPVpp(0) & "',p2_ep1_freq = '" & TestData.Test_EPFreq(0) & "',p2_ep1_pwidth = '" & TestData.Test_EPPWidth(0) & "',p2_ep1_nwidth = '" & TestData.Test_EPNWidth(0) & "',p2_ep2_vpp = '" & TestData.Test_EPVpp(1) & "',p2_ep2_freq = '" & TestData.Test_EPFreq(1) & "',p2_ep2_pwidth = '" & TestData.Test_EPNWidth(1) & "',p2_ep2_nwidth = '" & TestData.Test_EPNWidth(1) & "',p2_ep3_vpp = '" & TestData.Test_EPVpp(2) & "',p2_ep3_freq = '" & TestData.Test_EPFreq(2) & "',p2_ep3_pwidth = '" & TestData.Test_EPPWidth(2) & "', p2_ep3_nwidth = '" & TestData.Test_EPNWidth(2) & "', updated_at = NOW() WHERE td_serial = '" & TestData.Test_Serial & "';"
            End If

            txbWindow.AppendText(DBCmd & vbCrLf)

            If pgDBCommand(DBCmd) Then
                Return True
            Else
                Return False
            End If
        Else
            Return True
        End If
    End Function


    Private Sub hfFunction()
        StartTime = MeasureTimeAll(MeasStart)
        TestData.Test_Serial = txbBarcode.Text

        If StartSwitch = True Then
            If retryPortOpen() Then

                If TDDataSearch() Then
                    FailMain()
                    GoTo NormalEnd
                End If

                For i = 0 To nudOnRe.Value

                    If JigRun_On() Then
                        GoTo ProcessEnd
                    End If

                    delay_run(StepDelay)

                    If FirmVerCheck() Then

                        Dim ReadUni As Byte() = Encoding.Unicode.GetBytes(TestData.Test_Firmware)

                        If ReadUni(0) < 57 Then
                            MsgBox("잘못된 펌웨어 버전입니다. 버전을 확인하여 주십시오.", vbCritical, Program_Name & Program_Version)
                            GoTo ProcessEnd
                        End If

                        If i = nudOnRe.Value Then
                            MsgBox("전원 ON에 실패하였습니다. 다시 시도하여 주십시오.", vbCritical, Program_Name & Program_Version)
                            GoTo ProcessEnd
                        End If

                    Else
                        Exit For
                    End If

                    delay_run(StepDelay)

                Next

                'If TDSetCheck() Then
                '    FailMain()
                '    GoTo ProcessEnd
                'End If

                If BatteryTest() Then
                    FailMain()
                    GoTo ProcessEnd
                End If

                If TempTest() Then
                    FailMain()
                    GoTo ProcessEnd
                End If

                If HFTestRun() Then
                    FailMain()
                    GoTo ProcessEnd
                End If


                If DataWrite(ModelCode.PadRight(2, "0"c)) Then
                    FailMain()
                    GoTo ProcessEnd
                End If

                GoTo RunSuccess

            Else
                MsgBox("지그를 연결한 후 동작하여 주십시오.", vbCritical, Program_Name & Program_Version)
                FailMain()
                GoTo NormalEnd
            End If
        Else
            MsgBox("스코프와 스펙트럼을 연결한 후 동작하여 주십시오.", vbCritical, Program_Name & Program_Version)
            FailMain()
            GoTo NormalEnd
        End If

RunSuccess:
        If HIFU_PostReg() Then

            txbWindow.AppendText("PostgreSQL Data Save : OK" & vbCrLf)

            If dbHFSave() Then
                txbWindow.AppendText("DB Data Save : OK" & vbCrLf)

                If CountChanage() Then

                    txbWindow.AppendText("Run Count Change : OK" & vbCrLf)
                    Dim csvData As String = "" & TestData.Test_Serial & "," & NowDate & "," & NowTime & "," & TestData.Test_Firmware & "," & TestData.Test_Battery & "," & TestData.Test_Temperature(TempData.DivTemp) & "," & TestData.Test_Temperature(TempData.CartTemp) & "," & TestData.Test_HFData(HifuTest_Step.Step1) & "," & TestData.Test_HFData(HifuTest_Step.Step2) & "," & TestData.Test_HFData(HifuTest_Step.step3) & "," & TestError & ""

                    If Save_Csv(csvData) Then

                        txbWindow.AppendText("CSV Data Save : FAIL" & vbCrLf)
                        FailMain()

                    Else

                        txbWindow.AppendText("CSV Data Save : OK" & vbCrLf)

                        If TestError = False Then
                            FailMain()
                        Else
                            SuccessMain()
                        End If

                    End If

                Else

                    txbWindow.AppendText("Run Count Change : FAIL" & vbCrLf)
                    FailMain()

                End If

            Else
                txbWindow.AppendText("DB Data Save : FAIL" & vbCrLf)
                FailMain()
            End If

        Else

            txbWindow.AppendText("PostgreSQL Data Save : FAIL" & vbCrLf)
            FailMain()

        End If

ProcessEnd:
        Jig_End()

NormalEnd:
        ScopeClear()
        SpecClear()
        txbWindow.AppendText("[" & MeasureTimeAll(MeasEnd) & "ms] Test Play" & vbCrLf)
    End Sub

    Private Function HIFU_PostReg() As Boolean

        If ckbPostgre.Checked = True Then
            DBCmd = "select exists(select 1 from prods where td_serial = '" & TestData.Test_Serial & "') AS A;"
            Dim TDExistBol As Boolean = pgDBQueryScalar(DBCmd)

            If TDExistBol = False Then
                DBCmd = "INSERT INTO prods(td_serial, p1_jignum, p1_testdate, p1_testtime, p1_result, p1_fwver, p1_batterylv, p1_divtemp, p1_carttemp, p1_hf1_value, p1_hf2_value, p1_hf3_value, created_at, updated_at)" &
                    "VALUES('" & TestData.Test_Serial & "', '" & nudJigNum.Value & "', '" & NowDate & "', '" & NowTime & "','" & TestError & "', '" & TestData.Test_Firmware & "', '" & TestData.Test_Battery & "', '" & TestData.Test_Temperature(TempData.DivTemp) & "', '" & TestData.Test_Temperature(TempData.CartTemp) & "', '" & TestData.Test_HFData(HifuTest_Step.Step1) & "', '" & TestData.Test_HFData(HifuTest_Step.Step2) & "', '" & TestData.Test_HFData(HifuTest_Step.step3) & "', NOW(), NOW());"
            Else
                DBCmd = "UPDATE prods SET td_serial = '" & TestData.Test_Serial & "', p1_jignum = '" & nudJigNum.Value & "', p1_testdate = '" & NowDate & "', p1_testtime = '" & NowTime & "', " &
                    "p1_result = '" & TestError & "', p1_fwver = '" & TestData.Test_Firmware & "', p1_batterylv = '" & TestData.Test_Battery & "', p1_divtemp = '" & TestData.Test_Temperature(TempData.DivTemp) & "', " &
                    "p1_carttemp = '" & TestData.Test_Temperature(TempData.CartTemp) & "', p1_hf1_value = '" & TestData.Test_HFData(HifuTest_Step.Step1) & "', p1_hf2_value = '" & TestData.Test_HFData(HifuTest_Step.Step2) & "', p1_hf3_value = '" & TestData.Test_HFData(HifuTest_Step.step3) & "', updated_at = NOW() WHERE td_serial = '" & TestData.Test_Serial & "';"
            End If

            If pgDBCommand(DBCmd) Then
                Return True
            Else
                Return False
            End If
        Else
            Return True
        End If
    End Function

    Private Sub ldmFunction()
        StartTime = MeasureTimeAll(MeasStart)
        TestData.Test_Serial = txbBarcode.Text

        If StartSwitch = True Then
            If retryPortOpen() Then
                'If LDMTestStepCheck() Then
                '    MsgBox("공정 순서 오류, LDM 생산1을 먼저 진행해 주십시오.", vbExclamation, Program_Name & Program_Version)
                '    GoTo NormalEnd
                'End If



                If LDMDataSearch() Then
                    FailMain()
                    GoTo NormalEnd
                End If
                For i = 0 To nudOnRe.Value

                    If JigRun_On() Then
                        GoTo ProcessEnd
                    End If

                    delay_run(StepDelay)

                    If FirmVerCheck() Then

                        Dim ReadUni As Byte() = Encoding.Unicode.GetBytes(TestData.Test_Firmware)

                        If ReadUni(0) < 57 Then
                            MsgBox("잘못된 펌웨어 버전입니다. 버전을 확인하여 주십시오.", vbCritical, Program_Name & Program_Version)
                            GoTo ProcessEnd
                        End If

                        If i = nudOnRe.Value Then
                            MsgBox("전원 ON에 실패하였습니다. 다시 시도하여 주십시오.", vbCritical, Program_Name & Program_Version)
                            GoTo ProcessEnd
                        End If

                    Else
                        Exit For
                    End If

                    delay_run(StepDelay)

                Next
                If ModelName = "SEMOPLUS" Then
                    If TDSetCheck() Then
                        FailMain()
                        GoTo ProcessEnd
                    End If
                End If

                If BatteryTest() Then
                    FailMain()
                    GoTo ProcessEnd
                End If

                If TempTest() Then
                    FailMain()
                    GoTo ProcessEnd
                End If

                'If TDSetCheck() Then
                '    FailMain()
                '    GoTo ProcessEnd
                'End If

                If HFTestRunLDM() Then
                    FailMain()
                    GoTo ProcessEnd
                End If

                If ModelName = "SEMOPLUS" Then
                    TestStep = TestList.DataWritten
                    TestRunningState(testRunningList.TDWritten, Color.Green)
                Else
                    If LDMDataWrite(ModelCode.PadRight(2, "0"c)) Then
                        FailMain()
                        GoTo ProcessEnd
                    End If
                End If

                GoTo RunSuccess

            Else
                MsgBox("지그를 연결한 후 동작하여 주십시오.", vbCritical, Program_Name & Program_Version)
                FailMain()
                GoTo NormalEnd
            End If
        Else
            MsgBox("스코프와 스펙트럼을 연결한 후 동작하여 주십시오.", vbCritical, Program_Name & Program_Version)
            FailMain()
            GoTo NormalEnd
        End If
RunSuccess:
        Try
            If HIFU_PostReg() Then

                txbWindow.AppendText("PostgreSQL Data Save : OK" & vbCrLf)

                If dbLDMSave() Then
                    txbWindow.AppendText("DB Data Save : OK" & vbCrLf)

                    If CountChanage() Then

                        txbWindow.AppendText("Run Count Change : OK" & vbCrLf)
                        Dim csvData As String = "" & TestData.Test_Serial & "," & NowDate & "," & NowTime & "," & TestData.Test_Firmware & "," & TestData.Test_Temperature(TempData.DivTemp) & "," & TestData.Test_HFData(HifuTest_Step.Step1) & "," & TestData.Test_HFData(HifuTest_Step.Step2) & "," & TestData.Test_HFData(HifuTest_Step.step3) & "," & TestError & ""
                        If Save_Csv(csvData) Then

                            txbWindow.AppendText("CSV Data Save : FAIL" & vbCrLf)
                            FailMain()

                        Else

                            txbWindow.AppendText("CSV Data Save : OK" & vbCrLf)

                            If TestError = False Then
                                FailMain()
                            Else
                                SuccessMain()
                            End If

                        End If

                    Else

                        txbWindow.AppendText("Run Count Change : FAIL" & vbCrLf)
                        FailMain()

                    End If

                Else
                    txbWindow.AppendText("DB Data Save : FAIL" & vbCrLf)
                    FailMain()
                End If

            Else

                txbWindow.AppendText("PostgreSQL Data Save : FAIL" & vbCrLf)
                FailMain()

            End If
        Catch ex As TypeInitializationException
            txbWindow.AppendText("DB 초기화 오류: " & ex.Message & vbCrLf)
            If ex.InnerException IsNot Nothing Then
                txbWindow.AppendText("  내부: " & ex.InnerException.Message & vbCrLf)
            End If
            FailMain()
        Catch ex As Exception
            txbWindow.AppendText("PostgreSQL/DB 저장 중 오류: " & ex.Message & vbCrLf)
            FailMain()
        End Try

ProcessEnd:
        Jig_End()

NormalEnd:
        txbWindow.AppendText("[" & MeasureTimeAll(MeasEnd) & "ms] Test Play" & vbCrLf)
        ScopeClear()
        SpecClear()
    End Sub


    Private Function LDMDataSearch() As Boolean

        MeasureTimeFunc(MeasStart)

        If TDExist() Then

            TDCompare()

            If LDMDBDataLoad() Then
                MsgBox("해당 시리얼 번호는 데이터가 존재하지 않습니다. TD 수입검사 진행 여부를 확인하여 주십시오.", vbCritical, Program_Name & Program_Version)
                MeasureTimeFunc(MeasEnd)
                Return True
            End If

            txbTDSN.Text = TestData.Test_Serial
            txbTDSN.Refresh()
            txbDate.Text = LDM_DataSet(LDM_Data.pvDate)
            txbDate.Refresh()
            txbFreq.Text = LDM_DataSet(LDM_Data.freq_1)
            txbFreq.Refresh()

            txbWindow.AppendText("TD Data Time(s) : " & MeasureTimeFunc(MeasEnd) & vbCrLf)
            Return False

        Else
            MsgBox("TD 데이터가 존재하지 않습니다. 성적서를 등록하여 주십시오.", vbExclamation, Program_Name & Program_Version)
            MeasureTimeFunc(MeasEnd)
            Return True
        End If

    End Function


    Private Sub hfEpFunction()
        StartTime = MeasureTimeAll(MeasStart)
        TestData.Test_Serial = txbBarcode.Text
        If StartSwitch = True Then
            If retryPortOpen() Then
                If TDDataSearch() Then
                    FailMain()
                    GoTo NormalEnd
                End If

                For i = 0 To nudOnRe.Value

                    If JigRun_On() Then
                        GoTo ProcessEnd
                    End If

                    delay_run(StepDelay)

                    If FirmVerCheck() Then

                        Dim ReadUni As Byte() = Encoding.Unicode.GetBytes(TestData.Test_Firmware)

                        If ReadUni(0) < 57 Then
                            MsgBox("잘못된 펌웨어 버전입니다. 버전을 확인하여 주십시오.", vbCritical, Program_Name & Program_Version)
                            GoTo ProcessEnd
                        End If

                        If i = nudOnRe.Value Then
                            MsgBox("전원 ON에 실패하였습니다. 다시 시도하여 주십시오.", vbCritical, Program_Name & Program_Version)
                            GoTo ProcessEnd
                        End If

                    Else
                        Exit For
                    End If

                    delay_run(StepDelay)

                Next

                If BatteryTest() Then
                    FailMain()
                    GoTo ProcessEnd
                End If

                If TempTest() Then
                    FailMain()
                    GoTo ProcessEnd
                End If

                If TDSetCheck() Then
                    FailMain()
                    GoTo ProcessEnd
                End If

                If HFTestRun() Then
                    FailMain()
                    GoTo ProcessEnd
                End If

                If writeTDSNFlag Then
                    TestStep = TestList.DataWritten
                    TestRunningState(testRunningList.TDWritten, Color.Green)
                End If


                GoTo runSuccess
            Else
                MsgBox("지그를 연결한 후 동작하여 주십시오.", vbCritical, Program_Name & Program_Version)
                FailMain()
                GoTo NormalEnd
            End If
        Else
            MsgBox("스코프와 스펙트럼을 연결한 후 동작하여 주십시오.", vbCritical, Program_Name & Program_Version)
            FailMain()
            GoTo NormalEnd
        End If
runSuccess:
        If HIFU_PostReg() Then
            txbWindow.AppendText("PostgreSQL HIFU Data Save : OK" & vbCrLf)
            If dbHFSave() Then
                txbWindow.AppendText("DB Data Save : OK" & vbCrLf)

                If CountChanage() Then
                    txbWindow.AppendText("Run Count Change : OK" & vbCrLf)
                    Dim csvData As String = "" & TestData.Test_Serial & "," & NowDate & "," & NowTime & "," & TestData.Test_Firmware & "," & TestData.Test_Battery & "," & TestData.Test_Temperature(TempData.DivTemp) & "," & TestData.Test_Temperature(TempData.CartTemp) & "," & TestData.Test_HFData(HifuTest_Step.Step1) & "," & TestData.Test_HFData(HifuTest_Step.Step2) & "," & TestData.Test_HFData(HifuTest_Step.step3) & "," & TestError & ""

                    If Save_Csv(csvData) Then
                        txbWindow.AppendText("CSV Data Save : FAIL" & vbCrLf)
                        FailMain()
                    Else
                        txbWindow.AppendText("Run Count Change Save : OK" & vbCrLf)

                        If TestError = False Then
                            FailMain()
                        Else
                            SuccessMain()
                        End If
                    End If
                Else
                    txbWindow.AppendText("Run Count Change Save : FAIL" & vbCrLf)
                    FailMain()
                End If
            Else
                txbWindow.AppendText("DB HIFU Data Save : FAIL" & vbCrLf)
                FailMain()
            End If
        Else
            txbWindow.AppendText("PostgreSQL  Data Save : FAIL" & vbCrLf)
            FailMain()
        End If
ProcessEnd:
        Jig_End()

NormalEnd:
        txbWindow.AppendText("[" & MeasureTimeAll(MeasEnd) & "ms] Test Play" & vbCrLf)

    End Sub

    Private Function retryPortOpen() As Boolean
        If (cbbJgBaudRate.SelectedItem Is Nothing) OrElse (ParaComport Is Nothing Or ParaComport = "") Then
            Return False
        End If

        If JigSerial.IsOpen = False Then
            If cbbJgBaudRate.SelectedIndex = -1 Then
                cbbJgBaudRate.SelectedIndex = 1
            End If
            OpenSerial(cbbJgBaudRate.SelectedItem)
        End If

        Return JigSerial.IsOpen
    End Function



    Private Sub hfLdmEpFunction()
        Try
            StartTime = MeasureTimeAll(MeasStart)
            TestData.Test_Serial = txbBarcode.Text

            If StartSwitch = True Then
                If retryPortOpen() Then
                    If TDDataSearch() Then
                        FailMain()
                        GoTo NormalEnd
                    End If

                    For i = 0 To nudOnRe.Value

                        If JigRun_On() Then
                            GoTo ProcessEnd
                        End If

                        If FirmVerCheck() Then

                            Dim ReadUni As Byte() = Encoding.Unicode.GetBytes(TestData.Test_Firmware)

                            If ReadUni(0) < 57 Then
                                MsgBox("잘못된 펌웨어 버전입니다. 버전을 확인하여 주십시오.", vbCritical, Program_Name & Program_Version)
                                GoTo ProcessEnd
                            End If

                            If i = nudOnRe.Value Then
                                MsgBox("전원 ON에 실패하였습니다. 다시 시도하여 주십시오.", vbCritical, Program_Name & Program_Version)
                                GoTo ProcessEnd
                            End If

                        Else
                            Exit For
                        End If

                    Next

                    If BatteryTest() Then
                        FailMain()
                        GoTo ProcessEnd
                    End If

                    If TempTest() Then
                        FailMain()
                        GoTo ProcessEnd
                    End If

                    If EPTestRun() Then
                        GoTo ProcessEnd
                    End If


                    If DataWrite(ModelCode.PadRight(2, "0"c)) Then
                        FailMain()
                        GoTo ProcessEnd
                    End If

                    GoTo RunSuccess
                Else
                    MsgBox("지그를 연결한 후 동작하여 주십시오.", vbCritical, Program_Name & Program_Version)
                    GoTo NormalEnd
                End If
            Else
                MsgBox("스코프와 스펙트럼을 연결한 후 동작하여 주십시오.", vbCritical, Program_Name & Program_Version)
                GoTo NormalEnd
            End If

        Catch ex As Exception
            MsgBox("ERR!! :: " & ex.Message, vbCritical)
            GoTo ProcessEnd
        End Try
RunSuccess:
        If EP_PostReg() Then
            txbWindow.AppendText("PostgreSQL Data Save : OK" & vbCrLf)
            If dbEPSave() Then
                txbWindow.AppendText("DB Data Save : OK" & vbCrLf)
                If CountChanage() Then

                    txbWindow.AppendText("Run Count Change Save : OK" & vbCrLf)
                    Dim csvData As String = "" & TestData.Test_Serial & "," & NowDate & "," & NowTime & "," & TestData.Test_Firmware & "," & TestData.Test_EPVpp(0) & "," & TestData.Test_EPFreq(0) & "," & TestData.Test_EPPWidth(0) & "," & TestData.Test_EPNWidth(0) & "," & TestData.Test_EPVpp(1) & "," & TestData.Test_EPFreq(1) & "," & TestData.Test_EPPWidth(1) & "," & TestData.Test_EPNWidth(1) & "," & TestData.Test_EPVpp(2) & "," & TestData.Test_EPFreq(2) & "," & TestData.Test_EPPWidth(2) & "," & TestData.Test_EPNWidth(2) & "," & TestError & ""

                    If Save_Csv(csvData) Then

                        txbWindow.AppendText("CSV Data Save : FAIL" & vbCrLf)
                        FailMain()

                    Else

                        txbWindow.AppendText("Run Count Change Save : OK" & vbCrLf)

                        If TestError = False Then
                            FailMain()
                        Else
                            SuccessMain()
                        End If

                    End If
                Else

                    txbWindow.AppendText("Run Count Change Save : FAIL" & vbCrLf)
                    FailMain()

                End If
            Else
                txbWindow.AppendText("DB Data Save : FAIL" & vbCrLf)
                FailMain()
            End If
        Else
            txbWindow.AppendText("PostgreSQL Data Save : FAIL" & vbCrLf)
            FailMain()
        End If
ProcessEnd:
        If ResponseErrorCheck Then
            RetryMain()
        End If
        Jig_End()
NormalEnd:
        ScopeClear()
        SpecClear()
        txbWindow.AppendText("[" & MeasureTimeAll(MeasEnd) & "ms] Test Play" & vbCrLf)
    End Sub


    Private Sub ldmEPFunction() ''세모 ep
        Try
            StartTime = MeasureTimeAll(MeasStart)
            TestData.Test_Serial = txbBarcode.Text

            If StartSwitch = True Then
                If retryPortOpen() Then
                    If LDMDataSearch() Then
                        FailMain()
                        GoTo NormalEnd
                    End If
                    For i = 0 To nudOnRe.Value

                        If JigRun_On() Then
                            GoTo ProcessEnd
                        End If

                        delay_run(StepDelay)

                        If FirmVerCheck() Then

                            Dim ReadUni As Byte() = Encoding.Unicode.GetBytes(TestData.Test_Firmware)

                            If ReadUni(0) < 57 Then
                                MsgBox("잘못된 펌웨어 버전입니다. 버전을 확인하여 주십시오.", vbCritical, Program_Name & Program_Version)
                                GoTo ProcessEnd
                            End If

                            If i = nudOnRe.Value Then
                                MsgBox("전원 ON에 실패하였습니다. 다시 시도하여 주십시오.", vbCritical, Program_Name & Program_Version)
                                GoTo ProcessEnd
                            End If

                        Else
                            Exit For
                        End If

                        delay_run(StepDelay)

                    Next

                    If BatteryTest() Then
                        FailMain()
                        GoTo ProcessEnd
                    End If
                    If TempTest() Then
                        FailMain()
                        GoTo ProcessEnd
                    End If

                    If EPTestRun() Then
                        GoTo ProcessEnd
                    End If

                    If LDMDataWrite(ModelCode.PadRight(2, "0"c)) Then
                        FailMain()
                        GoTo ProcessEnd
                    End If

                    GoTo RunSuccess
                Else
                    MsgBox("지그를 연결한 후 동작하여 주십시오.", vbCritical, Program_Name & Program_Version)
                    GoTo NormalEnd
                End If
            Else
                MsgBox("스코프와 스펙트럼을 연결한 후 동작하여 주십시오.", vbCritical, Program_Name & Program_Version)
                GoTo NormalEnd
            End If
        Catch ex As Exception
            MsgBox("ERR!! :: " & ex.Message, vbCritical)
            GoTo ProcessEnd
        End Try
RunSuccess:
        If EP_PostReg() Then
            txbWindow.AppendText("PostgreSQL Data Save : OK" & vbCrLf)
            If dbLdmEpSave() Then
                txbWindow.AppendText("DB Data Save : OK" & vbCrLf)
                If CountChanage() Then
                    txbWindow.AppendText("Run Count Change Save : OK" & vbCrLf)
                    Dim csvData As String = "" & TestData.Test_Serial & "," & NowDate & "," & NowTime & "," & TestData.Test_Firmware & "," & TestData.Test_EPVpp(0) & "," & TestData.Test_EPFreq(0) & "," & TestData.Test_EPPWidth(0) & "," & TestData.Test_EPNWidth(0) & "," & TestData.Test_EPVpp(1) & "," & TestData.Test_EPFreq(1) & "," & TestData.Test_EPPWidth(1) & "," & TestData.Test_EPNWidth(1) & "," & TestData.Test_EPVpp(2) & "," & TestData.Test_EPFreq(2) & "," & TestData.Test_EPPWidth(2) & "," & TestData.Test_EPNWidth(2) & "," & TestError & ""
                    If Save_Csv(csvData) Then
                        txbWindow.AppendText("CSV Data Save : FAIL" & vbCrLf)
                        FailMain()
                    Else
                        txbWindow.AppendText("Run Count Change Save : OK" & vbCrLf)

                        If TestError = False Then
                            FailMain()
                        Else
                            SuccessMain()
                        End If
                    End If
                Else
                    txbWindow.AppendText("Run Count Change Save : FAIL" & vbCrLf)
                    FailMain()
                End If
            Else
                txbWindow.AppendText("DB Data Save : FAIL" & vbCrLf)
                FailMain()
            End If
        Else
            txbWindow.AppendText("PostgreSQL Data Save : FAIL" & vbCrLf)
            FailMain()
        End If

ProcessEnd:
        If ResponseErrorCheck Then
            RetryMain()
        End If
        Jig_End()
NormalEnd:
        ScopeClear()
        SpecClear()
        txbWindow.AppendText("[" & MeasureTimeAll(MeasEnd) & "ms] Test Play" & vbCrLf)

    End Sub




    Private Sub epfunction()

        Try
            StartTime = MeasureTimeAll(MeasStart)

            If StartSwitch = True Then
                If retryPortOpen() Then

                    If txbBarcode.Text <> "[START]" Then
                        MsgBox("잘못된 시작 명령어를 입력하였습니다.", vbExclamation, Program_Name & Program_Version)
                        GoTo startFail
                    End If

                    For i = 0 To nudOnRe.Value

                        If JigRun_On() Then
                            GoTo ProcessEnd
                        End If

                        If FirmVerCheck() Then

                            Dim ReadUni As Byte() = Encoding.Unicode.GetBytes(TestData.Test_Firmware)

                            If ReadUni(0) < 57 Then
                                MsgBox("잘못된 펌웨어 버전입니다. 버전을 확인하여 주십시오.", vbCritical, Program_Name & Program_Version)
                                GoTo ProcessEnd
                            End If

                            If i = nudOnRe.Value Then
                                MsgBox("전원 ON에 실패하였습니다. 다시 시도하여 주십시오.", vbCritical, Program_Name & Program_Version)
                                GoTo ProcessEnd
                            End If

                        Else
                            Exit For
                        End If

                    Next

                    If AltoDataSetting() Then
                        TestError = False
                        newTDYnFlag = False
                        GoTo ProcessEnd
                    End If

                    delay_run(StepDelay)


                    If TempTest() Then
                        TestError = False
                        GoTo ProcessEnd
                    End If

                    If BatteryTest() Then
                        TestError = False
                        GoTo ProcessEnd
                    End If

                    If EPTestRun() Then
                        GoTo ProcessEnd
                    End If

                    If newTDYnFlag Then
                        If DataWriteAL() Then
                            TestError = False
                            newTDYnFlag = False
                            GoTo ProcessEnd
                        End If
                    Else
                        TestStep = TestList.DataWritten
                        TestRunningState(testRunningList.TDWritten, Color.Green)
                    End If

                    GoTo RunSuccess

                Else
                    MsgBox("지그를 연결한 후 동작하여 주십시오.", vbCritical, Program_Name & Program_Version)
                    GoTo startFail
                End If
            Else
                MsgBox("스코프와 스펙트럼을 연결한 후 동작하여 주십시오.", vbCritical, Program_Name & Program_Version)
                GoTo startFail
            End If

        Catch ex As Exception
            MsgBox("ERR!! :: " & ex.Message, vbCritical)
            GoTo ProcessEnd
        End Try
RunSuccess:
        If EP_PostReg() Then
            txbWindow.AppendText("PostgreSQL Data Save : OK" & vbCrLf)
            If dbEPSave() Then
                txbWindow.AppendText("DB Data Save : OK" & vbCrLf)
                If CountChanage() Then

                    txbWindow.AppendText("Run Count Change Save : OK" & vbCrLf)
                    Dim csvData As String = "" & TestData.Test_Serial & "," & NowDate & "," & NowTime & "," & TestData.Test_Firmware & "," & TestData.Test_EPVpp(0) & "," & TestData.Test_EPFreq(0) & "," & TestData.Test_EPPWidth(0) & "," & TestData.Test_EPNWidth(0) & "," & TestData.Test_EPVpp(1) & "," & TestData.Test_EPFreq(1) & "," & TestData.Test_EPPWidth(1) & "," & TestData.Test_EPNWidth(1) & "," & TestData.Test_EPVpp(2) & "," & TestData.Test_EPFreq(2) & "," & TestData.Test_EPPWidth(2) & "," & TestData.Test_EPNWidth(2) & "," & TestError & ""

                    If Save_Csv(csvData) Then

                        txbWindow.AppendText("CSV Data Save : FAIL" & vbCrLf)
                        FailMain()

                    Else

                        txbWindow.AppendText("Run Count Change Save : OK" & vbCrLf)

                        If TestError = False Then
                            FailMain()
                        Else
                            SuccessMain()
                        End If

                    End If
                Else

                    txbWindow.AppendText("Run Count Change Save : FAIL" & vbCrLf)
                    FailMain()

                End If
            Else
                txbWindow.AppendText("DB Data Save : FAIL" & vbCrLf)
                FailMain()
            End If
        Else
            txbWindow.AppendText("PostgreSQL Data Save : FAIL" & vbCrLf)
            FailMain()
        End If
ProcessEnd:
        If ResponseErrorCheck Then
            RetryMain()
        ElseIf TestError = False Then
            FailMain()
        End If
        Jig_End()
startFail:
        ScopeClear()
        SpecClear()
        txbWindow.AppendText("[" & MeasureTimeAll(MeasEnd) & "ms] Test Play" & vbCrLf)
    End Sub


    Private Sub rfMcfunction()
        StartTime = MeasureTimeAll(MeasStart)

        If StartSwitch = True Then
            If retryPortOpen() Then

                If txbBarcode.Text <> "[START]" Then
                    MsgBox("잘못된 시작 명령어를 입력하였습니다.", vbExclamation, Program_Name & Program_Version)
                    GoTo NormalEnd
                End If

                For i = 0 To nudOnRe.Value

                    If JigRun_On() Then
                        GoTo ProcessEnd
                    End If

                    If FirmVerCheck() Then

                        Dim ReadUni As Byte() = Encoding.Unicode.GetBytes(TestData.Test_Firmware)

                        If ReadUni(0) < 57 Then
                            MsgBox("잘못된 펌웨어 버전입니다. 버전을 확인하여 주십시오.", vbCritical, Program_Name & Program_Version)
                            GoTo ProcessEnd
                        End If

                        If i = nudOnRe.Value Then
                            MsgBox("전원 ON에 실패하였습니다. 다시 시도하여 주십시오.", vbCritical, Program_Name & Program_Version)
                            GoTo ProcessEnd
                        End If

                    Else
                        Exit For
                    End If

                Next

                If AltoDataSetting() Then
                    TestError = False
                    newTDYnFlag = False
                    GoTo ProcessEnd
                End If

                If TempTest() Then
                    TestError = False
                    GoTo ProcessEnd
                End If

                If BatteryTest() Then
                    TestError = False
                    GoTo NormalEnd
                End If

                If RFTestRun() Then
                    TestError = False
                    GoTo ProcessEnd
                End If

                'If MCTestRunSp() Then
                '    FailMain()
                '    GoTo ProcessEnd
                'End If

                If newTDYnFlag Then
                    If DataWriteAL() Then
                        TestError = False
                        newTDYnFlag = False
                        GoTo ProcessEnd
                    End If
                Else
                    TestStep = TestList.DataWritten
                    TestRunningState(testRunningList.TDWritten, Color.Green)
                End If


                GoTo SuccessEnd

            Else
                MsgBox("지그를 연결한 후 동작하여 주십시오.", vbCritical, Program_Name & Program_Version)
                GoTo NormalEnd
            End If
        Else
            MsgBox("스코프와 스펙트럼을 연결한 후 동작하여 주십시오.", vbCritical, Program_Name & Program_Version)
            GoTo NormalEnd
        End If

SuccessEnd:
        If RFMc_PostReg() Then

            txbWindow.AppendText("PostgreSQL Data Save : OK" & vbCrLf)

            If dbRFMCSave() Then
                txbWindow.AppendText("DB Data Save : OK" & vbCrLf)

                If CountChanage() Then
                    txbWindow.AppendText("Run Count Change : OK" & vbCrLf)
                    Dim csvData As String = "" & TestData.Test_Serial & "," & NowDate & "," & NowTime & "," & TestData.Test_Firmware & "," & TestData.Test_RFVRMS(0) & "," & TestData.Test_RFFreq(0) & "," & TestData.Test_RFVRMS(1) & "," & TestData.Test_RFFreq(1) & "," & TestData.Test_RFVRMS(2) & "," & TestData.Test_RFFreq(2) & "," & TestError & ""

                    If Save_Csv(csvData) Then
                        txbWindow.AppendText("CSV Data Save : FAIL" & vbCrLf)
                        FailMain()
                    Else
                        txbWindow.AppendText("CSV Data Save : OK" & vbCrLf)

                        If TestError = False Then
                            FailMain()
                        Else
                            SuccessMain()
                        End If
                    End If

                Else
                    txbWindow.AppendText("Run Count Change : FAIL" & vbCrLf)
                    FailMain()
                End If

            Else
                txbWindow.AppendText("DB Data Save : FAIL" & vbCrLf)
                FailMain()
            End If

        Else
            txbWindow.AppendText("PostgreSQL Data Save : FAIL" & vbCrLf)
            FailMain()
        End If


ProcessEnd:
        If TestError = False Then
            FailMain()
        End If
        Jig_End()

NormalEnd:
        ScopeClear()
        SpecClear()
        txbWindow.AppendText("[" & MeasureTimeAll(MeasEnd) & "ms] Test Play" & vbCrLf)
    End Sub

    Private Sub DSTestFunction()
        StartTime = MeasureTimeAll(MeasStart)

        If StartSwitch = True Then
            If retryPortOpen() Then

                If txbBarcode.Text <> "[START]" Then
                    MsgBox("잘못된 시작 명령어를 입력하였습니다.", vbExclamation, Program_Name & Program_Version)
                    GoTo NormalEnd
                End If

                If JigRun_On() Then
                    FailMain()
                    GoTo ProcessEnd
                End If

                'If TDNullProdWrite() Then
                '    FailMain()
                '    GoTo ProcessEnd
                'End If

                delay_run(Val(txbDSDelay.Text))

                If FirmVerCheck() Then
                    txbDSBasic.Text = "FAIL"
                    txbDSBasic.BackColor = Color.Red
                    txbDSBasic.Refresh()
                    FailMain()
                    MsgBox("최신 펌웨어로 동작하고 있지 않습니다. 펌웨어 버전을 확인하여 주십시오.", vbCritical, Program_Name & Program_Version)
                    GoTo ProcessEnd
                End If

                If TempTest() Then
                    txbDSBasic.Text = "FAIL"
                    txbDSBasic.BackColor = Color.Red
                    txbDSBasic.Refresh()
                    FailMain()
                    GoTo ProcessEnd
                End If

                If BatteryTest() Then
                    txbDSBasic.Text = "FAIL"
                    txbDSBasic.BackColor = Color.Red
                    txbDSBasic.Refresh()
                    FailMain()
                    GoTo ProcessEnd
                End If

                txbDSBasic.Text = "SUCCESS"
                txbDSBasic.BackColor = Color.Green
                txbDSBasic.Refresh()

                If HFTestRun() Then
                    FailMain()
                    GoTo ProcessEnd
                End If

                TestStep = TestList.DataWrite
                TestRunningState(testRunningList.Success, Color.Green)



                'Dim TestResult As Boolean = Not (TestError)
                'Dim mqttSendData As String = "[{""td_serial"":""" & TestData.Test_Serial & """},{""p1_testdate"":""" & NowDate & """},{""p1_testtime"":""" & NowTime & """},{""p1_result"":""" & TestResult & """},{""p1_fwver"":""" & TestData.Test_Firmware & """},{""p1_batterylv"":""" & TestData.Test_Battery & """},{""p1_divtemp"":""" & TestData.Test_Temperature(TempData.DivTemp) & """},{""p1_carttemp"":""" & TestData.Test_Temperature(TempData.CartTemp) & """},{""p1_hf1_value"":""" & TestData.Test_HFData(HifuTest_Step.Step1) & """},{""p1_hf2_value"":""" & TestData.Test_HFData(HifuTest_Step.Step2) & """},{""p1_hf3_value"":""" & TestData.Test_HFData(HifuTest_Step.step3) & """},{""oled_result"":""""},{""buzzer_result"":""""}]"

                'If Mqtt_DataSend(mqttSendData, mqttTopic) Then
                '    txbWindow.AppendText("MES Server Mqtt Protocol Fail ! " & vbCrLf)
                '    TestRunningState(testRunningList.Fail, Color.Red)
                'Else
                '    txbWindow.AppendText("MES Server Mqtt Protocol Save ! " & vbCrLf)
                '    TestRunningState(testRunningList.Success, Color.Green)
                'End If

                'txbWindow.AppendText("MES Server Mqtt Protocol Save ! " & vbCrLf)
                'TestRunningState(testRunningList.Success, Color.Green)

                GoTo RunSuccess

            Else
                MsgBox("지그를 연결한 후 동작하여 주십시오.", vbCritical, Program_Name & Program_Version)
                FailMain()
                GoTo NormalEnd
            End If
        Else
            MsgBox("스코프와 스펙트럼을 연결한 후 동작하여 주십시오.", vbCritical, Program_Name & Program_Version)
            FailMain()
            GoTo NormalEnd
        End If

RunSuccess:
        'If dbHFSave() Then
        If CountChanage() Then
            Dim csvData As String = NowDate & "," & NowTime & "," & TestData.Test_Firmware & "," & TestData.Test_Battery & "," & TestData.Test_Temperature(TempData.DivTemp) & "," & TestData.Test_Temperature(TempData.CartTemp) & "," & TestData.Test_HFData(HifuTest_Step.Step1) & "," & TestData.Test_HFData(HifuTest_Step.Step2) & "," & TestData.Test_HFData(HifuTest_Step.step3) & ""
            If Save_Csv(csvData) Then
                txbWindow.AppendText("CSV Data Save : FAIL" & vbCrLf)
                FailMain()
            Else
                If txbDSWrite.BackColor = Color.Green And txbDSWrite_2.BackColor = Color.Green And txbDSWrite_3.BackColor = Color.Green Then
                    txbDSSave.BackColor = Color.Green
                Else
                    txbDSSave.BackColor = Color.Red
                End If

                If TestError = False Then
                    FailMain()
                Else
                    SuccessMain()
                End If
            End If
        Else
            FailMain()
        End If
        'Else
        '    FailMain()
        'End If

ProcessEnd:
        Jig_End()
NormalEnd:
        txbWindow.AppendText("[" & MeasureTimeAll(MeasEnd) & "ms] Test Play" & vbCrLf)
    End Sub

    Private Sub allFunction()
        txbBarcode.ReadOnly = True
        Dim ModCnt As Int16 = 0
        Dim ErrorCheck As Boolean = False

        StartTime = MeasureTimeAll(MeasStart)

        TestData.Test_Serial = txbBarcode.Text

        If StartSwitch = True Then
            If retryPortOpen() Then

                MeasureTimeFunc(MeasStart)
                If TDDataSearch() Then
                    GoTo ProcessEnd
                End If
                txbWindow.AppendText("4. " & MeasureTimeFunc(MeasEnd) & vbCrLf)

                MeasureTimeFunc(MeasStart)
                MainTextChange("전원 ON")

                If JigRun_On() Then
                    MsgBox("제품과의 연결이 올바르지 않습니다. 연결 상태를 확인하여 주십시오.", vbCritical, Program_Name & Program_Version)
                    GoTo ProcessEnd
                End If
                txbWindow.AppendText("3. " & MeasureTimeFunc(MeasEnd) & vbCrLf)

                MeasureTimeFunc(MeasStart)

                If FirmVerCheck() Then
                    MsgBox("최신 펌웨어로 동작하고 있지 않습니다. 펌웨어 버전을 확인하여 주십시오.", vbCritical, Program_Name & Program_Version)
                    GoTo ProcessEnd
                End If

                txbWindow.AppendText("1. firm : " & MeasureTimeFunc(MeasEnd) & vbCrLf)

                MeasureTimeFunc(MeasStart)

                MainTextChange("HIFU 측정중")
                'delay_run(StepDelay)

                If HFTestRun() Then

                    If TestError = False Then
                        ErrorRunning()
                        GoTo ProcessEnd
                    End If
                    ErrorRunning()
                    ErrorCheck = True
                Else
                    SuccessRunning()
                End If

                txbWindow.AppendText("F. HF : " & MeasureTimeFunc(MeasEnd) & vbCrLf)

                MeasureTimeFunc(MeasStart)

                delay_run(StepDelay)

                If RFTestRun() Then
                    If TestError = False Then
                        ErrorRunning()
                        GoTo ProcessEnd
                    End If

                    ErrorRunning()
                    ErrorCheck = True
                Else
                    SuccessRunning()
                End If

                txbWindow.AppendText("F. RF : " & MeasureTimeFunc(MeasEnd) & vbCrLf)

                MeasureTimeFunc(MeasStart)

                MainTextChange("미세전류 측정중")
                'delay_run(StepDelay)

                If MCTestRunSp() Then
                    If TestError = False Then
                        ErrorRunning()
                        GoTo ProcessEnd
                    End If

                    ErrorRunning()
                    ErrorCheck = True
                Else
                    SuccessRunning()
                End If

                txbWindow.AppendText("F. MC : " & MeasureTimeFunc(MeasEnd) & vbCrLf)

                MeasureTimeFunc(MeasStart)

                If EPTestRun() Then
                    If TestError = False Then
                        ErrorRunning()
                        GoTo ProcessEnd
                    End If

                    ErrorRunning()
                    ErrorCheck = True
                Else
                    SuccessRunning()
                End If

                txbWindow.AppendText("F. EP : " & MeasureTimeFunc(MeasEnd) & vbCrLf)

                'MainTextChange("LED 측정중..")
                'delay_run(StepDelay)

                'If LEDTestRun3() Then
                '    ErrorRunning()
                '    ErrorCheck = True
                'Else
                '    SuccessRunning()
                'End If

                'MeasureTimeFunc(MeasStart)

                If BatteryTest() Then
                    ErrorRunning()
                    GoTo ProcessEnd
                Else
                    SuccessRunning()
                End If

                txbWindow.AppendText("F. BT : " & MeasureTimeFunc(MeasEnd) & vbCrLf)

                MeasureTimeFunc(MeasStart)

                If TempTest() Then
                    ErrorRunning()
                    GoTo ProcessEnd
                Else
                    SuccessRunning()
                End If

                txbWindow.AppendText("F. TM : " & MeasureTimeFunc(MeasEnd) & vbCrLf)

                MeasureTimeFunc(MeasStart)

                If DataWrite(ModelCode.PadRight(2, "0"c)) Then
                    ErrorRunning()
                    ErrorCheck = True
                Else
                    SuccessRunning()
                End If

                txbWindow.AppendText("F. DW : " & MeasureTimeFunc(MeasEnd) & vbCrLf)

                MeasureTimeFunc(MeasStart)

                MainTextChange("DB입력중..")

                If DBSave() Then
                    ErrorRunning()
                    ErrorCheck = True
                Else
                    SuccessRunning()
                End If

                MainTextChange("측정 완료")

                txbWindow.AppendText("F. DB : " & MeasureTimeFunc(MeasEnd) & vbCrLf)

                If ErrorCheck = True Then
                    FailMain()
                    ErrorCheck = False
                Else
                    txbDayCount.Text += 1
                    txbOkCount.Text += 1
                    SuccessMain()
                    ErrorCheck = True
                End If

                txbWindow.AppendText("[" & MeasureTimeAll(MeasEnd) & "ms] Test Play Success" & vbCrLf)

                Jig_End()

                Dim NowDate As String = Format(Now, "yyyy") & "-" & Format(Now, "MM") & "-" & Format(Now, "dd")
                Dim NowTime As String = Format(Now, "HH") & ":" & Format(Now, "mm") & ":" & Format(Now, "ss")

                txbBarcode.ReadOnly = False
                txbBarcode.Select(txbBarcode.Text.Length, 0)

                txbWindow.AppendText("[" & MeasureTimeAll(MeasEnd) & "ms] Test Play Success" & vbCrLf)

                TestStep = TestList.Wait
                Exit Sub

            Else
                MsgBox("지그를 연결한 후 동작하여 주십시오.", vbCritical, Program_Name & Program_Version)
                GoTo NormalEnd
                Exit Sub
            End If
        Else
            MsgBox("스코프와 스펙트럼을 연결한 후 동작하여 주십시오.", vbCritical, Program_Name & Program_Version)
            GoTo NormalEnd
            Exit Sub
        End If

NormalEnd:
        FailMain()
        If formType = formTypeList.prdRFMCEP Then
            ScopeClear()
            SpecClear()
        End If

        Exit Sub

ProcessEnd:
        FailMain()
        Jig_End()
        ScopeClear()
        SpecClear()
    End Sub

    Private Function CountChanage() As Boolean
        TestStep = TestList.COUNT
        If formType <> formTypeList.company Then
            TestRunningState(testRunningList.Running, Color.Yellow)
            If todayCountSet() Then
                txbWindow.AppendText("Today Count Setting Error ! " & vbCrLf)
                TestRunningState(testRunningList.Fail, Color.Red)
                Return False
            End If

            Select Case formType
                Case formTypeList.prdHF, formTypeList.iqcDsHF, formTypeList.prdDsHF, formTypeList.prdLowHF
                    HIFUReCount()
                Case formTypeList.prdRFMCEP, formTypeList.prdRFEP, formTypeList.prdEP, formTypeList.prdHFLDMEP, formTypeList.prdRFMC
                    RFReCount()
                Case formTypeList.iqcHFRFEP, formTypeList.iqcRFEP, formTypeList.iqcHF, formTypeList.iqcHFEP, formTypeList.iqcEP, formTypeList.iqcRFEPMC, formType = formTypeList.iqcLDM Or formType = formTypeList.iqcLDMEP
                    IQCReCount()
                Case formType = formTypeList.prdLDM
                    LDMReCount()
                Case formType = formTypeList.prdVRLDM Or formType = formTypeList.prdLDMEP
                    LDMRFReCount()


            End Select

            If CountUpdate() Then
                txbWindow.AppendText("Today Count Update Error ! " & vbCrLf)
                TestRunningState(testRunningList.Fail, Color.Red)
                Return False
            End If
        End If

        TestRunningState(testRunningList.Success, Color.Green)
        Return True
    End Function

    Private Sub HIFUReCount()
        If dupDATA = 0 Then
            txbDayCount.Text = Val(txbDayCount.Text) + 1
            If processNum = TestStepList.HF_NewSuc Or processNum = TestStepList.HF_ReSuc Then
                txbOkCount.Text = Val(txbOkCount.Text) + 1
            Else
                txbNgCount.Text = Val(txbNgCount.Text) + 1
            End If
        Else
            If TDDataSet(TD_Data.TestStep) = TestStepList.HF_NEWFail Or TDDataSet(TD_Data.TestStep) = TestStepList.HF_ReFail Then
                'If processNum = TestStepList.HF_NewSuc Or processNum = TestStepList.HF_ReSuc Then
                If processNum = TestStepList.HF_ReSuc Then
                    txbOkCount.Text = Val(txbOkCount.Text) + 1
                    txbNgCount.Text = Val(txbNgCount.Text) - 1
                End If
            Else
                'If processNum = TestStepList.HF_NEWFail Or processNum = TestStepList.HF_ReFail Then
                If processNum = TestStepList.HF_ReFail Then
                    txbOkCount.Text = Val(txbOkCount.Text) - 1
                    txbNgCount.Text = Val(txbNgCount.Text) + 1
                End If
            End If
        End If
    End Sub
    Private Sub LDMReCount()
        If dupDATA = 0 Then
            txbDayCount.Text = Val(txbDayCount.Text) + 1
            If processNum = TestStepList.HF_NewSuc Or processNum = TestStepList.HF_ReSuc Then
                txbOkCount.Text = Val(txbOkCount.Text) + 1
            Else
                txbNgCount.Text = Val(txbNgCount.Text) + 1
            End If
        Else
            If LDM_DataSet(LDM_Data.TestStep) = TestStepList.HF_NEWFail Or LDM_DataSet(LDM_Data.TestStep) = TestStepList.HF_ReFail Then
                If processNum = TestStepList.HF_ReSuc Then
                    txbOkCount.Text = Val(txbOkCount.Text) + 1
                    txbNgCount.Text = Val(txbNgCount.Text) - 1
                End If
            Else
                If processNum = TestStepList.HF_ReFail Then
                    txbOkCount.Text = Val(txbOkCount.Text) - 1
                    txbNgCount.Text = Val(txbNgCount.Text) + 1
                End If
            End If
        End If
    End Sub


    Private Sub IQCReCount()
        txbDayCount.Text = Val(txbDayCount.Text) + 1
        If TestError = False Then   'Fail
            txbNgCount.Text = Val(txbNgCount.Text) + 1
        Else
            txbOkCount.Text = Val(txbOkCount.Text) + 1
        End If
    End Sub

    Private Sub RFReCount()
        If dupDATA = 0 Then
            txbDayCount.Text = Val(txbDayCount.Text) + 1
            If processNum = TestStepList.RF_NewSuc Or processNum = TestStepList.RF_ReSuc Then
                txbOkCount.Text = Val(txbOkCount.Text) + 1
            Else
                txbNgCount.Text = Val(txbNgCount.Text) + 1
            End If
        Else
            If TDDataSet(TD_Data.TestStep) = TestStepList.RF_NewFail Or TDDataSet(TD_Data.TestStep) = TestStepList.RF_ReFail Then
                If processNum = TestStepList.RF_NewSuc Or processNum = TestStepList.RF_ReSuc Then
                    txbOkCount.Text = Val(txbOkCount.Text) + 1
                    txbNgCount.Text = Val(txbNgCount.Text) - 1
                End If
            Else
                If processNum = TestStepList.RF_NewFail Or processNum = TestStepList.RF_ReFail Then
                    txbOkCount.Text = Val(txbOkCount.Text) - 1
                    txbNgCount.Text = Val(txbNgCount.Text) + 1
                End If
            End If
        End If
    End Sub
    Private Sub LDMRFReCount()
        If dupDATA = 0 Then
            txbDayCount.Text = Val(txbDayCount.Text) + 1
            If processNum = TestStepList.RF_NewSuc Or processNum = TestStepList.RF_ReSuc Then
                txbOkCount.Text = Val(txbOkCount.Text) + 1
            Else
                txbNgCount.Text = Val(txbNgCount.Text) + 1
            End If
        Else
            If LDM_DataSet(TD_Data.TestStep) = TestStepList.RF_NewFail Or LDM_DataSet(TD_Data.TestStep) = TestStepList.RF_ReFail Then
                If processNum = TestStepList.RF_NewSuc Or processNum = TestStepList.RF_ReSuc Then
                    txbOkCount.Text = Val(txbOkCount.Text) + 1
                    txbNgCount.Text = Val(txbNgCount.Text) - 1
                End If
            Else
                If processNum = TestStepList.RF_NewFail Or processNum = TestStepList.RF_ReFail Then
                    txbOkCount.Text = Val(txbOkCount.Text) - 1
                    txbNgCount.Text = Val(txbNgCount.Text) + 1
                End If
            End If
        End If
    End Sub


    Private Function CountUpdate() As Boolean
        If formType = formTypeList.prdRFEP Then
            DBCmd = "UPDATE " & pd1CntTableNow & " SET PD1_AltoCnt = '" & txbDayCount.Text & "', PD1_AltoOkCnt = '" & txbOkCount.Text & "', PD1_AltoNgCnt = '" & txbNgCount.Text & "' WHERE PD1_Date = '" & NowDate & "'"
        ElseIf formType = formTypeList.prdHF Then
            DBCmd = "UPDATE " & pd1CntTableNow & " SET PD1_MaxHFTotalCnt = '" & txbDayCount.Text & "', PD1_MaxHFOkCnt = '" & txbOkCount.Text & "', PD1_MaxHFNgCnt = '" & txbNgCount.Text & "' WHERE PD1_Date = '" & NowDate & "'"
        ElseIf formType = formTypeList.prdRFMCEP Then
            DBCmd = "UPDATE " & pd1CntTableNow & " SET PD1_MaxRFTotalCnt = '" & txbDayCount.Text & "', PD1_MaxRFOkCnt = '" & txbOkCount.Text & "', PD1_MaxRFNgCnt = '" & txbNgCount.Text & "' WHERE PD1_Date = '" & NowDate & "'"
        ElseIf formType = formTypeList.iqcHFRFEP Then
            DBCmd = "UPDATE " & iqcCntTableNow & " SET IQC_MAXTotalCnt = '" & txbDayCount.Text & "', IQC_MAXOkCnt = '" & txbOkCount.Text & "', IQC_MAXNgCnt = '" & txbNgCount.Text & "' WHERE IQC_Date = '" & NowDate & "'"
        ElseIf formType = formTypeList.iqcRFEP Or formType = formTypeList.iqcEP Or formType = formTypeList.iqcRFEPMC Then
            DBCmd = "UPDATE " & iqcCntTableNow & " SET IQC_ALTOTotalCnt = '" & txbDayCount.Text & "', IQC_ALTOOkCnt = '" & txbOkCount.Text & "', IQC_ALTONgCnt = '" & txbNgCount.Text & "' WHERE IQC_Date = '" & NowDate & "'"
        ElseIf formType = formTypeList.iqcHF Or formType = formTypeList.iqcHFEP Then
            DBCmd = "UPDATE " & iqcCntTableNow & " SET IQC_EFFECTTotalCnt = '" & txbDayCount.Text & "', IQC_EFFECTOkCnt = '" & txbOkCount.Text & "', IQC_EFFECTNgCnt = '" & txbNgCount.Text & "' WHERE IQC_Date = '" & NowDate & "'"
        ElseIf formType = formTypeList.iqcLDM Then
            DBCmd = "UPDATE " & iqcCntTableNow & " SET IQC_LDMTotalCnt = '" & txbDayCount.Text & "', IQC_LDMOkCnt = '" & txbOkCount.Text & "', IQC_LDMNgCnt = '" & txbNgCount.Text & "' WHERE IQC_Date = '" & NowDate & "'"
        ElseIf formType = formTypeList.prdLowHF Then ''저가형
            DBCmd = "UPDATE " & pd1CntTableNow & " SET PD1_LowPriceHFCnt = '" & txbDayCount.Text & "', PD1_LowPriceHFOkCnt = '" & txbOkCount.Text & "', PD1_LowPriceHFNgCnt = '" & txbNgCount.Text & "' WHERE PD1_Date = '" & NowDate & "'"
        ElseIf formType = formTypeList.prdHFLDMEP Or formType = formTypeList.prdEP Or formType = formTypeList.prdLDMEP Then ''저가형 ep ldm
            DBCmd = "UPDATE " & pd1CntTableNow & " SET PD1_LowPriceEPCnt = '" & txbDayCount.Text & "', PD1_LowPriceEPOkCnt = '" & txbOkCount.Text & "', PD1_LowPriceEPNgCnt = '" & txbNgCount.Text & "' WHERE PD1_Date = '" & NowDate & "'"
        ElseIf formType = formTypeList.prdLDM Then ''저가형 세모 ldm
            DBCmd = "UPDATE " & pd1CntTableNow & " SET PD1_LowPriceLDMCnt = '" & txbDayCount.Text & "', PD1_LowPriceLDMOkCnt = '" & txbOkCount.Text & "', PD1_LowPriceLDMNgCnt = '" & txbNgCount.Text & "' WHERE PD1_Date = '" & NowDate & "'"
        ElseIf formType = formTypeList.prdVRLDM Or formType = formTypeList.prdRFMC Then '' 저가형 마름모 , 세모rf
            DBCmd = "UPDATE " & pd1CntTableNow & " SET PD1_LowPriceRFCnt = '" & txbDayCount.Text & "', PD1_LowPriceRFOKCnt = '" & txbOkCount.Text & "', PD1_LowPriceRFNgCnt = '" & txbNgCount.Text & "' WHERE PD1_Date = '" & NowDate & "'"
        End If


        If DBCommand(DBCmd) Then
            Return False
        Else
            Return True
        End If
    End Function

    Private Function TDDataSearch() As Boolean

        MeasureTimeFunc(MeasStart)
        If TDExist() Then

            TDCompare()

            If TDTestNG() Then
                MsgBox("해당 시리얼 번호는 데이터가 존재하지 않습니다. TD 수입검사 진행 여부를 확인하여 주십시오.", vbCritical, Program_Name & Program_Version)
                MeasureTimeFunc(MeasEnd)
                Return True
            End If

            If TDDataSet(TD_Data.TestStep) = 1 Then
                MsgBox("전류측정을 진행하지 않은 TD 시리얼 번호입니다. 전류측정을 진행하여 주십시오.", vbCritical, Program_Name & Program_Version)
                MeasureTimeFunc(MeasEnd)
                Return True
            End If

            txbTDSN.Text = TestData.Test_Serial
            txbTDSN.Refresh()
            txbDate.Text = TDDataSet(TD_Data.TestDate)
            txbDate.Refresh()
            txbFreq.Text = TDDataSet(TD_Data.Freq)
            txbFreq.Refresh()
            txbGrade.Text = TDDataSet(TD_Data.Grade)
            txbGrade.Refresh()

            txbWindow.AppendText("TD Data Time(s) : " & MeasureTimeFunc(MeasEnd) & vbCrLf)
            Return False

        Else
            MsgBox("TD 데이터가 존재하지 않습니다. 성적서를 등록하여 주십시오.", vbExclamation, Program_Name & Program_Version)
            MeasureTimeFunc(MeasEnd)
            Return True
        End If
    End Function

    Private Sub ImageLocation(ColorCode As Int16, NowNum As Int16, ReCnt As Integer)
        XMoveCrd = 0
        YMoveCrd = 0

        Select Case NowNum
            Case 0
                XMoveCrd = LedCoordinate(ColorCode, 0)
                YMoveCrd = LedCoordinate(ColorCode, 1)

            Case 1
                XMoveCrd = LedCoordinate(ColorCode, 0) + ReCnt
                YMoveCrd = LedCoordinate(ColorCode, 1)
            Case 2
                XMoveCrd = LedCoordinate(ColorCode, 0)
                YMoveCrd = LedCoordinate(ColorCode, 1) + ReCnt
            Case 3
                XMoveCrd = LedCoordinate(ColorCode, 0) - ReCnt
                YMoveCrd = LedCoordinate(ColorCode, 1)
            Case 4
                XMoveCrd = LedCoordinate(ColorCode, 0)
                YMoveCrd = LedCoordinate(ColorCode, 1) - ReCnt

            Case 5
                XMoveCrd = LedCoordinate(ColorCode, 0) + ReCnt
                YMoveCrd = LedCoordinate(ColorCode, 1) - ReCnt

            Case 6
                XMoveCrd = LedCoordinate(ColorCode, 0) + ReCnt
                YMoveCrd = LedCoordinate(ColorCode, 1) + ReCnt

            Case 7
                XMoveCrd = LedCoordinate(ColorCode, 0) - ReCnt
                YMoveCrd = LedCoordinate(ColorCode, 1) + ReCnt

            Case 8
                XMoveCrd = LedCoordinate(ColorCode, 0) - ReCnt
                YMoveCrd = LedCoordinate(ColorCode, 1) - ReCnt
        End Select

        If XMoveCrd < 0 Then
            XMoveCrd = 0
        End If

        If YMoveCrd < 0 Then
            YMoveCrd = 0
        End If

        If XMoveCrd > 640 Then
            XMoveCrd = 640
        End If

        If YMoveCrd > 480 Then
            YMoveCrd = 480
        End If

    End Sub

    Private Sub SuccessRunning()
        textRunning(TestStep).Text = "O K"
        textRunning(TestStep).BackColor = Color.Green
    End Sub

    Private Sub ErrorRunning()
        textRunning(TestStep).Text = "F A I L"
        textRunning(TestStep).BackColor = Color.Red
    End Sub

    Private Sub TestRunningState(stateType As Int16, bColor As Color)
        Dim ChangeTxb As New TextBox
        Dim runSwitch As Boolean = True

        Select Case TestStep
            Case TestList.Firmware

                If formType = formTypeList.iqcDsHF Or formType = formTypeList.prdDsHF Then
                    ChangeTxb = txbDSFirm
                Else
                    runSwitch = False
                End If

            Case TestList.Battey

                If formType = formTypeList.prdHF Or formType = formTypeList.prdLowHF Or formType = formTypeList.prdEP Or formType = formTypeList.prdHFLDMEP Or formType = formTypeList.prdLDM Or formType = formTypeList.prdVRLDM Or formType = formTypeList.prdLDMEP Then
                    ChangeTxb = txbBat

                ElseIf formType = formTypeList.iqcDsHF Or formType = formTypeList.prdDsHF Then
                    ChangeTxb = txbDSBat

                Else
                    runSwitch = False
                End If

            Case TestList.Temp

                If formType = formTypeList.prdHF Or formType = formTypeList.prdLowHF Or formType = formTypeList.prdEP Or formType = formTypeList.prdHFLDMEP Or formType = formTypeList.prdLDM Or formType = formTypeList.prdVRLDM Or formType = formTypeList.prdLDMEP Then
                    ChangeTxb = txbTemp
                ElseIf formType = formTypeList.iqcDsHF Or formType = formTypeList.prdDsHF Then
                    ChangeTxb = txbDSTemp
                Else
                    runSwitch = False
                End If

            Case TestList.HIFU

                If formType = formTypeList.prdHF Or formType = formTypeList.prdLowHF Or formType = formTypeList.prdEP Or formType = formTypeList.prdHFLDMEP Or formType = formTypeList.prdLDM Or formType = formTypeList.prdVRLDM Or formType = formTypeList.prdLDMEP Then
                    ChangeTxb = txbHFresult
                ElseIf formType = formTypeList.iqcHFRFEP Or formType = formTypeList.iqcHF Or formType = formTypeList.iqcEP Or formType = formTypeList.iqcLDM Or formType = formTypeList.iqcHFEP Or formType = formTypeList.iqcLDMEP Then
                    ChangeTxb = txbIQCHF
                ElseIf formType = formTypeList.iqcDsHF Or formType = formTypeList.prdDsHF Then
                    ChangeTxb = txbDSHifu
                Else
                    runSwitch = False
                End If

            Case TestList.RF

                If formType = formTypeList.prdRFMCEP Or formType = formTypeList.prdRFMC Or formType = formTypeList.iqcRFEPMC Then
                    ChangeTxb = txbRFresult

                ElseIf formType = formTypeList.prdRFEP Or formType = formTypeList.iqcRFEP Or formType = formTypeList.company Then
                    ChangeTxb = txbAlIQCRF

                ElseIf formType = formTypeList.iqcHFRFEP Then
                    ChangeTxb = txbIQCRF

                Else
                    runSwitch = False
                End If

            Case TestList.MC

                If formType = formTypeList.prdRFMCEP Or formType = formTypeList.iqcRFEPMC Then
                    ChangeTxb = txbMCresult

                Else
                    runSwitch = False
                End If

            Case TestList.EP
                If formType = formTypeList.prdRFMCEP Or formType = formTypeList.iqcRFEPMC Then
                    ChangeTxb = txbEPresult

                ElseIf formType = formTypeList.prdRFEP Or formType = formTypeList.iqcRFEP Or formType = formTypeList.company Then
                    ChangeTxb = txbAlIQCEP

                ElseIf formType = formTypeList.iqcHFRFEP Or formType = formTypeList.iqcHFEP Or formType = formTypeList.iqcLDMEP Then
                    ChangeTxb = txbIQCEP

                Else
                    runSwitch = False
                End If

            Case TestList.DataWrite
                If formType = formTypeList.prdHF Or formType = formTypeList.prdLowHF Or formType = formTypeList.prdEP Or formType = formTypeList.prdVRLDM Or formType = formTypeList.prdRFMC Or formType = formTypeList.prdLDM Or formType = formTypeList.prdHFLDMEP Or formType = formTypeList.prdLDMEP Then
                    ChangeTxb = txbTDreg

                ElseIf formType = formTypeList.iqcDsHF Or formType = formTypeList.prdDsHF Then
                    ChangeTxb = txbDSWrite

                Else
                    runSwitch = False
                End If

            Case TestList.DataWritten
                ChangeTxb = txbTDreg

            Case TestList.DBWrite
                If formType = formTypeList.prdHF Or formType = formTypeList.prdLowHF Or formType = formTypeList.prdEP Or formType = formTypeList.prdHFLDMEP Or formType = formTypeList.prdLDM Or formType = formTypeList.prdVRLDM Or formType = formTypeList.prdLDMEP Then
                    ChangeTxb = txbDBreg

                Else
                    runSwitch = False
                End If

            Case TestList.COUNT
                If formType = formTypeList.iqcDsHF Or formType = formTypeList.prdDsHF Then
                    ChangeTxb = txbDSWrite_2
                Else
                    runSwitch = False
                End If

            Case TestList.CSV
                If formType = formTypeList.iqcDsHF Or formType = formTypeList.prdDsHF Then
                    ChangeTxb = txbDSWrite_3
                Else
                    runSwitch = False
                End If
            Case Else
                runSwitch = False
        End Select

        If runSwitch = True Then
            ChangeTxb.Text = testState(stateType)
            ChangeTxb.BackColor = bColor
            ChangeTxb.Refresh()
        End If
    End Sub

    Private Sub FailMain()
        txbBarcode.Text = " 불  합  격"
        txbBarcode.BackColor = Color.Red
        txbBarcode.Refresh()
    End Sub
    Private Sub RetryMain()
        txbBarcode.Text = " 계 측 기 재 검 사 필 요"
        txbBarcode.BackColor = Color.Gray
        txbBarcode.Refresh()
    End Sub

    Private Sub SuccessMain()
        txbBarcode.Text = " 합  격"
        txbBarcode.BackColor = Color.Green
        txbBarcode.Refresh()
    End Sub

    Private Sub MainTextChange(ChangeText As String)
        txbBarcode.Text = ChangeText
        txbBarcode.BackColor = Color.GreenYellow
        txbBarcode.Refresh()
    End Sub

    Private Sub delay_run(ByVal millisecond As Double)
        Dim delayTime As Date = Now.AddSeconds(millisecond / 1000)
        Do Until Now > delayTime
            Application.DoEvents()
        Loop
    End Sub

    Private Function dbAltoSave() As Boolean
        If formType = formTypeList.prdRFEP Then

            MeasureTimeFunc(MeasStart)
            MainTextChange("DB입력중..")
            TestStep = TestList.DBWrite
            TestRunningState(testRunningList.Running, Color.Yellow)

            DBCmd = "SELECT EXISTS(SELECT 1 FROM " & rfTableNow & " WHERE PV_SN='" & TestData.Test_Serial & "') AS A;"

            Dim DupYn As Boolean = DBQueryScalar(DBCmd)

            If DupYn = True Then
                DBCmd = "UPDATE " & rfTableNow & " SET TestDate='" & NowDate & "',TestTime='" & NowTime & "',RF_R1Vrms='" & TestData.Test_RFVRMS(0) & "',RF_R1Freq='" & TestData.Test_RFFreq(0) & "',RF_R2Vrms='" & TestData.Test_RFVRMS(1) & "',RF_R2Freq='" & TestData.Test_RFFreq(1) & "',RF_R3Vrms='" & TestData.Test_RFVRMS(2) & "',RF_R3Freq='" & TestData.Test_RFFreq(2) & "',EP_R1Vpp='" & TestData.Test_EPVpp(0) & "',EP_R1Freq='" & TestData.Test_EPFreq(0) & "',EP_R1PWidth='" & TestData.Test_EPPWidth(0) & "',EP_R1NWidth='" & TestData.Test_EPNWidth(0) & "',EP_R2Vpp='" & TestData.Test_EPVpp(1) & "',EP_R2Freq='" & TestData.Test_EPFreq(1) & "',EP_R2PWidth='" & TestData.Test_EPPWidth(1) & "',EP_R2NWidth='" & TestData.Test_EPNWidth(1) & "',EP_R3Vpp='" & TestData.Test_EPVpp(2) & "',EP_R3Freq='" & TestData.Test_EPFreq(2) & "',EP_R3PWidth='" & TestData.Test_EPPWidth(2) & "',EP_R3NWidth='" & TestData.Test_EPNWidth(2) & "' WHERE PV_SN = '" & TestData.Test_Serial & "'"

                If TestError = False Then
                    processNum = TestStepList.RF_ReFail
                Else
                    processNum = TestStepList.RF_ReSuc
                End If

            Else
                DBCmd = "INSERT INTO " & rfTableNow & "(PV_SN,TestDate,TestTime,RF_R1Vrms,RF_R1Freq,RF_R2Vrms,RF_R2Freq,RF_R3Vrms,RF_R3Freq,EP_R1Vpp,EP_R1Freq,EP_R1PWidth,EP_R1NWidth,EP_R2Vpp,EP_R2Freq,EP_R2PWidth,EP_R2NWidth,EP_R3Vpp,EP_R3Freq,EP_R3PWidth,EP_R3NWidth) VALUES ('" & TestData.Test_Serial & "','" & NowDate & "','" & NowTime & "','" & TestData.Test_RFVRMS(0) & "','" & TestData.Test_RFFreq(0) & "','" & TestData.Test_RFVRMS(1) & "','" & TestData.Test_RFFreq(1) & "','" & TestData.Test_RFVRMS(2) & "','" & TestData.Test_RFFreq(2) & "','" & TestData.Test_EPVpp(0) & "','" & TestData.Test_EPFreq(0) & "','" & TestData.Test_EPPWidth(0) & "','" & TestData.Test_EPNWidth(0) & "','" & TestData.Test_EPVpp(1) & "','" & TestData.Test_EPFreq(1) & "','" & TestData.Test_EPPWidth(1) & "','" & TestData.Test_EPNWidth(1) & "','" & TestData.Test_EPVpp(2) & "','" & TestData.Test_EPFreq(2) & "','" & TestData.Test_EPPWidth(2) & "','" & TestData.Test_EPNWidth(2) & "')"


                If TestError = False Then
                    processNum = TestStepList.RF_NewFail
                Else
                    processNum = TestStepList.RF_NewSuc
                End If

            End If

            txbWindow.AppendText("DataBase Save FAIL" & DBCmd & "//" & processNum & vbCrLf)
            If DBCommand(DBCmd) = False Then
                GoTo dbFail
            End If

            If TDDataSet(TD_Data.TestStep) = "11" Then
                DBCmd = "INSERT INTO " & NonTDTableNow & "(TestStep,PV_SN,P1_DateTime,Fw_Ver,DivTemp,CtTemp,BatteryLv) VALUES('" & processNum & "','" & TestData.Test_Serial & "','" & NowDate & " " & NowTime & "','" & TestData.Test_Firmware & "','" & TestData.Test_Temperature(TempData.DivTemp) & "','" & TestData.Test_Temperature(TempData.CartTemp) & "','" & TestData.Test_Battery & "')"


                txbWindow.AppendText("DataBase Save FAIL" & DBCmd & vbCrLf)
                If DBCommand(DBCmd) = False Then
                    GoTo dbFail
                End If

            Else

                Dim sucSwitch As Boolean = False

                For i = 1 To nudSaveCk.Value
                    sucSwitch = False
                    DBCmd = "UPDATE " & NonTDTableNow & " SET TestStep = '" & processNum & "', P1_DateTime = '" & NowDate & " " & NowTime & "', Fw_Ver = '" & TestData.Test_Firmware & "', DivTemp = '" & TestData.Test_Temperature(TempData.DivTemp) & "', CtTemp = '" & TestData.Test_Temperature(TempData.CartTemp) & "', BatteryLv = '" & TestData.Test_Battery & "' WHERE PV_SN = '" & TestData.Test_Serial & "'"


                    txbWindow.AppendText("DataBase Save FAIL" & DBCmd & vbCrLf)
                    If DBCommand(DBCmd) = False Then
                        GoTo dbFail
                    End If

                    DBCmd = "SELECT TestStep FROM " & NonTDTableNow & " WHERE PV_SN = '" & TestData.Test_Serial & "'"

                    Dim tdState As Int16 = DBQueryScalar(DBCmd)

                    txbWindow.AppendText("DataBase Save FAIL" & DBCmd & "//" & tdState & "//" & processNum & vbCrLf)
                    If tdState = processNum Then
                        sucSwitch = True
                        Exit For
                    End If
                Next

                If sucSwitch = False Then
                    GoTo dbFail
                End If

            End If

            txbWindow.AppendText("DataBase Save Full Time : " & MeasureTimeFunc(MeasEnd) & vbCrLf)
            TestRunningState(testRunningList.Success, Color.Green)
        End If

        Return True

dbFail:
        txbWindow.AppendText("DataBase Save FAIL" & vbCrLf)
        MeasureTimeFunc(MeasEnd)
        TestRunningState(testRunningList.Fail, Color.Red)
        TestError = False
        Return False

    End Function

    Private Function dbRFSave() As Boolean
        MeasureTimeFunc(MeasStart)
        MainTextChange("DB입력중..")
        TestStep = TestList.DBWrite
        TestRunningState(testRunningList.Running, Color.Yellow)

        Dim sucSwitch As Boolean = False

        DBCmd = "SELECT EXISTS(SELECT 1 FROM " & rfTableNow & " WHERE PV_SN='" & TestData.Test_Serial & "') AS A;"

        Dim DupYn As Boolean = DBQueryScalar(DBCmd)

        If DupYn = True Then
            DBCmd = "UPDATE " & rfTableNow & " SET TestDate='" & NowDate & "',TestTime='" & NowTime & "',RF_R1Vrms='" & TestData.Test_RFVRMS(0) & "',RF_R1Freq='" & TestData.Test_RFFreq(0) & "',RF_R2Vrms='" & TestData.Test_RFVRMS(1) & "',RF_R2Freq='" & TestData.Test_RFFreq(1) & "',RF_R3Vrms='" & TestData.Test_RFVRMS(2) & "',RF_R3Freq='" & TestData.Test_RFFreq(2) & "',MC_R1Wave='" & TestData.Test_MCWidth(0) & "',MC_R1Vpp='" & TestData.Test_MCVpp(0) & "',MC_R1Freq='" & TestData.Test_MCFreq(0) & "',MC_R2Wave='" & TestData.Test_MCWidth(1) & "',MC_R2Vpp='" & TestData.Test_MCVpp(0) & "',MC_R2Freq='" & TestData.Test_MCFreq(0) & "',EP_R1Vpp='" & TestData.Test_EPVpp(0) & "',EP_R1Freq='" & TestData.Test_EPFreq(0) & "',EP_R1PWidth='" & TestData.Test_EPPWidth(0) & "',EP_R1NWidth='" & TestData.Test_EPNWidth(0) & "',EP_R2Vpp='" & TestData.Test_EPVpp(1) & "',EP_R2Freq='" & TestData.Test_EPFreq(1) & "',EP_R2PWidth='" & TestData.Test_EPPWidth(1) & "',EP_R2NWidth='" & TestData.Test_EPNWidth(1) & "',EP_R3Vpp='" & TestData.Test_EPVpp(2) & "',EP_R3Freq='" & TestData.Test_EPFreq(2) & "',EP_R3PWidth='" & TestData.Test_EPPWidth(2) & "',EP_R3NWidth='" & TestData.Test_EPNWidth(2) & "' WHERE PV_SN = '" & TestData.Test_Serial & "'"

            If TestError = False Then
                processNum = TestStepList.RF_ReFail
            Else
                processNum = TestStepList.RF_ReSuc
            End If

        Else
            DBCmd = "INSERT INTO " & rfTableNow & "(PV_SN,TestDate,TestTime,RF_R1Vrms,RF_R1Freq,RF_R2Vrms,RF_R2Freq,RF_R3Vrms,RF_R3Freq,MC_R1Wave,MC_R1Vpp,MC_R1Freq,MC_R2Wave,MC_R2Vpp,MC_R2Freq,EP_R1Vpp,EP_R1Freq,EP_R1PWidth,EP_R1NWidth,EP_R2Vpp,EP_R2Freq,EP_R2PWidth,EP_R2NWidth,EP_R3Vpp,EP_R3Freq,EP_R3PWidth,EP_R3NWidth) VALUES ('" & TestData.Test_Serial & "','" & NowDate & "','" & NowTime & "','" & TestData.Test_RFVRMS(0) & "','" & TestData.Test_RFFreq(0) & "','" & TestData.Test_RFVRMS(1) & "','" & TestData.Test_RFFreq(1) & "','" & TestData.Test_RFVRMS(2) & "','" & TestData.Test_RFFreq(2) & "','" & TestData.Test_MCWidth(0) & "','" & TestData.Test_MCVpp(0) & "','" & TestData.Test_MCFreq(0) & "','" & TestData.Test_MCWidth(1) & "','" & TestData.Test_MCVpp(1) & "','" & TestData.Test_MCFreq(1) & "','" & TestData.Test_EPVpp(0) & "','" & TestData.Test_EPFreq(0) & "','" & TestData.Test_EPPWidth(0) & "','" & TestData.Test_EPNWidth(0) & "','" & TestData.Test_EPVpp(1) & "','" & TestData.Test_EPFreq(1) & "','" & TestData.Test_EPPWidth(1) & "','" & TestData.Test_EPNWidth(1) & "','" & TestData.Test_EPVpp(2) & "','" & TestData.Test_EPFreq(2) & "','" & TestData.Test_EPPWidth(2) & "','" & TestData.Test_EPNWidth(2) & "')"

            If TestError = False Then
                processNum = TestStepList.RF_NewFail
            Else
                processNum = TestStepList.RF_NewSuc
            End If
        End If

        If DBCommand(DBCmd) = False Then
            GoTo dbFail
        End If

        For i = 1 To nudSaveCk.Value
            sucSwitch = False
            DBCmd = "UPDATE " & TDTableNow & " SET TestStep='" & processNum & "' WHERE PV_SN = '" & TestData.Test_Serial & "'"

            If DBCommand(DBCmd) = False Then
                GoTo dbFail
            End If

            DBCmd = "SELECT TestStep FROM " & TDTableNow & " WHERE PV_SN = '" & TestData.Test_Serial & "'"

            Dim tdState As Int16 = DBQueryScalar(DBCmd)

            If tdState = processNum Then
                sucSwitch = True
                Exit For
            End If
        Next

        If sucSwitch = False Then
            GoTo dbFail
        End If

        txbWindow.AppendText("DataBase Save Full Time : " & MeasureTimeFunc(MeasEnd) & vbCrLf)
        TestRunningState(testRunningList.Success, Color.Green)
        Return True

dbFail:
        txbWindow.AppendText("DataBase Save FAIL" & vbCrLf)
        MeasureTimeFunc(MeasEnd)
        TestRunningState(testRunningList.Fail, Color.Red)
        TestError = False
        Return False

    End Function
    Private Function dbRFLDMSave() As Boolean
        MeasureTimeFunc(MeasStart)
        MainTextChange("DB입력중..")
        TestStep = TestList.DBWrite
        TestRunningState(testRunningList.Running, Color.Yellow)

        Dim sucSwitch As Boolean = False

        DBCmd = "SELECT EXISTS(SELECT 1 FROM " & ldmRfTestTableNow & " WHERE PV_SN='" & TestData.Test_Serial & "') AS A;"

        Dim DupYn As Boolean = DBQueryScalar(DBCmd)

        If DupYn = True Then
            DBCmd = "UPDATE " & ldmRfTestTableNow & " SET TestDate='" & NowDate & "',TestTime='" & NowTime & "',RF_R1Vrms='" & TestData.Test_RFVRMS(0) & "',RF_R1Freq='" & TestData.Test_RFFreq(0) & "',RF_R2Vrms='" & TestData.Test_RFVRMS(1) & "',RF_R2Freq='" & TestData.Test_RFFreq(1) & "',RF_R3Vrms='" & TestData.Test_RFVRMS(2) & "',RF_R3Freq='" & TestData.Test_RFFreq(2) & "',TestResult='" & TestError & "' WHERE PV_SN = '" & TestData.Test_Serial & "'"

            If TestError = False Then
                processNum = TestStepList.RF_ReFail
            Else
                processNum = TestStepList.RF_ReSuc
            End If

        Else
            DBCmd = "INSERT INTO " & ldmRfTestTableNow & "(PV_SN,TestDate,TestTime,TestResult,RF_R1Vrms,RF_R1Freq,RF_R2Vrms,RF_R2Freq,RF_R3Vrms,RF_R3Freq) VALUES ('" & TestData.Test_Serial & "','" & NowDate & "','" & NowTime & "','" & TestError & "','" & TestData.Test_RFVRMS(0) & "','" & TestData.Test_RFFreq(0) & "','" & TestData.Test_RFVRMS(1) & "','" & TestData.Test_RFFreq(1) & "','" & TestData.Test_RFVRMS(2) & "','" & TestData.Test_RFFreq(2) & "')"

            If TestError = False Then
                processNum = TestStepList.RF_NewFail
            Else
                processNum = TestStepList.RF_NewSuc
            End If
        End If

        If DBCommand(DBCmd) = False Then
            GoTo dbFail
        End If

        For i = 1 To nudSaveCk.Value
            sucSwitch = False
            DBCmd = "UPDATE " & ldmTableNow & " SET TestStep='" & processNum & "' WHERE PV_SN = '" & TestData.Test_Serial & "'"

            If DBCommand(DBCmd) = False Then
                GoTo dbFail
            End If

            DBCmd = "SELECT TestStep FROM " & ldmTableNow & " WHERE PV_SN = '" & TestData.Test_Serial & "'"

            Dim tdState As Int16 = DBQueryScalar(DBCmd)

            If tdState = processNum Then
                sucSwitch = True
                Exit For
            End If
        Next

        If sucSwitch = False Then
            GoTo dbFail
        End If

        txbWindow.AppendText("DataBase Save Full Time : " & MeasureTimeFunc(MeasEnd) & vbCrLf)
        TestRunningState(testRunningList.Success, Color.Green)
        Return True

dbFail:
        txbWindow.AppendText("DataBase Save FAIL" & vbCrLf)
        MeasureTimeFunc(MeasEnd)
        TestRunningState(testRunningList.Fail, Color.Red)
        TestError = False
        Return False

    End Function

    Private Function dbRFMCSave() As Boolean
        MeasureTimeFunc(MeasStart)
        MainTextChange("DB입력중..")

        Dim sucSwitch As Boolean = False

        DBCmd = "SELECT EXISTS(SELECT 1 FROM " & rfTableNow & " WHERE PV_SN='" & TestData.Test_Serial & "') AS A;"

        Dim DupYn As Boolean = DBQueryScalar(DBCmd)


        If DupYn = True Then
            DBCmd = "UPDATE " & rfTableNow & " SET TestDate='" & NowDate & "',TestTime='" & NowTime & "',RF_R1Vrms='" & TestData.Test_RFVRMS(0) & "',RF_R1Freq='" & TestData.Test_RFFreq(0) & "',RF_R2Vrms='" & TestData.Test_RFVRMS(1) & "',RF_R2Freq='" & TestData.Test_RFFreq(1) & "',RF_R3Vrms='" & TestData.Test_RFVRMS(2) & "',RF_R3Freq='" & TestData.Test_RFFreq(2) & "' WHERE PV_SN = '" & TestData.Test_Serial & "'"

            If TestError = False Then
                processNum = TestStepList.RF_ReFail
            Else
                processNum = TestStepList.RF_ReSuc
            End If
        Else
            DBCmd = "INSERT INTO " & rfTableNow & "(PV_SN,TestDate,TestTime,RF_R1Vrms,RF_R1Freq,RF_R2Vrms,RF_R2Freq,RF_R3Vrms,RF_R3Freq) VALUES ('" & TestData.Test_Serial & "','" & NowDate & "','" & NowTime & "','" & TestData.Test_RFVRMS(0) & "','" & TestData.Test_RFFreq(0) & "','" & TestData.Test_RFVRMS(1) & "','" & TestData.Test_RFFreq(1) & "','" & TestData.Test_RFVRMS(2) & "','" & TestData.Test_RFFreq(2) & "')"

            If TestError = False Then
                processNum = TestStepList.RF_NewFail
            Else
                processNum = TestStepList.RF_NewSuc
            End If
        End If

        If DBCommand(DBCmd) = False Then
            GoTo dbFail
        End If

        If TDDataSet(TD_Data.TestStep) = "11" Then
            DBCmd = "INSERT INTO " & NonTDTableNow & "(TestStep,PV_SN,P1_DateTime,Fw_Ver,DivTemp,CtTemp,BatteryLv) VALUES('" & processNum & "','" & TestData.Test_Serial & "','" & NowDate & " " & NowTime & "','" & TestData.Test_Firmware & "','" & TestData.Test_Temperature(TempData.DivTemp) & "','" & TestData.Test_Temperature(TempData.CartTemp) & "','" & TestData.Test_Battery & "')"

            If DBCommand(DBCmd) = False Then
                txbWindow.AppendText("DataBase Save FAIL" & DBCmd & vbCrLf)
                GoTo dbFail
            End If

        End If

        For i = 1 To nudSaveCk.Value
            sucSwitch = False
            DBCmd = "UPDATE " & NonTDTableNow & " SET TestStep='" & processNum & "' WHERE PV_SN = '" & TestData.Test_Serial & "'"

            If DBCommand(DBCmd) = False Then
                GoTo dbFail
            End If

            DBCmd = "SELECT TestStep FROM " & NonTDTableNow & " WHERE PV_SN = '" & TestData.Test_Serial & "'"

            Dim tdState As Int16 = DBQueryScalar(DBCmd)

            If tdState = processNum Then
                sucSwitch = True
                Exit For
            End If
        Next

        If sucSwitch = False Then
            GoTo dbFail
        End If

        txbWindow.AppendText("DataBase Save Full Time : " & MeasureTimeFunc(MeasEnd) & vbCrLf)
        Return True

dbFail:
        txbWindow.AppendText("DataBase Save FAIL" & vbCrLf)
        MeasureTimeFunc(MeasEnd)
        TestError = False
        Return False

    End Function

    '저가형 ep
    Private Function dbEPSave() As Boolean
        MeasureTimeFunc(MeasStart)
        MainTextChange("DB입력중..")
        TestStep = TestList.DBWrite
        TestRunningState(testRunningList.Running, Color.Yellow)

        Dim sucSwitch As Boolean = False
        Dim chooseTDTable As String = TDTableNow

        DBCmd = "SELECT EXISTS(SELECT 1 FROM " & rfTableNow & " WHERE PV_SN='" & TestData.Test_Serial & "') AS A;"

        Dim DupYn As Boolean = DBQueryScalar(DBCmd)

        If DupYn = True Then
            DBCmd = "UPDATE " & rfTableNow & " SET TestDate='" & NowDate & "',TestTime='" & NowTime & "',EP_R1Vpp='" & TestData.Test_EPVpp(0) & "',EP_R1Freq='" & TestData.Test_EPFreq(0) & "',EP_R1PWidth='" & TestData.Test_EPPWidth(0) & "',EP_R1NWidth='" & TestData.Test_EPNWidth(0) & "',EP_R2Vpp='" & TestData.Test_EPVpp(1) & "',EP_R2Freq='" & TestData.Test_EPFreq(1) & "',EP_R2PWidth='" & TestData.Test_EPPWidth(1) & "',EP_R2NWidth='" & TestData.Test_EPNWidth(1) & "',EP_R3Vpp='" & TestData.Test_EPVpp(2) & "',EP_R3Freq='" & TestData.Test_EPFreq(2) & "',EP_R3PWidth='" & TestData.Test_EPPWidth(2) & "',EP_R3NWidth='" & TestData.Test_EPNWidth(2) & "' WHERE PV_SN = '" & TestData.Test_Serial & "'"

            If TestError = False Then
                processNum = TestStepList.RF_ReFail
            Else
                processNum = TestStepList.RF_ReSuc
            End If

        Else
            DBCmd = "INSERT INTO " & rfTableNow & "(PV_SN,TestDate,TestTime,EP_R1Vpp,EP_R1Freq,EP_R1PWidth,EP_R1NWidth,EP_R2Vpp,EP_R2Freq,EP_R2PWidth,EP_R2NWidth,EP_R3Vpp,EP_R3Freq,EP_R3PWidth,EP_R3NWidth) VALUES ('" & TestData.Test_Serial & "','" & NowDate & "','" & NowTime & "','" & TestData.Test_EPVpp(0) & "','" & TestData.Test_EPFreq(0) & "','" & TestData.Test_EPPWidth(0) & "','" & TestData.Test_EPNWidth(0) & "','" & TestData.Test_EPVpp(1) & "','" & TestData.Test_EPFreq(1) & "','" & TestData.Test_EPPWidth(1) & "','" & TestData.Test_EPNWidth(1) & "','" & TestData.Test_EPVpp(2) & "','" & TestData.Test_EPFreq(2) & "','" & TestData.Test_EPPWidth(2) & "','" & TestData.Test_EPNWidth(2) & "')"

            If TestError = False Then
                processNum = TestStepList.RF_NewFail
            Else
                processNum = TestStepList.RF_NewSuc
            End If
        End If

        If DBCommand(DBCmd) = False Then
            GoTo dbFail
        End If

        If Not formType = formTypeList.prdHFLDMEP Then
            chooseTDTable = NonTDTableNow
            If TDDataSet(TD_Data.TestStep) = "11" Then
                DBCmd = "INSERT INTO " & chooseTDTable & "(TestStep,PV_SN,P1_DateTime,Fw_Ver,DivTemp,CtTemp,BatteryLv) VALUES('" & processNum & "','" & TestData.Test_Serial & "','" & NowDate & " " & NowTime & "','" & TestData.Test_Firmware & "','" & TestData.Test_Temperature(TempData.DivTemp) & "','" & TestData.Test_Temperature(TempData.CartTemp) & "','" & TestData.Test_Battery & "')"

                If DBCommand(DBCmd) = False Then
                    txbWindow.AppendText("DataBase Save FAIL" & DBCmd & vbCrLf)
                    GoTo dbFail
                End If
            End If
        End If



        For i = 1 To nudSaveCk.Value
            sucSwitch = False
            DBCmd = "UPDATE " & chooseTDTable & " SET TestStep='" & processNum & "' WHERE PV_SN = '" & TestData.Test_Serial & "'"

            If DBCommand(DBCmd) = False Then
                GoTo dbFail
            End If

            DBCmd = "SELECT TestStep FROM " & chooseTDTable & " WHERE PV_SN = '" & TestData.Test_Serial & "'"

            Dim tdState As Int16 = DBQueryScalar(DBCmd)

            If tdState = processNum Then
                sucSwitch = True
                Exit For
            End If
        Next

        If sucSwitch = False Then
            GoTo dbFail
        End If

        txbWindow.AppendText("DataBase Save Full Time : " & MeasureTimeFunc(MeasEnd) & vbCrLf)
        TestRunningState(testRunningList.Success, Color.Green)
        Return True

dbFail:
        txbWindow.AppendText("DataBase Save FAIL" & vbCrLf)
        MeasureTimeFunc(MeasEnd)
        TestRunningState(testRunningList.Fail, Color.Red)
        TestError = False
        Return False

    End Function


    Private Function dbLdmEpSave() As Boolean ''ldm (ep)
        MeasureTimeFunc(MeasStart)
        MainTextChange("DB입력중..")
        TestStep = TestList.DBWrite
        TestRunningState(testRunningList.Running, Color.Yellow)

        Dim sucSwitch As Boolean = False

        DBCmd = "SELECT EXISTS(SELECT 1 FROM " & ldmRfTestTableNow & " WHERE PV_SN='" & TestData.Test_Serial & "') AS A;"

        Dim DupYn As Boolean = DBQueryScalar(DBCmd)

        If DupYn = True Then
            DBCmd = "UPDATE " & ldmRfTestTableNow & " SET TestDate='" & NowDate & "',TestTime='" & NowTime & "',EP_R1Vpp='" & TestData.Test_EPVpp(0) & "',EP_R1Freq='" & TestData.Test_EPFreq(0) & "',EP_R1PWidth='" & TestData.Test_EPPWidth(0) & "',EP_R1NWidth='" & TestData.Test_EPNWidth(0) & "',EP_R2Vpp='" & TestData.Test_EPVpp(1) & "',EP_R2Freq='" & TestData.Test_EPFreq(1) & "',EP_R2PWidth='" & TestData.Test_EPPWidth(1) & "',EP_R2NWidth='" & TestData.Test_EPNWidth(1) & "',EP_R3Vpp='" & TestData.Test_EPVpp(2) & "',EP_R3Freq='" & TestData.Test_EPFreq(2) & "',EP_R3PWidth='" & TestData.Test_EPPWidth(2) & "',EP_R3NWidth='" & TestData.Test_EPNWidth(2) & "',TestResult='" & TestError & "' WHERE PV_SN = '" & TestData.Test_Serial & "'"

            If TestError = False Then
                processNum = TestStepList.RF_ReFail
            Else
                processNum = TestStepList.RF_ReSuc
            End If

        Else
            DBCmd = "INSERT INTO " & ldmRfTestTableNow & "(PV_SN,TestDate,TestTime,EP_R1Vpp,EP_R1Freq,EP_R1PWidth,EP_R1NWidth,EP_R2Vpp,EP_R2Freq,EP_R2PWidth,EP_R2NWidth,EP_R3Vpp,EP_R3Freq,EP_R3PWidth,EP_R3NWidth,TestResult) VALUES ('" & TestData.Test_Serial & "','" & NowDate & "','" & NowTime & "','" & TestData.Test_EPVpp(0) & "','" & TestData.Test_EPFreq(0) & "','" & TestData.Test_EPPWidth(0) & "','" & TestData.Test_EPNWidth(0) & "','" & TestData.Test_EPVpp(1) & "','" & TestData.Test_EPFreq(1) & "','" & TestData.Test_EPPWidth(1) & "','" & TestData.Test_EPNWidth(1) & "','" & TestData.Test_EPVpp(2) & "','" & TestData.Test_EPFreq(2) & "','" & TestData.Test_EPPWidth(2) & "','" & TestData.Test_EPNWidth(2) & "','" & TestError & "')"

            If TestError = False Then
                processNum = TestStepList.RF_NewFail
            Else
                processNum = TestStepList.RF_NewSuc
            End If
        End If

        If DBCommand(DBCmd) = False Then
            GoTo dbFail
        End If


        For i = 1 To nudSaveCk.Value
            sucSwitch = False
            DBCmd = "UPDATE " & ldmTableNow & " SET TestStep='" & processNum & "' WHERE PV_SN = '" & TestData.Test_Serial & "'"

            If DBCommand(DBCmd) = False Then
                GoTo dbFail
            End If

            DBCmd = "SELECT TestStep FROM " & ldmTableNow & " WHERE PV_SN = '" & TestData.Test_Serial & "'"

            Dim tdState As Int16 = DBQueryScalar(DBCmd)

            If tdState = processNum Then
                sucSwitch = True
                Exit For
            End If
        Next

        If sucSwitch = False Then
            GoTo dbFail
        End If

        txbWindow.AppendText("DataBase Save Full Time : " & MeasureTimeFunc(MeasEnd) & vbCrLf)
        TestRunningState(testRunningList.Success, Color.Green)
        Return True

dbFail:
        txbWindow.AppendText("DataBase Save FAIL" & vbCrLf)
        MeasureTimeFunc(MeasEnd)
        TestRunningState(testRunningList.Fail, Color.Red)
        TestError = False
        Return False

    End Function



    Private Function dbHFSave() As Boolean
        MeasureTimeFunc(MeasStart)
        MainTextChange("DB입력중..")
        TestStep = TestList.DBWrite
        TestRunningState(testRunningList.Running, Color.Yellow)

        processNum = 0
        DBCmd = "SELECT EXISTS(SELECT 1 FROM " & hfTableNow & " WHERE PV_SN='" & TestData.Test_Serial & "') AS A;"

        Dim DupYn As Boolean = DBQueryScalar(DBCmd)

        If DupYn = True Then
            DBCmd = "UPDATE " & hfTableNow & " SET TestDate = '" & NowDate & "', TestTime = '" & NowTime & "', FW_Ver = '" & TestData.Test_Firmware & "', BatteryLv = '" & TestData.Test_Battery & "', DivTemp = '" & TestData.Test_Temperature(TempData.DivTemp) & "', CtTemp = '" & TestData.Test_Temperature(TempData.CartTemp) & "', HF_R1Value = '" & TestData.Test_HFData(HifuTest_Step.Step1) & "', HF_R2Value = '" & TestData.Test_HFData(HifuTest_Step.Step2) & "', HF_R3Value = '" & TestData.Test_HFData(HifuTest_Step.step3) & "' WHERE PV_SN = '" & TestData.Test_Serial & "'"
            If TestError = False Then
                processNum = TestStepList.HF_ReFail
            Else
                processNum = TestStepList.HF_ReSuc
            End If
        Else
            DBCmd = "INSERT INTO " & hfTableNow & "(PV_SN,TestDate,TestTime,FW_Ver,BatteryLv,DivTemp,CtTemp,HF_R1Value,HF_R2Value,HF_R3Value) VALUES ('" & TestData.Test_Serial & "','" & NowDate & "','" & NowTime & "','" & TestData.Test_Firmware & "','" & TestData.Test_Battery & "','" & TestData.Test_Temperature(TempData.DivTemp) & "','" & TestData.Test_Temperature(TempData.CartTemp) & "','" & TestData.Test_HFData(HifuTest_Step.Step1) & "','" & TestData.Test_HFData(HifuTest_Step.Step2) & "','" & TestData.Test_HFData(HifuTest_Step.step3) & "')"

            If TestError = False Then
                processNum = TestStepList.HF_NEWFail
            Else
                processNum = TestStepList.HF_NewSuc
            End If
        End If

        If DBCommand(DBCmd) = False Then
            GoTo dbFail
        End If


        Dim sucSwitch As Boolean = False

        For i = 1 To nudSaveCk.Value
            sucSwitch = False
            DBCmd = "UPDATE " & TDTableNow & " SET TestStep='" & processNum & "', Ct_Model='" & ModelName & "', Ct_Type='" & CartTypeName & "',Ct_Frequency='" & TDDataSet(TD_Data.Freq) & "',P1_Date='" & NowDate & "',P1_Time='" & NowTime & "',P1_Model='" & ModelName & "',P1_CartType='" & CartTypeName & "',P1_Frequency='" & TDDataSet(TD_Data.Freq) & "' WHERE PV_SN = '" & TestData.Test_Serial & "'"
            If DBCommand(DBCmd) = False Then
                GoTo dbFail
            End If

            DBCmd = "SELECT TestStep FROM " & TDTableNow & " WHERE PV_SN = '" & TestData.Test_Serial & "'"

            Dim tdState As String = DBQueryScalar(DBCmd)

            If tdState = processNum Then
                sucSwitch = True
                Exit For
            End If
        Next

        If sucSwitch = False Then
            GoTo dbFail
        End If

        txbWindow.AppendText("DataBase Save Full Time : " & MeasureTimeFunc(MeasEnd) & vbCrLf)
        TestRunningState(testRunningList.Success, Color.Green)
        Return True

dbFail:
        txbWindow.AppendText("DataBase Save FAIL" & vbCrLf)
        MeasureTimeFunc(MeasEnd)
        TestRunningState(testRunningList.Fail, Color.Red)
        TestError = False
        Return False

    End Function


    Private Function dbLDMSave() As Boolean
        MeasureTimeFunc(MeasStart)
        MainTextChange("DB입력중..")
        TestStep = TestList.DBWrite
        TestRunningState(testRunningList.Running, Color.Yellow)

        processNum = 0
        DBCmd = "SELECT EXISTS(SELECT 1 FROM " & ldmTestTableNow & " WHERE PV_SN='" & TestData.Test_Serial & "') AS A;"

        Dim DupYn As Boolean = DBQueryScalar(DBCmd)

        If DupYn = True Then
            DBCmd = "UPDATE " & ldmTestTableNow & " SET TestDate = '" & NowDate & "', TestTime = '" & NowTime & "', FW_Ver = '" & TestData.Test_Firmware & "', BatteryLv = '" & TestData.Test_Battery & "', DivTemp = '" & TestData.Test_Temperature(TempData.DivTemp) & "', CtTemp = '" & TestData.Test_Temperature(TempData.CartTemp) & "', LDM_R1Value = '" & TestData.Test_HFData(HifuTest_Step.Step1) & "', LDM_R2Value = '" & TestData.Test_HFData(HifuTest_Step.Step2) & "', LDM_R3Value = '" & TestData.Test_HFData(HifuTest_Step.step3) & "', TestResult ='" & TestError & "' WHERE PV_SN = '" & TestData.Test_Serial & "'"
            If TestError = False Then
                processNum = TestStepList.HF_ReFail
            Else
                processNum = TestStepList.HF_ReSuc
            End If
        Else
            DBCmd = "INSERT INTO " & ldmTestTableNow & "(PV_SN,TestDate,TestTime,FW_Ver,BatteryLv,DivTemp,CtTemp,LDM_R1Value,LDM_R2Value,LDM_R3Value,TestResult) VALUES ('" & TestData.Test_Serial & "','" & NowDate & "','" & NowTime & "','" & TestData.Test_Firmware & "','" & TestData.Test_Battery & "','" & TestData.Test_Temperature(TempData.DivTemp) & "','" & TestData.Test_Temperature(TempData.CartTemp) & "','" & TestData.Test_HFData(HifuTest_Step.Step1) & "','" & TestData.Test_HFData(HifuTest_Step.Step2) & "','" & TestData.Test_HFData(HifuTest_Step.step3) & "','" & TestError & "')"

            If TestError = False Then
                processNum = TestStepList.HF_NEWFail
            Else
                processNum = TestStepList.HF_NewSuc
            End If
        End If

        If DBCommand(DBCmd) = False Then
            GoTo dbFail
        End If

        If formType = formTypeList.prdLDM Then
            Dim sucSwitch As Boolean = False

            For i = 1 To nudSaveCk.Value
                sucSwitch = False
                DBCmd = "UPDATE " & ldmTableNow & " SET TestStep='" & processNum & "', Ct_Model='" & ModelName & "', Ct_Type='" & CartTypeName & "',Ct_Frequency='" & LDM_DataSet(LDM_Data.freq_1) & "',Ct_Frequency2='" & LDM_DataSet(LDM_Data.freq_2) & "',Ct_Frequency3='" & LDM_DataSet(LDM_Data.freq_3) & "',P1_Date='" & NowDate & "',P1_Time='" & NowTime & "',P1_Model='" & ModelName & "',P1_CartType='" & CartTypeName & "',P1_Frequency='" & LDM_DataSet(LDM_Data.freq_1) & "' WHERE PV_SN = '" & TestData.Test_Serial & "'"
                If DBCommand(DBCmd) = False Then
                    GoTo dbFail
                End If

                DBCmd = "SELECT TestStep FROM " & ldmTableNow & " WHERE PV_SN = '" & TestData.Test_Serial & "'"

                Dim tdState As String = DBQueryScalar(DBCmd)

                If tdState = processNum Then
                    sucSwitch = True
                    Exit For
                End If
            Next

            If sucSwitch = False Then
                GoTo dbFail
            End If

        End If

        txbWindow.AppendText("DataBase Save Full Time : " & MeasureTimeFunc(MeasEnd) & vbCrLf)
        TestRunningState(testRunningList.Success, Color.Green)
        Return True

dbFail:
        txbWindow.AppendText("DataBase Save FAIL" & vbCrLf)
        MeasureTimeFunc(MeasEnd)
        TestRunningState(testRunningList.Fail, Color.Red)
        TestError = False
        Return False

    End Function

    Private Function DBSave() As Boolean
        MeasureTime(MeasStart)

        Dim NowDate As String = Format(Now, "yyyy") & "-" & Format(Now, "MM") & "-" & Format(Now, "dd")
        Dim NowTime As String = Format(Now, "HH") & ":" & Format(Now, "mm") & ":" & Format(Now, "ss")
        DBCmd = "SELECT EXISTS(SELECT 1 FROM " & hfTableNow & " WHERE PV_SN='" & TestData.Test_Serial & "') AS A;"

        Dim DupYn As Boolean = DBQueryScalar(DBCmd)

        If DupYn = True Then
            DBCmd = "UPDATE " & hfTableNow & " SET TestDate = '" & NowDate & "', TestTime = '" & NowTime & "', FW_Ver = '" & TestData.Test_Firmware & "', BatteryLv = '" & TestData.Test_Battery & "', DivTemp = '" & TestData.Test_Temperature(TempData.DivTemp) & "', CtTemp = '" & TestData.Test_Temperature(TempData.CartTemp) & "', HF_R1Value = '" & TestData.Test_HFData(HifuTest_Step.Step1) & "', HF_R2Value = '" & TestData.Test_HFData(HifuTest_Step.Step2) & "', HF_R3Value = '" & TestData.Test_HFData(HifuTest_Step.step3) & "' WHERE PV_SN = '" & TestData.Test_Serial & "'"
        Else
            DBCmd = "INSERT INTO " & hfTableNow & "(PV_SN,TestDate,TestTime,FW_Ver,BatteryLv,DivTemp,CtTemp,HF_R1Value,HF_R2Value,HF_R3Value) VALUE('" & TestData.Test_Serial & "','" & NowDate & "','" & NowTime & "','" & TestData.Test_Firmware & "','" & TestData.Test_Battery & "','" & TestData.Test_Temperature(TempData.DivTemp) & "','" & TestData.Test_Temperature(TempData.CartTemp) & "','" & TestData.Test_HFData(HifuTest_Step.Step1) & "','" & TestData.Test_HFData(HifuTest_Step.Step2) & "','" & TestData.Test_HFData(HifuTest_Step.step3) & "')"
        End If

        DBCmd = "SELECT EXISTS(SELECT 1 FROM" & rfTableNow & "WHERE PV_SN='" & TestData.Test_Serial & "') AS A;"

        DupYn = DBQueryScalar(DBCmd)

        If DupYn = True Then
            DBCmd = "UPDATE " & rfTableNow & " SET TestDate='" & NowDate & "',TestTime='" & NowTime & "',RF_R1Vrms='" & TestData.Test_RFVRMS(0) & "',RF_R1Freq='" & TestData.Test_RFFreq(0) & "',RF_R2Vrms='" & TestData.Test_RFVRMS(1) & "',RF_R2Freq='" & TestData.Test_RFFreq(1) & "',RF_R3Vrms='" & TestData.Test_RFVRMS(2) & "',RF_R3Freq='" & TestData.Test_RFFreq(2) & "',MC_R1Wave='" & TestData.Test_MCWidth(0) & "',MC_R1Vpp='" & TestData.Test_MCVpp(0) & "',MC_R1Freq='" & TestData.Test_MCFreq(0) & "',MC_R2Wave='" & TestData.Test_MCWidth(1) & "',MC_R2Vpp='" & TestData.Test_MCVpp(0) & "',MC_R2Freq='" & TestData.Test_MCFreq(0) & "',EP_R1Vpp='" & TestData.Test_EPVpp(0) & "',EP_R1Freq='" & TestData.Test_EPFreq(0) & "',EP_R1PWidth='" & TestData.Test_EPPWidth(0) & "',EP_R1NWidth='" & TestData.Test_EPNWidth(0) & "',EP_R2Vpp='" & TestData.Test_EPVpp(1) & "',EP_R2Freq='" & TestData.Test_EPFreq(1) & "',EP_R2PWidth='" & TestData.Test_EPPWidth(1) & "',EP_R2NWidth='" & TestData.Test_EPNWidth(1) & "',EP_R3Vpp='" & TestData.Test_EPVpp(2) & "',EP_R3Freq='" & TestData.Test_EPFreq(2) & "',EP_R3PWidth='" & TestData.Test_EPPWidth(2) & "',EP_R3NWidth='" & TestData.Test_EPNWidth(2) & "' WHERE PV_SN = '" & TestData.Test_Serial & "'"
        Else
            DBCmd = "INSERT INTO " & rfTableNow & "(PV_SN,TestDate,TestTime,RF_R1Vrms,RF_R1Freq,RF_R2Vrms,RF_R2Freq,RF_R3Vrms,RF_R3Freq,MC_R1Wave,MC_R1Vpp,MC_R1Freq,MC_R2Wave,MC_R2Vpp,MC_R2Freq,EP_R1Vpp,EP_R1Freq,EP_R1PWidth,EP_R1NWidth,EP_R2Vpp,EP_R2Freq,EP_R2PWidth,EP_R2NWidth,EP_R3Vpp,EP_R3Freq,EP_R3PWidth,EP_R3NWidth) VALUES ('" & TestData.Test_Serial & "','" & NowDate & "','" & NowTime & "','" & TestData.Test_RFVRMS(0) & "','" & TestData.Test_RFFreq(0) & "','" & TestData.Test_RFVRMS(1) & "','" & TestData.Test_RFFreq(1) & "','" & TestData.Test_RFVRMS(2) & "','" & TestData.Test_RFFreq(2) & "','" & TestData.Test_MCWidth(0) & "','" & TestData.Test_MCVpp(0) & "','" & TestData.Test_MCFreq(0) & "','" & TestData.Test_MCWidth(1) & "','" & TestData.Test_MCVpp(1) & "','" & TestData.Test_MCFreq(1) & "','" & TestData.Test_EPVpp(0) & "','" & TestData.Test_EPFreq(0) & "','" & TestData.Test_EPPWidth(0) & "','" & TestData.Test_EPNWidth(0) & "','" & TestData.Test_EPVpp(1) & "','" & TestData.Test_EPFreq(1) & "','" & TestData.Test_EPPWidth(1) & "','" & TestData.Test_EPNWidth(1) & "','" & TestData.Test_EPVpp(2) & "','" & TestData.Test_EPFreq(2) & "','" & TestData.Test_EPPWidth(2) & "','" & TestData.Test_EPNWidth(2) & "')"
        End If

        For i = 0 To nudSaveCk.Value - 1
            DBCmd = "Update " & TDTableNow & " SET TestStep = '" & SuccessCode & "', Ct_Model = '" & ModelName & "', Ct_Type = '" & CartTypeName & "',Ct_Frequency = '" & TDDataSet(TD_Data.Freq) & "', P1_Date = '" & NowDate & "', P1_Time = '" & NowTime & "', P1_Model = '" & ModelName & "', P1_CartType = '" & CartTypeName & "', P1_Frequency = '" & TDDataSet(TD_Data.Freq) & "' WHERE PV_SN = '" & TestData.Test_Serial & "'"

            If DBCommand(DBCmd) = False Then
                txbWindow.AppendText("DataBase Save : FAIL" & vbCrLf)
                Return True
            End If

            DBCmd = "SELECT TestStep FROM " & TDTableNow & " WHERE PV_SN = '" & TestData.Test_Serial & "'"

            Dim tdState As Int16 = DBQueryScalar(DBCmd)

            If tdState = SuccessCode Then
                Exit For
            End If
        Next

        txbWindow.AppendText("[" & MeasureTime(MeasEnd) & "ms] DataBase Save : Success" & vbCrLf)
        MeasureTime(MeasStart)

        Dim csvData As String = "" & NowDate & "," & NowTime & "," & TestData.Test_Serial & "," & TestData.Test_Firmware & "," & TestData.Test_Battery & "," & TestData.Test_Temperature(TempData.DivTemp) & "," & TestData.Test_Temperature(TempData.CartTemp) & "," & TestData.Test_HFData(HifuTest_Step.Step1) & "," & TestData.Test_HFInterval(HifuTest_Diff.Step1_2) & "," & TestData.Test_HFData(HifuTest_Step.Step2) & "," & TestData.Test_HFInterval(HifuTest_Diff.Step2_3) & "," & TestData.Test_HFData(HifuTest_Step.step3) & "," & TestData.Test_RFVRMS(0) & "," & TestData.Test_RFFreq(0) & "," & TestData.Test_RFVRMS(1) & "," & TestData.Test_RFFreq(1) & "," & TestData.Test_RFVRMS(2) & "," & TestData.Test_RFFreq(2) & "," & TestData.Test_MCWidth(0) & "," & TestData.Test_MCVpp(0) & "," & TestData.Test_MCWidth(1) & "," & TestData.Test_MCVpp(1) & "," & TestData.Test_EPVpp(0) & "," & TestData.Test_EPFreq(0) & "," & TestData.Test_EPPWidth(0) & "," & TestData.Test_EPNWidth(0) & "," & TestData.Test_EPVpp(1) & "," & TestData.Test_EPFreq(1) & "," & TestData.Test_EPPWidth(1) & "," & TestData.Test_EPNWidth(1) & "," & TestData.Test_EPVpp(2) & "," & TestData.Test_EPFreq(2) & "," & TestData.Test_EPPWidth(2) & "," & TestData.Test_EPNWidth(2) & ""

        If Save_Csv(NowDate & "," & NowTime & "," & csvData) Then
            txbWindow.AppendText("CSV Data Save : FAIL" & vbCrLf)
            Return True
        End If

        txbWindow.AppendText("[" & MeasureTime(MeasEnd) & "ms] CSV Data Save : Success" & vbCrLf)
        Return False

    End Function

    Private Sub btnEnd_Click(sender As Object, e As EventArgs) Handles btnEnd.Click
        End
    End Sub

    Private Sub btnSetup_Click(sender As Object, e As EventArgs) Handles btnSetup.Click
        pnOption.Location = New Drawing.Point(6, 1)
        pnMain.Visible = False
        pnOption.Visible = True
    End Sub

    Private Sub btnOpExit_Click(sender As Object, e As EventArgs) Handles btnOpExit.Click
        pnMain.Location = New Drawing.Point(6, 1)
        pnMain.Visible = True
        pnOption.Visible = False
        loadLocalFile()
        Data_Setting()
        changeMode()

        txbBarcode.ReadOnly = False
        txbBarcode.Focus()
    End Sub

    Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
        ConfigIniSave()
    End Sub

    Private Sub ConfigIniSave()
        Dim FileName As String, TrigType As String, UnitType As String, RegText As String
        Dim comtext As String = ""
        Dim ObjWriter As StreamWriter
        On Error GoTo WR_File_Error

        '' Config 폴더/파일이 없거나 모델이 선택되지 않은 경우 예외 처리
        If comboBoxModel.SelectedItem Is Nothing OrElse comboBoxModel.SelectedIndex < 0 Then
            MsgBox("모델을 선택해 주세요.", vbExclamation)
            Exit Sub
        End If

        Dim FilePath As String = System.AppDomain.CurrentDomain.BaseDirectory() & "Config\" & comboBoxModel.SelectedItem.Key.ToString

        If Dir(FilePath, vbDirectory) = "" Then
            MkDir(FilePath)
        End If

        For i = 0 To DataSaveCount

            FileName = FilePath & "\" & DataSaveName(i) & ".ini"

            Select Case i
                Case 0 ''HIFU 스펙트럼 세팅값
                    comtext = txbSpan.Text & "," & txbRBW.Text & "," & nudHFCount.Text & "," & nudHFRun.Text & "," & nudHFwait.Text & "," & txbFrStep1.Text & "," & txbFrStep2.Text & "," & txbFrStep3.Text & "," & txbHFStDelay.Text & "," & txbHFLowShot.Text & "," & txbHFReCnt.Text & "," & txbHFeffect.Text & "," & txbHFReCkCnt.Text & "," & txbDSDelay.Text & "," & txbHFRefLev.Text
                Case 1
                    If rdbRFTrAuto.Checked Then
                        TrigType = rdbRFTrAuto.Text
                    Else
                        TrigType = rdbRFtrNormal.Text
                    End If

                    If rdbRFUnitV.Checked Then
                        UnitType = rdbRFUnitV.Text
                    Else
                        UnitType = rdbRFUnitA.Text
                    End If

                    comtext = TrigType & "," & txbRFtime.Text & "," & UnitType & "," & nudRFScale.Text & "," & txbRFDelay.Text & "," & nudRFRun.Text & "," & nudRFCh.Value & "," & nudRFTrgLv.Value & "," & txbRFWdtime.Text & "," & txbRFWdDelay.Text & "," & nudRFWdTrgLv.Value & "," & nudRFWdRun.Value

                Case 2
                    If rdbMCTrAuto.Checked Then
                        TrigType = rdbMCTrAuto.Text
                    Else
                        TrigType = rdbMCtrNormal.Text
                    End If

                    If rdbMCUnitV.Checked Then
                        UnitType = rdbMCUnitV.Text
                    Else
                        UnitType = rdbMCUnitA.Text
                    End If

                    comtext = TrigType & "," & txbMCFVtime.Text & "," & UnitType & "," & nudMCScale.Text & "," & txbMCFVDelay.Text & "," & nudMCFVRun.Text & "," & nudMCCh.Value & "," & nudMCFVTrgLv.Value & "," & txbMCWdtime.Text & "," & txbMCWdDelay.Text & "," & nudMCWdTrgLv.Value & "," & nudMCWdRun.Value

                Case 3
                    If rdbEPTrAuto1.Checked Then
                        TrigType = rdbEPTrAuto1.Text
                    Else
                        TrigType = rdbEPtrNormal1.Text
                    End If

                    If rdbEPUnitV1.Checked Then
                        UnitType = rdbEPUnitV1.Text
                    Else
                        UnitType = rdbEPUnitA1.Text
                    End If

                    Dim epConfig1 As String = TrigType & "," & txbEPFVtime1.Text & "," & UnitType & "," & nudEPScale1.Text & "," & txbEPFVDelay1.Text & "," & nudEPFVRun1.Text & "," & txbEPFreq1.Text & "," & txbEPFreq2.Text & "," & txbEPFreq3.Text & "," & nudEPCh1.Value & "," & nudEPFVTrgLv1.Value

                    If rdbEPTrAuto2.Checked Then
                        TrigType = rdbEPTrAuto2.Text
                    Else
                        TrigType = rdbEPtrNormal2.Text
                    End If

                    If rdbEPUnitV2.Checked Then
                        UnitType = rdbEPUnitV2.Text
                    Else
                        UnitType = rdbEPUnitA2.Text
                    End If

                    Dim epConfig2 As String = TrigType & "," & txbEPFVtime2.Text & "," & UnitType & "," & nudEPScale2.Text & "," & txbEPFVDelay2.Text & "," & nudEPFVRun2.Text & "," & txbEPFreq1.Text & "," & txbEPFreq2.Text & "," & txbEPFreq3.Text & "," & nudEPCh2.Value & "," & nudEPFVTrgLv2.Value

                    If rdbEPTrAuto3.Checked Then
                        TrigType = rdbEPTrAuto3.Text
                    Else
                        TrigType = rdbEPtrNormal3.Text
                    End If

                    If rdbEPUnitV3.Checked Then
                        UnitType = rdbEPUnitV3.Text
                    Else
                        UnitType = rdbEPUnitA3.Text
                    End If

                    Dim epConfig3 As String = TrigType & "," & txbEPFVtime3.Text & "," & UnitType & "," & nudEPScale3.Text & "," & txbEPFVDelay3.Text & "," & nudEPFVRun3.Text & "," & txbEPFreq1.Text & "," & txbEPFreq2.Text & "," & txbEPFreq3.Text & "," & nudEPCh3.Value & "," & nudEPFVTrgLv3.Value

                    comtext = epConfig1 & vbCrLf & epConfig2 & vbCrLf & epConfig3

                Case 4 '' 평가 
                    comtext = txbFirmVer.Text & "," & txbBatMin.Text & "," & txbBatMax.Text & "," & txbTpDevMin.Text & "," & txbTpDevMax.Text _
                        & "," & txbTpCartMin.Text & "," & txbTpCartMax.Text & "," & txbHFOutMin.Text & "," & txbHFOutMax.Text & "," & txbHFMin.Text & "," &
                        txbRFVRmin1.Text & "," & txbRFVRmax1.Text & "," & txbRFVRmin2.Text & "," & txbRFVRmax2.Text & "," & txbRFVRmin3.Text & "," &
                        txbRFVRmax3.Text & "," & txbMCVPmin.Text & "," & txbMCVPmax.Text & "," & txbMCDYmin.Text & "," & txbMCDYmax.Text & "," & txbMCFrmin.Text &
                        "," & txbMCFrmax.Text & "," & txbEPVPmin.Text & "," & txbEPVPmax.Text & "," & txbEPDYmin1.Text & "," & txbEPDYmax1.Text & "," &
                        txbEPDYmin2.Text & "," & txbEPDYmax2.Text & "," & txbEPDYmin3.Text & "," & txbEPDYmax3.Text & "," & txbHFLDMMax3.Text & "," & txbHFLDMMin3.Text _ ''txbRHueMin ~
                        & "," & txbHFLDMMax2.Text & "," & txbHFLDMMin2.Text & "," & txbHFLDMMax1.Text & "," & txbHFLDMMin1.Text & "," & txbLDMVRmax1.Text & "," &
                        txbLDMVRmin1.Text & "," & txbLDMVRmax2.Text & "," & txbLDMVRmin2.Text & "," & txbLDMVRmax3.Text & "," & txbLDMVRmin3.Text & "," & txbFirmVer_AL.Text & "," & '' ~ txbYBgtMax1
                        txbTpDevMin_AL.Text & "," & txbTpDevMax_AL.Text & "," & txbTpCartMin_AL.Text & "," & txbTpCartMax_AL.Text & "," & txbBatMin_AL.Text & "," &
                        txbBatMax_AL.Text & "," & txbRFVRmin1_AL.Text & "," & txbRFVRmax1_AL.Text & "," & txbRFVRmin2_AL.Text & "," & txbRFVRmax2_AL.Text & "," &
                        txbRFVRmin3_AL.Text & "," & txbRFVRmax3_AL.Text & "," & txbEPVPmin_AL.Text & "," & txbEPVPmax_AL.Text & "," & txbEPDYmin1_AL.Text & "," &
                        txbEPDYmax1_AL.Text & "," & txbEPDYmin2_AL.Text & "," & txbEPDYmax2_AL.Text & "," & txbEPDYmin3_AL.Text & "," & txbEPDYmax3_AL.Text & "," &
                        txbBDVRmin1_AL.Text & "," & txbBDVRmax1_AL.Text & "," & txbBDVRmin2_AL.Text & "," & txbBDVRmax2_AL.Text & "," & txbBDVRmin3_AL.Text & "," &
                        txbBDVRmax3_AL.Text & "," & txbDSfw_st.Text & "," & txbDSbat_stMin.Text & "," & txbDSbat_stMax.Text & "," & txbDSTmpDe_stMin.Text & "," &
                        txbDSTmpDe_stMax.Text & "," & txbDSTmpCa_stMin.Text & "," & txbDSTmpCa_stMax.Text & "," & txbDShfOut_stMin.Text & "," & txbDShfOut_stMax.Text & "," &
                        txbDShfDif_st.Text & "," & txbDSSub_Min.Text & "," & txbDSSub_Max.Text

                Case 5 ''계측기 설정
                    For cnt = 0 To dgvID.Rows.Count - 2
                        If cnt = 0 Then
                            comtext = dgvID.Rows(cnt).Cells(0).Value & "/" & dgvID.Rows(cnt).Cells(1).Value & "/" & dgvID.Rows(cnt).Cells(2).Value
                        Else
                            comtext = comtext & "," & dgvID.Rows(cnt).Cells(0).Value & "/" & dgvID.Rows(cnt).Cells(1).Value & "/" & dgvID.Rows(cnt).Cells(2).Value
                        End If
                    Next

                Case 6
                    If cbbSpecID.SelectedIndex = -1 And cbbScopeID.SelectedIndex = -1 Then
                        comtext = ""
                    Else
                        comtext = cbbScopeID.SelectedItem & "," & cbbSpecID.SelectedItem
                    End If

                Case 7
                    Dim ImgProcess As String
                    If rdbimgSave.Checked = True Then
                        ImgProcess = ImgSave
                    Else
                        ImgProcess = ImgCvt
                    End If

                    comtext = cbbWebCam.SelectedItem & "," & txbCamDelay.Text & "," & txbRedCdn_X1.Text & "," & txbRedCdn_Y1.Text & "," & txbYelCdn_X1.Text & "," & txbYelCdn_Y1.Text & "," & txbRedCdn_X2.Text & "," & txbRedCdn_Y2.Text & "," & txbYelCdn_X2.Text & "," & txbYelCdn_Y2.Text & "," & txbAround.Text & "," & txbInc.Text & "," & ImgProcess & "," & nudLEDStart.Value & "," & nudLedRe.Value
                Case 8
                    comtext = txbJgTimeout.Text & "," & txbJgDelay.Text & "," & txbDTTimeout.Text
                Case 9
                    comtext = cbbSerial.SelectedItem & "," & cbbJgBaudRate.SelectedItem & "," & ckbScopeZ.Checked
                Case 10
                    comtext = nudStepDelay.Value & "," & nudSpTimeout.Value & "," & nudScTimeout.Value & "," & nudSaveCk.Value & "," & nudEPRe.Value & "," & nudOnRe.Value & "," & nudJigNum.Value & "," & txbTDSNHead.Text
            End Select

            File.Delete(FileName)
            ObjWriter = New StreamWriter(FileName, True)
            ObjWriter.Flush()
            ObjWriter.WriteLine(comtext)

            ObjWriter.Close()
        Next

        MsgBox("Save Success!!", vbInformation)

        Exit Sub

WR_File_Error:
        MsgBox("Config Save Fail!", vbCritical)
    End Sub

    Private Sub modeConfigSave()
        If modeSaveSwitch = True Then
            Dim FileName As String, TrigType As String, UnitType As String, RegText As String
            Dim comtext As String = ""
            Dim ObjWriter As StreamWriter
            Dim FilePath As String = System.AppDomain.CurrentDomain.BaseDirectory() & "\Config"

            On Error GoTo WR_File_Error

            If comboBoxModel.SelectedItem Is Nothing OrElse comboBoxModel.SelectedIndex = -1 Then
                MsgBox("모델을 선택해 주세요")
            End If

            If Dir(FilePath, vbDirectory) = "" Then
                MkDir(FilePath)
            End If
            FileName = FilePath & "\RecentSelectedModel.ini"

            comtext = comboBoxModel.SelectedItem.Key.ToString

            File.Delete(FileName)
            ObjWriter = New StreamWriter(FileName, True)
            ObjWriter.Flush()
            ObjWriter.WriteLine(comtext)

            ObjWriter.Close()
        End If

        Exit Sub

WR_File_Error:
        MsgBox("Config Save Fail!", vbCritical)
    End Sub

    Private Sub ConfigIniLoad()
        Dim FileName As String, ConfigStr As String, LoadData As String
        Dim ObjReader As StreamReader
        Dim FilePath As String = System.AppDomain.CurrentDomain.BaseDirectory() & "\config"
        Dim modelName As String = "MAXIMUM"

        SaveFileCK()

        If Dir(FilePath, vbDirectory) = "" Then
            MkDir(FilePath)
        End If

        If recentModelSwitch = False Then
            FileName = FilePath & "\RecentSelectedModel.ini"
            If File.Exists(FileName) Then
                ObjReader = New StreamReader(FileName, True)
                modelName = ObjReader.ReadLine
                ObjReader.Close()
            End If
            recentModelSwitch = True
            comboBoxModel.SelectedIndex = comboBoxModel.FindString(modelName)
        Else
            modelName = comboBoxModel.SelectedItem.key.ToString
        End If

        FilePath = FilePath & "\" & modelName

        If Dir(FilePath, vbDirectory) = "" Then
            MkDir(FilePath)
        End If
        For i = 0 To DataSaveCount
            FileName = FilePath & "\" & DataSaveName(i) & ".ini"

            If File.Exists(FileName) Then
                If i = 5 Then dgvID.Rows.Clear()
                ObjReader = New StreamReader(FileName, True)

                If i = 3 Then
                    ConfigStr = ObjReader.ReadToEnd
                    Dim normalizedConfig As String = ConfigStr.Replace(vbCrLf, vbLf).Replace(vbCr, vbLf)
                    Dim epConfigArray As String() = normalizedConfig.Split(New String() {vbLf}, StringSplitOptions.RemoveEmptyEntries)
                    multiEpConfig_LoadTxb(epConfigArray)
                    ObjReader.Close()
                    Continue For
                End If

                ConfigStr = ObjReader.ReadLine
                ObjReader.Close()

                For cnt = 0 To UBound(Split(ConfigStr, ","))
                    If InStr(ConfigStr, ",") > 0 Then
                        LoadData = Mid(ConfigStr, 1, InStr(ConfigStr, ",") - 1)
                        ConfigStr = Mid(ConfigStr, InStr(ConfigStr, ",") + 1, ConfigStr.Length)
                    Else
                        LoadData = ConfigStr
                    End If

                    Select Case i
                        Case 0
                            HF_LoadTxb(cnt, LoadData)
                        Case 1
                            RF_LoadTxb(cnt, LoadData)
                        Case 2
                            MC_LoadTxb(cnt, LoadData)
                        Case 3
                            EP_LoadTxb(cnt, LoadData)
                        Case 4
                            Standard_LoadTxb(cnt, LoadData)
                        Case 5
                            EquipList_LoadTxb(LoadData)
                        Case 6
                            Equip_LoadTxb(cnt, LoadData)
                        Case 7
                            LED_LoadTxb(cnt, LoadData)
                        Case 8
                            JIG_LoadTxb(cnt, LoadData)
                        Case 9
                            Comport_LoadTxb(cnt, LoadData)
                        Case 10
                            ETC_LoadTxb(cnt, LoadData)
                    End Select
                Next

            Else
                '' 해당 모델 경로에 ini가 없으면 이전 모델 값이 남지 않도록 해당 섹션만 초기화
                ConfigSectionReset(i)
            End If

        Next
    End Sub

    Private Sub SaveFileCK()
        DataSaveName(0) = "HF_Config"
        DataSaveName(1) = "RF_Config"
        DataSaveName(2) = "MC_Config"
        DataSaveName(3) = "EP_Config"
        DataSaveName(4) = "Standard_Config"
        DataSaveName(5) = "EquipList_Config"
        DataSaveName(6) = "Equip_Config"
        DataSaveName(7) = "LED_Config"
        DataSaveName(8) = "JIG_Config"
        DataSaveName(9) = "Comport_Config"
        DataSaveName(10) = "ETC_Config"
    End Sub

    '' 모델 전환 시 해당 경로에 ini가 없을 때 이전 모델의 값이 남지 않도록 섹션별 컨트롤 초기화
    Private Sub ConfigSectionReset(sectionIndex As Integer)
        Select Case sectionIndex
            Case 0 '' HF_Config
                txbSpan.Text = "0" : txbRBW.Text = "0" : nudHFCount.Text = "0" : nudHFRun.Text = "0" : nudHFwait.Text = "0"
                txbFrStep1.Text = "0" : txbFrStep2.Text = "0" : txbFrStep3.Text = "0" : txbHFStDelay.Text = "0" : txbHFLowShot.Text = "0"
                txbHFReCnt.Text = "0" : txbHFeffect.Text = "0" : txbHFReCkCnt.Text = "0" : txbDSDelay.Text = "0" : txbHFRefLev.Text = "0"
            Case 1 '' RF_Config
                rdbRFTrAuto.Checked = True
                txbRFtime.Text = "0" : rdbRFUnitV.Checked = True : nudRFScale.Text = "0" : txbRFDelay.Text = "0" : nudRFRun.Text = "0"
                nudRFCh.Value = nudRFCh.Minimum : nudRFTrgLv.Value = nudRFTrgLv.Minimum : txbRFWdtime.Text = "0" : txbRFWdDelay.Text = "0" : nudRFWdTrgLv.Value = nudRFWdTrgLv.Minimum : nudRFWdRun.Value = nudRFWdRun.Minimum
            Case 2 '' MC_Config
                rdbMCTrAuto.Checked = True
                txbMCFVtime.Text = "0" : rdbMCUnitV.Checked = True : nudMCScale.Text = "0" : txbMCFVDelay.Text = "0" : nudMCFVRun.Text = "0"
                nudMCCh.Value = nudMCCh.Minimum : nudMCFVTrgLv.Value = nudMCFVTrgLv.Minimum : txbMCWdtime.Text = "0" : txbMCWdDelay.Text = "0" : nudMCWdTrgLv.Value = nudMCWdTrgLv.Minimum : nudMCWdRun.Value = nudMCWdRun.Minimum
            Case 3 '' EP_Config
                rdbEPTrAuto1.Checked = True
                txbEPFVtime1.Text = "0" : rdbEPUnitV1.Checked = True : nudEPScale1.Text = "0" : txbEPFVDelay1.Text = "0" : nudEPFVRun1.Text = "0"
                txbEPFreq1.Text = "0" : txbEPFreq2.Text = "0" : txbEPFreq3.Text = "0" : nudEPCh1.Value = nudEPCh1.Minimum : nudEPFVTrgLv1.Value = nudEPFVTrgLv1.Minimum
                rdbEPTrAuto2.Checked = True
                txbEPFVtime2.Text = "0" : rdbEPUnitV2.Checked = True : nudEPScale2.Text = "0" : txbEPFVDelay2.Text = "0" : nudEPFVRun2.Text = "0"
                nudEPCh2.Value = nudEPCh2.Minimum : nudEPFVTrgLv2.Value = nudEPFVTrgLv2.Minimum
                rdbEPTrAuto3.Checked = True
                txbEPFVtime3.Text = "0" : rdbEPUnitV3.Checked = True : nudEPScale3.Text = "0" : txbEPFVDelay3.Text = "0" : nudEPFVRun3.Text = "0"
                nudEPCh3.Value = nudEPCh3.Minimum : nudEPFVTrgLv3.Value = nudEPFVTrgLv3.Minimum
            Case 4 '' Standard_Config
                txbFirmVer.Text = "0" : txbBatMin.Text = "0" : txbBatMax.Text = "0" : txbTpDevMin.Text = "0" : txbTpDevMax.Text = "0"
                txbTpCartMin.Text = "0" : txbTpCartMax.Text = "0" : txbHFOutMin.Text = "0" : txbHFOutMax.Text = "0" : txbHFMin.Text = "0"
                txbRFVRmin1.Text = "0" : txbRFVRmax1.Text = "0" : txbRFVRmin2.Text = "0" : txbRFVRmax2.Text = "0" : txbRFVRmin3.Text = "0" : txbRFVRmax3.Text = "0"
                txbMCVPmin.Text = "0" : txbMCVPmax.Text = "0" : txbMCDYmin.Text = "0" : txbMCDYmax.Text = "0" : txbMCFrmin.Text = "0" : txbMCFrmax.Text = "0"
                txbEPVPmin.Text = "0" : txbEPVPmax.Text = "0" : txbEPDYmin1.Text = "0" : txbEPDYmax1.Text = "0" : txbEPDYmin2.Text = "0" : txbEPDYmax2.Text = "0" : txbEPDYmin3.Text = "0" : txbEPDYmax3.Text = "0"
                txbHFLDMMax3.Text = "0" : txbHFLDMMin3.Text = "0" : txbHFLDMMax2.Text = "0" : txbHFLDMMin2.Text = "0" : txbHFLDMMax1.Text = "0" : txbHFLDMMin1.Text = "0"
                txbLDMVRmax1.Text = "0" : txbLDMVRmin1.Text = "0" : txbLDMVRmax2.Text = "0" : txbLDMVRmin2.Text = "0" : txbLDMVRmax3.Text = "0" : txbLDMVRmin3.Text = "0"
                txbFirmVer_AL.Text = "0" : txbTpDevMin_AL.Text = "0" : txbTpDevMax_AL.Text = "0" : txbTpCartMin_AL.Text = "0" : txbTpCartMax_AL.Text = "0" : txbBatMin_AL.Text = "0" : txbBatMax_AL.Text = "0"
                txbRFVRmin1_AL.Text = "0" : txbRFVRmax1_AL.Text = "0" : txbRFVRmin2_AL.Text = "0" : txbRFVRmax2_AL.Text = "0" : txbRFVRmin3_AL.Text = "0" : txbRFVRmax3_AL.Text = "0"
                txbEPVPmin_AL.Text = "0" : txbEPVPmax_AL.Text = "0" : txbEPDYmin1_AL.Text = "0" : txbEPDYmax1_AL.Text = "0" : txbEPDYmin2_AL.Text = "0" : txbEPDYmax2_AL.Text = "0" : txbEPDYmin3_AL.Text = "0" : txbEPDYmax3_AL.Text = "0"
                txbBDVRmin1_AL.Text = "0" : txbBDVRmax1_AL.Text = "0" : txbBDVRmin2_AL.Text = "0" : txbBDVRmax2_AL.Text = "0" : txbBDVRmin3_AL.Text = "0" : txbBDVRmax3_AL.Text = "0"
                txbDSfw_st.Text = "0" : txbDSbat_stMin.Text = "0" : txbDSbat_stMax.Text = "0" : txbDSTmpDe_stMin.Text = "0" : txbDSTmpDe_stMax.Text = "0"
                txbDSTmpCa_stMin.Text = "0" : txbDSTmpCa_stMax.Text = "0" : txbDShfOut_stMin.Text = "0" : txbDShfOut_stMax.Text = "0" : txbDShfDif_st.Text = "0" : txbDSSub_Min.Text = "0" : txbDSSub_Max.Text = "0"
            Case 5 '' EquipList_Config
                dgvID.Rows.Clear()
            Case 6 '' Equip_Config
                cbbScopeID.SelectedIndex = -1
                cbbSpecID.SelectedIndex = -1
                txbScopeID.Text = ""
                txbSpecID.Text = ""

            Case 7 '' LED_Config
                cbbWebCam.SelectedIndex = -1
                txbCamDelay.Text = "0" : txbRedCdn_X1.Text = "0" : txbRedCdn_Y1.Text = "0" : txbYelCdn_X1.Text = "0" : txbYelCdn_Y1.Text = "0"
                txbRedCdn_X2.Text = "0" : txbRedCdn_Y2.Text = "0" : txbYelCdn_X2.Text = "0" : txbYelCdn_Y2.Text = "0" : txbAround.Text = "0" : txbInc.Text = "0"
                rdbimgSave.Checked = True : nudLEDStart.Value = nudLEDStart.Minimum : nudLedRe.Value = nudLedRe.Minimum
            Case 8 '' JIG_Config
                txbJgTimeout.Text = "0" : txbJgDelay.Text = "0" : txbDTTimeout.Text = "0"
            Case 9 '' Comport_Config
                'cbbSerial.SelectedIndex = -1
                'cbbJgBaudRate.SelectedIndex = -1
                'ckbScopeZ.Checked = False
            Case 10 '' ETC_Config
                nudStepDelay.Value = nudStepDelay.Minimum : nudSpTimeout.Value = nudSpTimeout.Minimum : nudScTimeout.Text = "0" : nudSaveCk.Value = nudSaveCk.Minimum : nudEPRe.Value = nudEPRe.Minimum : nudOnRe.Value = nudOnRe.Minimum : nudJigNum.Value = nudJigNum.Minimum : txbTDSNHead.Text = "0"
        End Select
    End Sub

    Private Sub DataTextReset()
        txbTDSN.Text = "대기"
        txbDate.Text = "대기"
        txbFreq.Text = "대기"
        txbGrade.Text = "대기"
        txbVer.Text = "대기"
        txbVolt.Text = "대기"
        txbDevTmp.Text = "대기"
        txbCartTmp.Text = "대기"
    End Sub

    Private Sub DataColorReset()
        txbTDSN.BackColor = Color.White
        txbDate.BackColor = Color.White
        txbFreq.BackColor = Color.White
        txbGrade.BackColor = Color.White
        txbVer.BackColor = Color.White
        txbVolt.BackColor = Color.White
        txbDevTmp.BackColor = Color.White
        txbCartTmp.BackColor = Color.White
    End Sub

    Private Sub DataRefresh()
        txbTDSN.Refresh()
        txbDate.Refresh()
        txbFreq.Refresh()
        txbGrade.Refresh()
        txbVer.Refresh()
        txbVolt.Refresh()
        txbDevTmp.Refresh()
        txbCartTmp.Refresh()
    End Sub

    Private Sub StepTextReset()
        txbStep1.Text = "대기"
        txbStep2.Text = "대기"
        txbStep3.Text = "대기"
        txbStep4.Text = "대기"
        txbStep5.Text = "대기"
        txbStep6.Text = "대기"
        txbStep7.Text = "대기"
        txbStep8.Text = "대기"
        txbStep9.Text = "대기"
        txbStep10.Text = "대기"
    End Sub

    Private Sub StepColorReset()
        txbStep1.BackColor = Color.White
        txbStep2.BackColor = Color.White
        txbStep3.BackColor = Color.White
        txbStep4.BackColor = Color.White
        txbStep5.BackColor = Color.White
        txbStep6.BackColor = Color.White
        txbStep7.BackColor = Color.White
        txbStep8.BackColor = Color.White
        txbStep9.BackColor = Color.White
        txbStep10.BackColor = Color.White
    End Sub

    Private Sub StepRefresh()
        txbStep1.Refresh()
        txbStep2.Refresh()
        txbStep3.Refresh()
        txbStep4.Refresh()
        txbStep5.Refresh()
        txbStep6.Refresh()
        txbStep7.Refresh()
        txbStep8.Refresh()
        txbStep9.Refresh()
        txbStep10.Refresh()
    End Sub

    Private Sub SaveDataReset()
        TestData.Test_Serial = ""
        TestData.Test_Firmware = ""
        TestData.Test_Battery = 0
        ReDim TestData.Test_Temperature(0)
        ReDim TestData.Test_Temperature(TempData.CPUTemp)

        ReDim TestData.Test_HFData(HifuTest_Step.step5)
        ReDim TestData.Test_HFInterval(HifuTest_Step.step3 - 1)

        ReDim TestData.Test_RFVRMS(RFTest_Count)
        ReDim TestData.Test_RFFreq(RFTest_Count)

        ReDim TestData.Test_MCVpp(MCTest_Count)
        ReDim TestData.Test_MCWidth(MCTest_Count)
        ReDim TestData.Test_MCFreq(MCTest_Count)

        ReDim TestData.Test_EPVpp(EPTest_Count)
        ReDim TestData.Test_EPFreq(EPTest_Count)
        ReDim TestData.Test_EPPWidth(EPTest_Count)
        ReDim TestData.Test_EPNWidth(EPTest_Count)
    End Sub

    Private Sub HF_LoadTxb(cnt As Int16, LoadData As String)
        Select Case cnt
            Case 0
                txbSpan.Text = LoadData
            Case 1
                txbRBW.Text = LoadData
            Case 2
                nudHFCount.Text = LoadData
            Case 3
                nudHFRun.Text = LoadData
            Case 4
                nudHFwait.Text = LoadData
            Case 5
                txbFrStep1.Text = LoadData
            Case 6
                txbFrStep2.Text = LoadData
            Case 7
                txbFrStep3.Text = LoadData
            Case 8
                txbHFStDelay.Text = LoadData
            Case 9
                txbHFLowShot.Text = LoadData
            Case 10
                txbHFReCnt.Text = LoadData
            Case 11
                txbHFeffect.Text = LoadData
            Case 12
                txbHFReCkCnt.Text = LoadData
            Case 13
                txbDSDelay.Text = LoadData
            Case 14
                txbHFRefLev.Text = LoadData

            Case Else
                MsgBox("HF_잘못된 데이터가 존재합니다.", vbExclamation)
        End Select
    End Sub
    Private Sub Comport_LoadTxb(cnt As Int16, LoadData As String)
        Select Case cnt
            Case 0
                'LoadComportName()

                'For i = 0 To cbbSerial.Items.Count - 1
                '    cbbSerial.SelectedIndex = i
                '    If cbbSerial.SelectedItem = LoadData Then
                '        ParaComport = LoadData
                '        Exit For
                '    Else
                '        cbbSerial.SelectedIndex = -1
                '    End If
                'Next

                'btnSerial.Text = "스캔"

            Case 1

                For i = 0 To cbbJgBaudRate.Items.Count - 1
                    cbbJgBaudRate.SelectedIndex = i
                    If cbbJgBaudRate.SelectedItem = LoadData Then
                        Exit For
                    Else
                        cbbJgBaudRate.SelectedIndex = -1
                    End If
                Next

                'If ParaComport <> "" And LoadData <> "" Then
                '    OpenSerial(LoadData)
                'End If

            Case 2
                ckbScopeZ.Checked = LoadData
            Case Else
                MsgBox("Comport_잘못된 데이터가 존재합니다.", vbExclamation)
        End Select
    End Sub

    Private Sub ETC_LoadTxb(cnt As Int16, LoadData As String)
        Select Case cnt
            Case 0
                nudStepDelay.Value = LoadData
            Case 1
                nudSpTimeout.Value = LoadData
            Case 2
                nudScTimeout.Text = LoadData
            Case 3
                nudSaveCk.Value = LoadData
            Case 4
                nudEPRe.Value = LoadData
            Case 5
                nudOnRe.Value = LoadData
            Case 6
                nudJigNum.Value = LoadData
            Case 7
                txbTDSNHead.Text = LoadData
            Case Else
                MsgBox("ETC_잘못된 데이터가 존재합니다.", vbExclamation)
        End Select
    End Sub

    Private Sub JIG_LoadTxb(cnt As Int16, LoadData As String)
        Select Case cnt
            Case 0
                txbJgTimeout.Text = LoadData
            Case 1
                txbJgDelay.Text = LoadData
            Case 2
                txbDTTimeout.Text = LoadData

            Case Else
                MsgBox("JIG_잘못된 데이터가 존재합니다.", vbExclamation)
        End Select
    End Sub

    Private Sub LED_LoadTxb(cnt As Int16, LoadData As String)
        Select Case cnt
            Case 0
                WebCamList(True)

                For i = 0 To cbbWebCam.Items.Count - 1
                    cbbWebCam.SelectedIndex = i
                    If LoadData = cbbWebCam.SelectedItem Then
                        WebCamNum = cbbWebCam.SelectedIndex
                        Exit For
                    End If

                    cbbWebCam.SelectedIndex = -1
                Next
            Case 1
                txbCamDelay.Text = LoadData
            Case 2
                txbRedCdn_X1.Text = LoadData
            Case 3
                txbRedCdn_Y1.Text = LoadData
            Case 4
                txbYelCdn_X1.Text = LoadData
            Case 5
                txbYelCdn_Y1.Text = LoadData
            Case 6
                txbRedCdn_X2.Text = LoadData
            Case 7
                txbRedCdn_Y2.Text = LoadData
            Case 8
                txbYelCdn_X2.Text = LoadData
            Case 9
                txbYelCdn_Y2.Text = LoadData
            Case 10
                txbAround.Text = LoadData
            Case 11
                txbInc.Text = LoadData
            Case 12
                If LoadData = ImgSave Then
                    rdbimgSave.Checked = True
                    rdbMatCovert.Checked = False
                ElseIf LoadData = ImgCvt Then
                    rdbimgSave.Checked = False
                    rdbMatCovert.Checked = True
                Else
                    MsgBox("이미지 처리 방식에 관련하여 잘못된 데이터가 저장되었습니다.", vbCritical)
                End If

            Case 13
                nudLEDStart.Value = LoadData
            Case 14
                nudLedRe.Value = LoadData

            Case Else
                MsgBox("LED_잘못된 데이터가 존재합니다.", vbExclamation)
        End Select
    End Sub

    Private Sub RF_LoadTxb(cnt As Int16, LoadData As String)
        Select Case cnt
            Case 0
                If LoadData.ToLower = "auto" Then
                    rdbRFTrAuto.Checked = True
                Else
                    rdbRFtrNormal.Checked = True
                End If
            Case 1
                txbRFtime.Text = LoadData
            Case 2
                If LoadData.ToLower = "volt" Then
                    rdbRFUnitV.Checked = True
                Else
                    rdbRFUnitA.Checked = True
                End If
            Case 3
                nudRFScale.Text = LoadData
            Case 4
                txbRFDelay.Text = LoadData
            Case 5
                nudRFRun.Text = LoadData
            Case 6
                nudRFCh.Value = LoadData
            Case 7
                nudRFTrgLv.Value = LoadData

            Case 8
                txbRFWdtime.Text = LoadData
            Case 9
                txbRFWdDelay.Text = LoadData
            Case 10
                nudRFWdTrgLv.Value = LoadData
            Case 11
                nudRFWdRun.Value = LoadData

            Case Else
                MsgBox("RF_잘못된 데이터가 존재합니다.", vbExclamation)
        End Select
    End Sub

    Private Sub MC_LoadTxb(cnt As Int16, LoadData As String)
        Select Case cnt
            Case 0
                If LoadData.ToLower = "auto" Then
                    rdbMCTrAuto.Checked = True
                Else
                    rdbMCtrNormal.Checked = True
                End If
            Case 1
                txbMCFVtime.Text = LoadData
            Case 2
                If LoadData.ToLower = "volt" Then
                    rdbMCUnitV.Checked = True
                Else
                    rdbMCUnitA.Checked = True
                End If
            Case 3
                nudMCScale.Text = LoadData
            Case 4
                txbMCFVDelay.Text = LoadData
            Case 5
                nudMCFVRun.Text = LoadData
            Case 6
                nudMCCh.Value = LoadData
            Case 7
                nudMCFVTrgLv.Value = LoadData
            Case 8
                txbMCWdtime.Text = LoadData
            Case 9
                txbMCWdDelay.Text = LoadData
            Case 10
                nudMCWdTrgLv.Value = LoadData
            Case 11
                nudMCWdRun.Value = LoadData
            Case Else
                MsgBox("MC_잘못된 데이터가 존재합니다.", vbExclamation)
        End Select
    End Sub

    Private Sub EP_LoadTxb(cnt As Int16, LoadData As String)
        Select Case cnt
            Case 0
                If LoadData.ToLower = "auto" Then
                    rdbEPTrAuto1.Checked = True
                Else
                    rdbEPtrNormal1.Checked = True
                End If
            Case 1
                txbEPFVtime1.Text = LoadData
            Case 2
                If LoadData.ToLower = "volt" Then
                    rdbEPUnitV1.Checked = True
                Else
                    rdbEPUnitA1.Checked = True
                End If
            Case 3
                nudEPScale1.Text = LoadData
            Case 4
                txbEPFVDelay1.Text = LoadData
            Case 5
                nudEPFVRun1.Text = LoadData
            Case 6
                txbEPFreq1.Text = LoadData
            Case 7
                txbEPFreq2.Text = LoadData
            Case 8
                txbEPFreq3.Text = LoadData
            Case 9
                nudEPCh1.Value = LoadData
            Case 10
                nudEPFVTrgLv1.Value = LoadData
            Case Else
                MsgBox("EP_잘못된 데이터가 존재합니다.", vbExclamation)
        End Select
    End Sub

    Private Sub multiEpConfig_LoadTxb(array As String())
        If array.Length < 3 Or array.Length > 3 Then
            rdbEPTrAuto1.Checked = True
            txbEPFVtime1.Text = "0" : rdbEPUnitV1.Checked = True : nudEPScale1.Text = "0" : txbEPFVDelay1.Text = "0" : nudEPFVRun1.Text = "0"
            nudEPCh1.Value = nudEPCh1.Minimum : nudEPFVTrgLv1.Value = nudEPFVTrgLv1.Minimum
            'txbEPFreq1.Text = "0" : txbEPFreq2.Text = "0" : txbEPFreq3.Text = "0"
            rdbEPTrAuto2.Checked = True
            txbEPFVtime2.Text = "0" : rdbEPUnitV2.Checked = True : nudEPScale2.Text = "0" : txbEPFVDelay2.Text = "0" : nudEPFVRun2.Text = "0"
            nudEPCh2.Value = nudEPCh2.Minimum : nudEPFVTrgLv2.Value = nudEPFVTrgLv2.Minimum
            rdbEPTrAuto3.Checked = True
            txbEPFVtime3.Text = "0" : rdbEPUnitV3.Checked = True : nudEPScale3.Text = "0" : txbEPFVDelay3.Text = "0" : nudEPFVRun3.Text = "0"
            nudEPCh3.Value = nudEPCh3.Minimum : nudEPFVTrgLv3.Value = nudEPFVTrgLv3.Minimum
            Exit Sub
        End If

        For i As Int16 = 0 To array.Length - 1
            Dim elememtString As String() = Split(array(i), ",")
            For j As Int16 = 0 To UBound(elememtString)

                Select Case j
                    Case 0
                        If elememtString(j).ToLower = "auto" Then
                            EpTrigerMode(i, 0).Checked = True
                        Else
                            EpTrigerMode(i, 1).Checked = True
                        End If
                    Case 1
                        EpTimeScale(i).Text = elememtString(j)
                    Case 2
                        If elememtString(j).ToLower = "volt" Then
                            EpScaleMode(i, 0).Checked = True
                        Else
                            EpScaleMode(i, 1).Checked = True
                        End If
                    Case 3
                        EpnudEPScale1(i).Text = elememtString(j)
                    Case 4
                        EpDelay(i).Text = elememtString(j)
                    Case 5
                        EpRunTime(i).Text = elememtString(j)
                    Case 6
                        txbEPFreq1.Text = elememtString(j)
                    Case 7
                        txbEPFreq2.Text = elememtString(j)
                    Case 8
                        txbEPFreq3.Text = elememtString(j)
                    Case 9
                        EpChennal(i).Value = elememtString(j)
                    Case 10
                        EpTriggerLv(i).Value = elememtString(j)
                    Case Else
                        MsgBox("EP_잘못된 데이터가 존재합니다.", vbExclamation)
                End Select

            Next
        Next
    End Sub

    Private Sub Standard_LoadTxb(cnt As Int16, LoadData As String)
        Select Case cnt
            Case 0
                txbFirmVer.Text = LoadData
            Case 1
                txbBatMin.Text = LoadData
            Case 2
                txbBatMax.Text = LoadData
            Case 3
                txbTpDevMin.Text = LoadData
            Case 4
                txbTpDevMax.Text = LoadData
            Case 5
                txbTpCartMin.Text = LoadData
            Case 6
                txbTpCartMax.Text = LoadData
            Case 7
                txbHFOutMin.Text = LoadData
            Case 8
                txbHFOutMax.Text = LoadData
            Case 9
                txbHFMin.Text = LoadData
            Case 10
                txbRFVRmin1.Text = LoadData
            Case 11
                txbRFVRmax1.Text = LoadData
            Case 12
                txbRFVRmin2.Text = LoadData
            Case 13
                txbRFVRmax2.Text = LoadData
            Case 14
                txbRFVRmin3.Text = LoadData
            Case 15
                txbRFVRmax3.Text = LoadData
            Case 16
                txbMCVPmin.Text = LoadData
            Case 17
                txbMCVPmax.Text = LoadData
            Case 18
                txbMCDYmin.Text = LoadData
            Case 19
                txbMCDYmax.Text = LoadData
            Case 20
                txbMCFrmin.Text = LoadData
            Case 21
                txbMCFrmax.Text = LoadData
            Case 22
                txbEPVPmin.Text = LoadData
            Case 23
                txbEPVPmax.Text = LoadData
            Case 24
                txbEPDYmin1.Text = LoadData
            Case 25
                txbEPDYmax1.Text = LoadData
            Case 26
                txbEPDYmin2.Text = LoadData
            Case 27
                txbEPDYmax2.Text = LoadData
            Case 28
                txbEPDYmin3.Text = LoadData
            Case 29
                txbEPDYmax3.Text = LoadData
            Case 30 '' LED
                txbHFLDMMax3.Text = LoadData
            Case 31
                txbHFLDMMin3.Text = LoadData
            Case 32
                txbHFLDMMax2.Text = LoadData
            Case 33
                txbHFLDMMin2.Text = LoadData
            Case 34
                txbHFLDMMax1.Text = LoadData
            Case 35
                txbHFLDMMin1.Text = LoadData

            Case 36
                txbLDMVRmax1.Text = LoadData
            Case 37
                txbLDMVRmin1.Text = LoadData
            Case 38
                txbLDMVRmax2.Text = LoadData
            Case 39
                txbLDMVRmin2.Text = LoadData
            Case 40
                txbLDMVRmax3.Text = LoadData
            Case 41 ''LED 
                txbLDMVRmin3.Text = LoadData

            Case 42
                txbFirmVer_AL.Text = LoadData
            Case 43
                txbTpDevMin_AL.Text = LoadData
            Case 44
                txbTpDevMax_AL.Text = LoadData
            Case 45
                txbTpCartMin_AL.Text = LoadData
            Case 46
                txbTpCartMax_AL.Text = LoadData
            Case 47
                txbBatMin_AL.Text = LoadData
            Case 48
                txbBatMax_AL.Text = LoadData
            Case 49
                txbRFVRmin1_AL.Text = LoadData
            Case 50
                txbRFVRmax1_AL.Text = LoadData
            Case 51
                txbRFVRmin2_AL.Text = LoadData
            Case 52
                txbRFVRmax2_AL.Text = LoadData
            Case 53
                txbRFVRmin3_AL.Text = LoadData
            Case 54
                txbRFVRmax3_AL.Text = LoadData
            Case 55
                txbEPVPmin_AL.Text = LoadData
            Case 56
                txbEPVPmax_AL.Text = LoadData
            Case 57
                txbEPDYmin1_AL.Text = LoadData
            Case 58
                txbEPDYmax1_AL.Text = LoadData
            Case 59
                txbEPDYmin2_AL.Text = LoadData
            Case 60
                txbEPDYmax2_AL.Text = LoadData
            Case 61
                txbEPDYmin3_AL.Text = LoadData
            Case 62
                txbEPDYmax3_AL.Text = LoadData
            Case 63
                txbBDVRmin1_AL.Text = LoadData
            Case 64
                txbBDVRmax1_AL.Text = LoadData
            Case 65
                txbBDVRmin2_AL.Text = LoadData
            Case 66
                txbBDVRmax2_AL.Text = LoadData
            Case 67
                txbBDVRmin3_AL.Text = LoadData
            Case 68
                txbBDVRmax3_AL.Text = LoadData
            Case 69
                txbDSfw_st.Text = LoadData
            Case 70
                txbDSbat_stMin.Text = LoadData
            Case 71
                txbDSbat_stMax.Text = LoadData
            Case 72
                txbDSTmpDe_stMin.Text = LoadData
            Case 73
                txbDSTmpDe_stMax.Text = LoadData
            Case 74
                txbDSTmpCa_stMin.Text = LoadData
            Case 75
                txbDSTmpCa_stMax.Text = LoadData
            Case 76
                txbDShfOut_stMin.Text = LoadData
            Case 77
                txbDShfOut_stMax.Text = LoadData
            Case 78
                txbDShfDif_st.Text = LoadData

            Case 79
                txbDSSub_Min.Text = LoadData
            Case 80
                txbDSSub_Max.Text = LoadData

            Case Else
                MsgBox("기준 설정_잘못된 데이터가 존재합니다.", vbExclamation)
        End Select
    End Sub

    Private Sub Equip_LoadTxb(cnt As Int16, LoadData As String)
        Const MountEquip As Int16 = 1
        Dim CbList(MountEquip) As ComboBox

        CbList(MountEquip - 1) = cbbScopeID
        CbList(MountEquip) = cbbSpecID

        If LoadData <> "" And CbList(cnt).Items.Count <> 0 Then
            For i = 0 To CbList(cnt).Items.Count - 1
                CbList(cnt).SelectedIndex = i
                If LoadData = CbList(cnt).SelectedItem Then
                    Exit For
                End If

                CbList(cnt).SelectedIndex = -1
            Next
        End If

    End Sub

    Private Sub btnScRg_Click(sender As Object, e As EventArgs) Handles btnScRg.Click
        If txbRgScName.Text.Replace(" ", "") = "" Then
            MsgBox("장비명을 입력하지 않았습니다.", vbExclamation)
        Else
            If txbRgScID.Text.Replace(" ", "") = "" Then
                MsgBox("장비 ID를 입력하지 않았습니다.", vbExclamation)
            Else
                If cbbRgScType.SelectedIndex = -1 Then
                    MsgBox("장비 종류를 입력하지 않았습니다.", vbExclamation)
                Else
                    dgvID.Rows.Add(txbRgScName.Text, txbRgScID.Text, cbbRgScType.SelectedItem)
                    MsgBox("장비 등록 완료", vbInformation)

                    EquipCBBLoad()
                    txbRgScName.Text = ""
                    txbRgScID.Text = ""
                    cbbRgScType.SelectedIndex = -1
                    cbbRgScType.Text = "선택!"

                End If
            End If
        End If
    End Sub

    Private Sub cbbScopeID_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbbScopeID.SelectedIndexChanged
        If cbbScopeID.SelectedIndex <> -1 Then
            txbScopeID.Text = ScopeList(cbbScopeID.SelectedIndex)
        End If
    End Sub

    Private Sub cbbSpecID_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbbSpecID.SelectedIndexChanged
        If cbbSpecID.SelectedIndex <> -1 Then
            txbSpecID.Text = SpecList(cbbSpecID.SelectedIndex)
        End If
    End Sub

    Private Sub btnScDel_Click(sender As Object, e As EventArgs) Handles btnScDel.Click
        For i = 0 To dgvID.Rows.Count - 2
            If dgvID.Rows(i).Selected = True Then
                If MsgBox("해당 장비 데이터를 삭제하시겠습니까?", vbExclamation + vbYesNo) = MsgBoxResult.Yes Then
                    dgvID.Rows.Remove(dgvID.Rows(i))
                    MsgBox("데이터 삭제를 완료하였습니다.", vbInformation)
                End If
            End If
        Next
    End Sub

    Private Sub EquipCBBLoad()
        cbbScopeID.Items.Clear()
        cbbSpecID.Items.Clear()

        If dgvID.Rows.Count > 1 Then
            For i = 0 To dgvID.Rows.Count - 2
                If dgvID.Rows(i).Cells(2).Value.ToString.ToLower = "scope" Then
                    cbbScopeID.Items.Add(dgvID.Rows(i).Cells(0).Value)
                    ReDim Preserve ScopeList(cbbScopeID.Items.Count - 1)
                    ScopeList(cbbScopeID.Items.Count - 1) = dgvID.Rows(i).Cells(1).Value
                Else
                    cbbSpecID.Items.Add(dgvID.Rows(i).Cells(0).Value)
                    ReDim Preserve SpecList(cbbSpecID.Items.Count - 1)
                    SpecList(cbbSpecID.Items.Count - 1) = dgvID.Rows(i).Cells(1).Value
                End If
            Next
        End If
    End Sub

    Private Sub EquipList_LoadTxb(LoadData As String)
        Dim DgvList() As String = New String(0) {""}
        For i = 0 To UBound(Split(LoadData, "/"))
            ReDim Preserve DgvList(i)
            If InStr(LoadData, "/") > 0 Then
                DgvList(i) = Mid(LoadData, 1, InStr(LoadData, "/") - 1)
                LoadData = Mid(LoadData, InStr(LoadData, "/") + 1, LoadData.Length)
            Else
                DgvList(i) = Mid(LoadData, 1, LoadData.Length)
            End If
        Next

        dgvID.Rows.Add(DgvList)

        EquipCBBLoad()
    End Sub

    Private Sub rdbSort_CheckedChanged(sender As Object, e As EventArgs) Handles rdbSort.CheckedChanged
        gbChkPoint.Visible = True
        gbChkPoint.Enabled = True
        gbScopeOption.Visible = False
        gbScopeOption.Enabled = False
        gbETC.Visible = False
        gbETC.Enabled = False
        gbStandard.Visible = True
        rdbStdMax.Checked = True

    End Sub

    Private Sub rdbRF_CheckedChanged(sender As Object, e As EventArgs) Handles rdbRF.CheckedChanged
        gbChkPoint.Visible = False
        gbChkPoint.Enabled = False
        gbScopeOption.Visible = True
        gbScopeOption.Enabled = True
        gbETC.Visible = True
        gbETC.Enabled = True

        gbMCoption.Visible = False
        gbMCoption.Enabled = False
        gbRFOption.Visible = True
        gbRFOption.Enabled = True
        gbStandard.Visible = False
    End Sub

    Private Sub rdbMC_CheckedChanged(sender As Object, e As EventArgs) Handles rdbMC.CheckedChanged
        gbChkPoint.Visible = False
        gbChkPoint.Enabled = False
        gbScopeOption.Visible = True
        gbScopeOption.Enabled = True
        gbETC.Visible = True
        gbETC.Enabled = True

        gbMCoption.Visible = True
        gbMCoption.Enabled = True
        gbRFOption.Visible = False
        gbRFOption.Enabled = False
        gbStandard.Visible = False
    End Sub

    Private Sub rdbLed_CheckedChanged(sender As Object, e As EventArgs) Handles rdbLed.CheckedChanged
        gbLedOp.Visible = True
        gbLedOp.Enabled = True

        gbSpecOption.Visible = False
        gbSpecOption.Enabled = False

    End Sub

    Private Sub rdbTestMode_CheckedChanged(sender As Object, e As EventArgs) Handles rdbTestMode.CheckedChanged
        gbLedOp.Visible = False
        gbLedOp.Enabled = False

        gbSpecOption.Visible = True
        gbSpecOption.Enabled = True

    End Sub

    Private Function loadLocalFile() As Boolean
        Try
            Dim filePath, fileName, strData As String
            Dim saveYear As String = DateAndTime.Year(Now)
            Dim saveMonth As String = Format(Now, "MM")
            Dim saveDay As String = Format(Now, "dd")
            Dim saveDate As String = saveYear & "-" & saveMonth & "-" & saveDay

            filePath = System.AppDomain.CurrentDomain.BaseDirectory & "\TestCount"
            If Dir(filePath, vbDirectory) = "" Then
                MkDir(filePath)
            End If
            fileName = filePath & "\" & saveYear & "_" & saveMonth & ".csv"

            If File.Exists(fileName) Then
                strData = File.ReadAllText(fileName)

                If UBound(Split(strData, saveDate)) > 0 Then
                    todayCount = Val(Mid(strData, InStr(strData, saveDate), InStr(strData, vbCrLf) - 1))
                End If

            End If

            Return True
        Catch ex As Exception
            MsgBox("오류 발생 :: " & ex.Message, vbCritical)
            Return False
        End Try

    End Function

    Private Function saveLocalFile() As Boolean

        Try
            Dim filePath, fileName, saveData, strData As String

            Dim saveYear As String = DateAndTime.Year(Now)
            Dim saveMonth As String = Format(Now, "MM")
            Dim saveDay As String = Format(Now, "dd")
            Dim startForm As String = "TestDate,Count"

            filePath = System.AppDomain.CurrentDomain.BaseDirectory & "\TestCount"
            If Dir(filePath, vbDirectory) = "" Then
                MkDir(filePath)
            End If
            fileName = filePath & "\" & saveYear & "_" & saveMonth & ".csv"

            saveData = NowDate & "," & todayCount

            If File.Exists(fileName) = True Then
                strData = File.ReadAllText(fileName, Encoding.UTF8)

                If strData = vbCrLf Or strData = Nothing Or strData = "" Then
                    strData = startForm & vbCrLf & saveData & vbCrLf

                Else
                    If UBound(Split(strData, NowDate)) > 0 Then
                        strData = Mid(strData, 1, InStr(strData, NowDate) - 1)
                        strData = strData & saveData & vbCrLf
                    Else
                        strData = strData & saveData & vbCrLf
                    End If

                End If
            Else
                strData = startForm & vbCrLf & saveData & vbCrLf
            End If

            File.WriteAllText(fileName, strData, Encoding.UTF8)

            Return False
        Catch ex As Exception
            MsgBox("오류 발생 :: " & ex.Message, vbCritical)
            TestError = False
            Return True
        End Try

    End Function

    Private Function Save_Csv(SaveData As String) As Boolean
        On Error GoTo WR_File_Error
        TestStep = TestList.CSV

        Dim ItemList As String
        Dim FileName As String
        Dim objWriter As StreamWriter

        Dim syaer As String = DateAndTime.Year(Now)
        Dim smonth As String = DateAndTime.Month(Now)
        Dim sday As String = DateAndTime.Day(Now)

        Dim FilePath As String = System.AppDomain.CurrentDomain.BaseDirectory & "\LogData"

        If Dir(FilePath, vbDirectory) = "" Then
            MkDir(FilePath)
        End If

        Select Case formType
            Case formTypeList.full
                ItemList = "TestDate,TestTime,PV_SN,FW_VER,Battery_Level,Div_Temp,Cart_Temp,HIFU_6850,HIFU_Diff1,HIFU_7000,HIFU_Diff2,HIFU_7150,RF_1VRMS,RF_1Freq,RF_2VRMS,RF_2Freq,RF_3VRMS,RF_3Freq,MC_PlusWave,MC_PlusVpp,MC_MinusWave,MC_MinusVpp,EP_1Vpp,EP_1Freq,EP_1PWidth,EP_1NWidth,EP_2Vpp,EP_2Freq,EP_2PWidth,EP_2NWidth,EP_3Vpp,EP_3Freq,EP_3PWidth,EP_3NWidth,Test_Result"
                FileName = FilePath & "\" & DateAndTime.Year(Now) & "_" & DateAndTime.Month(Now) & "_" & DateAndTime.Day(Now) & "_ALL.csv"
            Case formTypeList.prdHF, formType = formTypeList.prdLowHF
                ItemList = "PV_SN,TestDate,TestTime,FW_Ver,BatteryLv,DivTemp,CtTemp,HF_R1Value,HF_R2Value,HF_R3Value,Test_Result"
                FileName = FilePath & "\" & DateAndTime.Year(Now) & "_" & DateAndTime.Month(Now) & "_" & DateAndTime.Day(Now) & "_HF.csv"
            Case formTypeList.prdRFMCEP, formType = formTypeList.prdHFLDMEP
                ItemList = "PV_SN,TestDate,TestTime,FW_Ver,RF_R1Vrms,RF_R1Freq,RF_R2Vrms,RF_R2Freq,RF_R3Vrms,RF_R3Freq,MC_R1Wave,MC_R1Vpp,MC_R1Freq,MC_R2Wave,MC_R2Vpp,MC_R2Freq,EP_R1Vpp,EP_R1Freq,EP_R1PWidth,EP_R1NWidth,EP_R2Vpp,EP_R2Freq,EP_R2PWidth,EP_R2NWidth,EP_R3Vpp,EP_R3Freq,EP_R3PWidth,EP_R3NWidth,Test_Result"
                FileName = FilePath & "\" & DateAndTime.Year(Now) & "_" & DateAndTime.Month(Now) & "_" & DateAndTime.Day(Now) & "_RF.csv"
            Case formTypeList.iqcRFEP
                ItemList = "TestDate,TestTime,FW_Ver,Div_Temp,RF_R1Vrms,RF_R1Freq,RF_R2Vrms,RF_R2Freq,RF_R3Vrms,RF_R3Freq,EP_R1Vpp,EP_R1Freq,EP_R1PWidth,EP_R1NWidth,EP_R2Vpp,EP_R2Freq,EP_R2PWidth,EP_R2NWidth,EP_R3Vpp,EP_R3Freq,EP_R3PWidth,EP_R3NWidth,Test_Result"
                FileName = FilePath & "\" & DateAndTime.Year(Now) & "_" & DateAndTime.Month(Now) & "_" & DateAndTime.Day(Now) & "_ALTOIQC.csv"
            Case formTypeList.prdRFEP
                ItemList = "PV_SN,TestDate,TestTime,FW_Ver,Div_Temp,Cart_Temp,Battery_Level,RF_R1Vrms,RF_R1Freq,RF_R2Vrms,RF_R2Freq,RF_R3Vrms,RF_R3Freq,EP_R1Vpp,EP_R1Freq,EP_R1PWidth,EP_R1NWidth,EP_R2Vpp,EP_R2Freq,EP_R2PWidth,EP_R2NWidth,EP_R3Vpp,EP_R3Freq,EP_R3PWidth,EP_R3NWidth,Test_Result"
                FileName = FilePath & "\" & DateAndTime.Year(Now) & "_" & DateAndTime.Month(Now) & "_" & DateAndTime.Day(Now) & "_ALTOPD.csv"
            Case formTypeList.iqcHFRFEP, formTypeList.iqcHFEP, formTypeList.iqcLDMEP
                ItemList = "TestDate,TestTime,FW_Ver,Div_Temp,HF_R1Value,HF_R2Value,HF_R3Value,RF_R1Vrms,RF_R1Freq,RF_R2Vrms,RF_R2Freq,RF_R3Vrms,RF_R3Freq,EP_R1Vpp,EP_R1Freq,EP_R1PWidth,EP_R1NWidth,EP_R2Vpp,EP_R2Freq,EP_R2PWidth,EP_R2NWidth,EP_R3Vpp,EP_R3Freq,EP_R3PWidth,EP_R3NWidth,Test_Result"
                FileName = FilePath & "\" & DateAndTime.Year(Now) & "_" & DateAndTime.Month(Now) & "_" & DateAndTime.Day(Now) & "_IQC.csv"
            Case formTypeList.iqcHF
                ItemList = "TestDate,TestTime,FW_Ver,Div_Temp,HF_R1Value,HF_R2Value,HF_R3Value,Test_Result"
                FileName = FilePath & "\" & DateAndTime.Year(Now) & "_" & DateAndTime.Month(Now) & "_" & DateAndTime.Day(Now) & "_HFIQC.csv"
            Case formTypeList.company
                ItemList = "TestDate,TestTime,FW_Ver,Div_Temp,HF_R1Value,HF_R2Value,HF_R3Value,RF_R1Vrms,RF_R1Freq,RF_R2Vrms,RF_R2Freq,RF_R3Vrms,RF_R3Freq,EP_R1Vpp,EP_R1Freq,EP_R1PWidth,EP_R1NWidth,EP_R2Vpp,EP_R2Freq,EP_R2PWidth,EP_R2NWidth,EP_R3Vpp,EP_R3Freq,EP_R3PWidth,EP_R3NWidth,Test_Result"
                FileName = FilePath & "\" & DateAndTime.Year(Now) & "_" & DateAndTime.Month(Now) & "_" & DateAndTime.Day(Now) & "_COMPANY.csv"
            Case formTypeList.iqcDsHF, formTypeList.prdDsHF
                ItemList = "TestDate,TestTime,FW_Ver,BatteryLv,DivTemp,CtTemp,HF_R1Value,HF_R2Value,HF_R3Value,Test_Result"
                FileName = FilePath & "\" & DateAndTime.Year(Now) & "_" & DateAndTime.Month(Now) & "_" & DateAndTime.Day(Now) & "_DS_HF.csv"
            Case formType = formTypeList.iqcLDM
                ItemList = "TestDate,TestTime,FW_Ver,Div_Temp,LDM_R1Value,LDM_R2Value,LDM_R3Value,Test_Result"
                FileName = FilePath & "\" & DateAndTime.Year(Now) & "_" & DateAndTime.Month(Now) & "_" & DateAndTime.Day(Now) & "_LDMIQC.csv"
            Case formType = formTypeList.prdLDM
                ItemList = "PV_SN,TestDate,TestTime,FW_Ver,Div_Temp,LDM_R1Value,LDM_R2Value,LDM_R3Value,Test_Result"
                FileName = FilePath & "\" & DateAndTime.Year(Now) & "_" & DateAndTime.Month(Now) & "_" & DateAndTime.Day(Now) & "_LDM.csv"
            Case formType = formTypeList.prdVRLDM
                ItemList = "PV_SN,TestDate,TestTime,FW_Ver,Div_Temp,Cart_Temp,Battery_Level,RF_R1Vrms,RF_R1Freq,RF_R2Vrms,RF_R2Freq,RF_R3Vrms,RF_R3Freq,Test_Result"
                FileName = FilePath & "\" & DateAndTime.Year(Now) & "_" & DateAndTime.Month(Now) & "_" & DateAndTime.Day(Now) & "_LDM(RF).csv"
            Case formType = formTypeList.iqcEP
                ItemList = "TestDate,TestTime,FW_Ver,Div_Temp,EP_R1Vpp,EP_R1Freq,EP_R1PWidth,EP_R1NWidth,EP_R2Vpp,EP_R2Freq,EP_R2PWidth,EP_R2NWidth,EP_R3Vpp,EP_R3Freq,EP_R3PWidth,EP_R3NWidth,Test_Result"
                FileName = FilePath & "\" & DateAndTime.Year(Now) & "_" & DateAndTime.Month(Now) & "_" & DateAndTime.Day(Now) & "_EPIQC(NEMO).csv"
            Case formTypeList.iqcRFEPMC
                ItemList = "TestDate,TestTime,FW_Ver,Div_Temp,RF_R1Vrms,RF_R1Freq,RF_R2Vrms,RF_R2Freq,RF_R3Vrms,RF_R3Freq,MC_R1Wave,MC_R1Vpp,MC_R1Freq,MC_R2Wave,MC_R2Vpp,MC_R2Freq,EP_R1Vpp,EP_R1Freq,EP_R1PWidth,EP_R1NWidth,EP_R2Vpp,EP_R2Freq,EP_R2PWidth,EP_R2NWidth,EP_R3Vpp,EP_R3Freq,EP_R3PWidth,EP_R3NWidth,Test_Result"
                FileName = FilePath & "\" & DateAndTime.Year(Now) & "_" & DateAndTime.Month(Now) & "_" & DateAndTime.Day(Now) & "_MAREUMMOIQC.csv"
            Case formTypeList.prdEP, formTypeList.prdLDMEP
                ItemList = "PV_SN,TestDate,TestTime,FW_Ver,EP_R1Vpp,EP_R1Freq,EP_R1PWidth,EP_R1NWidth,EP_R2Vpp,EP_R2Freq,EP_R2PWidth,EP_R2NWidth,EP_R3Vpp,EP_R3Freq,EP_R3PWidth,EP_R3NWidth,Test_Result"
                FileName = FilePath & "\" & DateAndTime.Year(Now) & "_" & DateAndTime.Month(Now) & "_" & DateAndTime.Day(Now) & "_lowPriceEPPD.csv"
            Case formTypeList.prdRFMC
                ItemList = "PV_SN,TestDate,TestTime,FW_Ver,RF_R1Vrms,RF_R1Freq,RF_R2Vrms,RF_R2Freq,RF_R3Vrms,RF_R3Freq,Test_Result"
                FileName = FilePath & "\" & DateAndTime.Year(Now) & "_" & DateAndTime.Month(Now) & "_" & DateAndTime.Day(Now) & "_lowPriceRFMCPD.csv"
            Case Else
                FileName = "Null"
                ItemList = "Null"
        End Select

        If File.Exists(FileName) = True Then
            objWriter = New StreamWriter(FileName, True)
            objWriter.WriteLine(SaveData)
        Else
            objWriter = New StreamWriter(FileName, True)
            objWriter.WriteLine(ItemList)
            objWriter.WriteLine(SaveData)
        End If

        objWriter.Close()
        TestRunningState(testRunningList.Success, Color.Green)
        Return False

WR_File_Error:
        MsgBox("Logdata save fail!" & Err.Description)
        TestRunningState(testRunningList.Fail, Color.Red)
        Return True

    End Function

    Private Sub WebCamList(CamType As Boolean)
        Dim CamDevice As FilterInfoCollection = New FilterInfoCollection(FilterCategory.VideoInputDevice)
        Dim CamList As ComboBox

        If CamType = True Then
            CamList = cbbWebCam
        Else
            CamList = cbbOLEDCam
        End If

        CamList.Items.Clear()

        If CamDevice.Count <> 0 Then
            For i = 0 To CamDevice.Count - 1
                CamList.Items.Add(CamDevice(i).Name)
            Next
        End If

    End Sub

    Private Sub btnWebCam_Click(sender As Object, e As EventArgs) Handles btnWebCam.Click
        If btnWebCam.Text = "스캔" Then
            WebCamList(True)
            btnWebCam.Text = "연결"
        Else
            If cbbWebCam.SelectedIndex = -1 Then
                btnWebCam.Text = "스캔"
                MsgBox("웹캠을 선택하여 주십시오.", vbExclamation)
                Exit Sub
            End If

            If cbbWebCam.SelectedItem = cbbOLEDCam.SelectedItem Then
                MsgBox("OLED 측정 카메라와 같습니다. 다른 카메라를 선택하여 주십시오.", vbCritical)
                Exit Sub
            End If

            WebCamNum = cbbWebCam.SelectedIndex

            btnWebCam.Text = "스캔"
            MsgBox("연결 완료", vbInformation)

        End If
    End Sub

    Private Sub btnOLEDCam_Click(sender As Object, e As EventArgs) Handles btnOLEDCam.Click
        If btnOLEDCam.Text = "스캔" Then
            WebCamList(False)
            btnOLEDCam.Text = "연결"
        Else
            If cbbOLEDCam.SelectedIndex = -1 Then
                btnOLEDCam.Text = "스캔"
                MsgBox("웹캠을 선택하여 주십시오.", vbExclamation)
                Exit Sub
            End If

            If cbbWebCam.SelectedItem = cbbOLEDCam.SelectedItem Then
                MsgBox("LED 측정 카메라와 같습니다. 다른 카메라를 선택하여 주십시오.", vbCritical)
                Exit Sub
            End If

            OLEDCamNum = cbbOLEDCam.SelectedIndex

            btnOLEDCam.Text = "스캔"
            MsgBox("연결 완료", vbInformation)

        End If
    End Sub

    Private Sub MainSetting()
        Me.Text = Program_Name & Program_Version
        Me.Size = New Drawing.Size(1920, 1080)
        Me.WindowState = FormWindowState.Maximized
    End Sub

    Private Sub TopPositonSet()
        pnMain.Location = New Drawing.Point(0, 0)
        pnMain.Size = New Drawing.Size(1920, 1080)

        gpbConfig.Location = New Drawing.Point(5, 5)
        gpbConfig.Size = New Drawing.Size(285, 85)

        gbOldMode.Location = New Drawing.Point(295, 5)
        gbOldMode.Size = New Drawing.Size(1090, 85)

        btnReStart.Location = New Drawing.Point(1395, 5)
        btnReStart.Size = New Drawing.Size(170, 85)


        btnSetup.Location = New Drawing.Point(1570, 5)
        btnSetup.Size = New Drawing.Size(170, 85)

        btnEnd.Location = New Drawing.Point(1745, 5)
        btnEnd.Size = New Drawing.Size(170, 85)
    End Sub

    Private Sub BarcPositionSet()

        txbBarcode.Location = New Drawing.Point(277, 25)
        txbBarcode.Size = New Drawing.Size(810, 102)

        lbBarcode.Location = New Drawing.Point(18, 28)

        pnTDSN.Location = New Drawing.Point(1110, 15)
        pnDate.Location = New Drawing.Point(1110, 55)
        pnFreq.Location = New Drawing.Point(1110, 95)

        pnGrade.Location = New Drawing.Point(1370, 15)
        pnVer.Location = New Drawing.Point(1370, 55)
        pnVolt.Location = New Drawing.Point(1370, 95)

        pnDevTmp.Location = New Drawing.Point(1630, 15)
        pnCartTmp.Location = New Drawing.Point(1630, 55)
    End Sub

    Private Sub changeMode()
        Dim ErrorSwitch As Boolean = False

        btnEnd.Enabled = False

        Select Case formType
            Case formTypeList.full, formTypeList.iqcHFRFEP, formTypeList.iqcHFEP, formTypeList.iqcLDMEP

                EquipSetting()

            Case formTypeList.prdHF, formTypeList.iqcDsHF, formTypeList.prdDsHF, formTypeList.iqcHF, formTypeList.prdLowHF, formTypeList.iqcLDM, formTypeList.prdLDM
                If SpecSet() Then
                    txbWindow.AppendText("Spectrum Setting Fail!!" & vbCrLf)
                    ErrorSwitch = True
                Else
                    txbWindow.AppendText("Spectrum Setting Success!!" & vbCrLf)
                End If

                If ErrorSwitch = False Then
                    StartSwitch = True
                End If

            Case formTypeList.prdRFMCEP, formTypeList.iqcRFEP, formTypeList.prdRFEP, formTypeList.company, formTypeList.iqcEP, formTypeList.iqcRFEPMC, formTypeList.prdHFLDMEP, formTypeList.prdEP, formTypeList.prdRFMC, formTypeList.prdVRLDM, formTypeList.prdLDMEP
                If EquipSet() Then
                    txbWindow.AppendText("Scope Setting Fail!!" & vbCrLf)
                    ErrorSwitch = True
                Else
                    txbWindow.AppendText("Scope Setting Success!!" & vbCrLf)
                End If

                If ErrorSwitch = False Then
                    StartSwitch = True
                End If

            Case Else
                EquipSetting()
        End Select

        btnEnd.Enabled = True
        StartClear()
        txbBarcode.ReadOnly = False
        txbBarcode.Focus()
    End Sub

    Private Sub txbRFresult_gotFocus(sender As Object, e As EventArgs) Handles txbRFresult.GotFocus, txbRFtest1.GotFocus, txbRFtest2.GotFocus, txbRFtest3.GotFocus, txbMCresult.GotFocus, txbEPresult.GotFocus, txbEPtest1.GotFocus, txbEPtest2.GotFocus, txbEPtest3.GotFocus, txbBat.GotFocus, txbTemp.GotFocus, txbHFresult.GotFocus, txbHFtest1.GotFocus, txbHFtest2.GotFocus, txbHFtest3.GotFocus, txbDBreg.GotFocus, txbTDreg.GotFocus, txbCmdWindow.GotFocus, txbDayCount.GotFocus, txbOkCount.GotFocus, txbNgCount.GotFocus
        txbBarcode.Focus()
    End Sub

    Private Sub chkAdmin_CheckedChanged(sender As Object, e As EventArgs) Handles chkAdmin.CheckedChanged
        If chkAdmin.Checked = True Then
            Button1.Visible = True
        Else
            Button1.Visible = False
        End If
    End Sub

    Private Sub StatePosition()
        Dim StepPanel(TestCount - 1) As Panel

        gbStep.Location = New Drawing.Point(5, 240)
        pnStep1.Location = New Drawing.Point(13, 20)
        pnStep2.Location = New Drawing.Point(13, 165)
        pnStep3.Location = New Drawing.Point(13, 310)
        pnStep4.Location = New Drawing.Point(13, 455)
        pnStep5.Location = New Drawing.Point(13, 600)
        pnStep8.Location = New Drawing.Point(548, 20)
        pnStep9.Location = New Drawing.Point(548, 165)
        pnStep10.Location = New Drawing.Point(548, 310)
        pnStep6.Location = New Drawing.Point(548, 455)
        pnStep6.Enabled = False
        pnStep7.Location = New Drawing.Point(548, 600)
        pnStep7.Enabled = False
    End Sub

    Private Sub SituationPosition()
        txbCmdWindow.Location = New Drawing.Point(1100, 245)
        txbCmdWindow.Size = New Drawing.Size(810, 440)

        btnRun.Location = New Drawing.Point(1100, 850)
        btnRun.Size = New Drawing.Size(810, 135)
    End Sub

    Private Sub comboBoxModel_SelectedIndexChanged(sender As Object, e As EventArgs) Handles comboBoxModel.SelectedIndexChanged
        If comboBoxModel.SelectedIndex <> -1 Then
            ModelCode = comboBoxModel.SelectedItem.Value.ToString
            ModelName = comboBoxModel.SelectedItem.Key.ToString

            TDUseYn = False
            HifuUseYn = False
            RfUseYn = False
            EpUseYn = False
            McUseYn = False
            LdmUseYn = False
            LowPriceUseYn = False
            checkBoxHfUse.Checked = False
            checkBoxRfUse.Checked = False
            checkBoxEpUse.Checked = False
            checkBoxMcUse.Checked = False

            DBCmd = "SELECT DeviceTypeCode, CartTypeName, TDUseYn, HifuUseYn, RfUseYn, EpUseYn, McUseYn, LdmUseYn, LowPriceUseYn FROM " & ApplyModelInfoDB & " WHERE ModelCode = '" & ModelCode & "' LIMIT 1"
            If DBQueryReader(DBCmd) Then
                DeviceTypeCode = sqlDataQuery(0)
                CartTypeName = sqlDataQuery(1)
                If sqlDataQuery(2) = "Y" Then
                    TDUseYn = True
                End If
                If sqlDataQuery(3) = "Y" Then
                    HifuUseYn = True
                    checkBoxHfUse.Checked = True
                End If
                If sqlDataQuery(4) = "Y" Then
                    RfUseYn = True
                    checkBoxRfUse.Checked = True
                End If
                If sqlDataQuery(5) = "Y" Then
                    EpUseYn = True
                    checkBoxEpUse.Checked = True
                End If
                If sqlDataQuery(6) = "Y" Then
                    McUseYn = True
                    checkBoxMcUse.Checked = True
                End If
                If sqlDataQuery(7) = "Y" Then
                    LdmUseYn = True
                    checkBoxHfUse.Checked = True
                End If
                If sqlDataQuery(8) = "Y" Then
                    LowPriceUseYn = True
                End If

            End If

            comboBoxVerificationStep.DisplayMember = "Key"
            comboBoxVerificationStep.ValueMember = "Value"
            comboBoxVerificationStep.Items.Clear()

            If DeviceTypeCode = "A" Then
                If HifuUseYn = True And RfUseYn = True And EpUseYn = True Then
                    comboBoxVerificationStep.Items.Add(New DictionaryEntry("수입검사(HF/RF/EP)", "iqcHFRFEP"))
                End If
                If HifuUseYn = True And RfUseYn = False And EpUseYn = False Then
                    comboBoxVerificationStep.Items.Add(New DictionaryEntry("수입검사(HF)", "iqcHF"))
                End If
                If HifuUseYn = False And RfUseYn = True And EpUseYn = True And LowPriceUseYn = False Then
                    comboBoxVerificationStep.Items.Add(New DictionaryEntry("수입검사(RF/EP)", "iqcRFEP"))
                End If

                '저가형 모델
                If LowPriceUseYn = True Then
                    If EpUseYn = True And HifuUseYn = False And RfUseYn = False And LdmUseYn = False Then ''네모
                        comboBoxVerificationStep.Items.Add(New DictionaryEntry("수입검사(EP)", "iqcEP"))
                    End If
                    If HifuUseYn = True Then
                        comboBoxVerificationStep.Items.Add(New DictionaryEntry("수입검사(HF/EP)", "iqcHFLDMEP")) ''맥시멈 수입화면/ 원
                        comboBoxVerificationStep.Items.Add(New DictionaryEntry("생산2(HF)", "prdHFLDM")) ''맥시멈 hf 생산 화면 /원
                        comboBoxVerificationStep.Items.Add(New DictionaryEntry("생산1(EP)", "prdHFLDMEP")) ''맥시멈 hf 생산 화면 /원
                    End If

                    If LdmUseYn = True And RfUseYn = False And EpUseYn = False Then ''세모 기본
                        comboBoxVerificationStep.Items.Add(New DictionaryEntry("수입검사(LDM)", "iqcLDM"))
                    End If

                    If LdmUseYn = True And EpUseYn = True Then ''세모 플러스
                        comboBoxVerificationStep.Items.Add(New DictionaryEntry("수입검사(LDM/EP)", "iqcLDMEP"))
                        comboBoxVerificationStep.Items.Add(New DictionaryEntry("생산(EP)", "prdLDMEP"))
                    End If

                    If LdmUseYn = True Then ''ldm                      
                        ''comboBoxVerificationStep.Items.Add(New DictionaryEntry("생산1(LDM/VRMS)", "prdVRLDM"))
                        comboBoxVerificationStep.Items.Add(New DictionaryEntry("생산2(LDM)", "prdLDM"))
                    End If


                    If McUseYn = True And HifuUseYn = False Then
                        comboBoxVerificationStep.Items.Add(New DictionaryEntry("수입검사(RF/EP/MC)", "iqcRFEPMC")) ''맥시멈 생산 화면
                        comboBoxVerificationStep.Items.Add(New DictionaryEntry("생산1(RF/MC)", "prdRFMC")) ''맥시멈 생산 화면
                    End If
                    If EpUseYn = True And (HifuUseYn = False And LdmUseYn = False) Then
                        comboBoxVerificationStep.Items.Add(New DictionaryEntry("생산1-1(EP)", "prdEP")) ''맥시멈 hf 생산 화면
                    End If
                End If


                If HifuUseYn = True And LowPriceUseYn = False Then
                    comboBoxVerificationStep.Items.Add(New DictionaryEntry("생산1(HF측정/정보입력)", "prdHF"))
                End If
                If RfUseYn = True And EpUseYn = True And McUseYn = True And LowPriceUseYn = False Then
                    comboBoxVerificationStep.Items.Add(New DictionaryEntry("생산2(RF/MC/EP)", "prdRFMCEP"))
                End If
                If RfUseYn = True And EpUseYn = True And McUseYn = False Then
                    comboBoxVerificationStep.Items.Add(New DictionaryEntry("생산3(RF/EP)", "prdRFEP"))
                End If
            ElseIf DeviceTypeCode = "D" Then
                If HifuUseYn = True And RfUseYn = False And EpUseYn = False Then
                    comboBoxVerificationStep.Items.Add(New DictionaryEntry("수입검사(DS_HF)", "iqcDsHF"))
                End If

                If HifuUseYn = True Then
                    comboBoxVerificationStep.Items.Add(New DictionaryEntry("생산5(HF)", "prdDsHF"))
                End If
            End If

            If RfUseYn = True And EpUseYn = True And LowPriceUseYn = False Then
                comboBoxVerificationStep.Items.Add(New DictionaryEntry("업체전용(RF/EP)", "company"))
            End If

            ConfigIniLoad()

            If comboBoxVerificationStep.Items.Count > 0 Then
                comboBoxVerificationStep.SelectedIndex = 0
            End If

        End If
    End Sub

    Private Sub comboBoxVerificationStep_SelectedIndexChanged(sender As Object, e As EventArgs) Handles comboBoxVerificationStep.SelectedIndexChanged
        If comboBoxVerificationStep.SelectedIndex <> -1 Then
            VerificationStep = comboBoxVerificationStep.SelectedItem.Value.ToString

            gbIQC.Visible = False
            gbAltoIQC.Visible = False
            gbDSForm.Visible = False
            gbHFTest.Visible = False
            gbRFMCEP.Visible = False
            gbStep.Visible = False
            If lbIQCHF.Text.Equals("3. Cos-Up") Or lbIQCHF.Text.Equals("1. LDM") Then
                lbIQCHF.Text = "1. HIFU"
            End If
            If (lbHF.Text.Equals("3. LDM") And lbTDreg.Text.Equals("4. LDM 정보입력")) Or lbHF.Text.Equals("3. EP") Then
                lbHF.Text = "3. HIFU"
                lbTDreg.Text = "4. TD 정보입력"
            End If

            Select Case VerificationStep
                Case "iqcHFRFEP"
                    gbIQC.Visible = True
                    pnIQCRF.Visible = True
                    pnIQCRun2.Visible = True
                    pnIQCEP.Visible = True
                    pnIQCRun3.Visible = True
                    formType = formTypeList.iqcHFRFEP
                Case "iqcRFEP"
                    gbAltoIQC.Visible = True
                    formType = formTypeList.iqcRFEP
                Case "iqcDsHF"
                    gbDSForm.Visible = True
                    formType = formTypeList.iqcDsHF
                Case "iqcHF"
                    gbIQC.Visible = True
                    pnIQCRF.Visible = False
                    pnIQCRun2.Visible = False
                    pnIQCEP.Visible = False
                    pnIQCRun3.Visible = False
                    formType = formTypeList.iqcHF
                Case "prdHF"
                    gbHFTest.Visible = True
                    formType = formTypeList.prdHF
                Case "prdRFMCEP"
                    gbRFMCEP.Visible = True
                    formType = formTypeList.prdRFMCEP
                Case "prdRFEP"
                    gbAltoIQC.Visible = True
                    formType = formTypeList.prdRFEP
                Case "prdDsHF"
                    gbDSForm.Visible = True
                    formType = formTypeList.prdDsHF
                Case "company"
                    gbAltoIQC.Visible = True
                    formType = formTypeList.company

                    '저가형 모델
                Case "iqcHFLDMEP"
                    gbIQC.Visible = True
                    pnIQCRF.Visible = True
                    pnIQCRun2.Visible = True
                    pnIQCEP.Visible = True
                    pnIQCRun3.Visible = True
                    formType = formTypeList.iqcHFEP
                Case "iqcLDM"
                    gbIQC.Visible = True
                    pnIQCRF.Visible = False
                    pnIQCRun2.Visible = False
                    pnIQCEP.Visible = False
                    pnIQCRun3.Visible = False
                    lbIQCHF.Text = "1. LDM"
                    formType = formTypeList.iqcLDM
                Case "iqcEP"
                    gbIQC.Visible = True
                    pnIQCRF.Visible = False
                    pnIQCRun2.Visible = False
                    pnIQCEP.Visible = False
                    pnIQCRun3.Visible = False
                    lbIQCHF.Text = "3. Cos-Up"
                    formType = formTypeList.iqcEP
                Case "iqcRFEPMC"
                    gbRFMCEP.Visible = True
                    formType = formTypeList.iqcRFEPMC

                Case "iqcLDMEP"
                    gbIQC.Visible = True
                    pnIQCRF.Visible = True
                    pnIQCRun2.Visible = True
                    pnIQCEP.Visible = True
                    pnIQCRun3.Visible = True
                    lbIQCHF.Text = "1. LDM"
                    formType = formTypeList.iqcLDMEP

                Case "prdHFLDM"
                    gbHFTest.Visible = True
                    formType = formTypeList.prdLowHF
                Case "prdLDM"
                    gbHFTest.Visible = True
                    lbHF.Text = "3. LDM"
                    lbTDreg.Text = "4. LDM 정보입력"
                    formType = formTypeList.prdLDM
                Case "prdVRLDM"
                    gbHFTest.Visible = True
                    lbHF.Text = "3. LDM"
                    lbTDreg.Text = "4. LDM 정보입력"
                    formType = formTypeList.prdVRLDM
                Case "prdLDMEP"
                    gbHFTest.Visible = True
                    lbHF.Text = "3. EP"
                    formType = formTypeList.prdLDMEP
                Case "prdHFLDMEP"
                    gbHFTest.Visible = True
                    lbHF.Text = "3. EP"
                    formType = formTypeList.prdHFLDMEP
                Case "prdEP"
                    gbHFTest.Visible = True
                    lbHF.Text = "3. EP"
                    formType = formTypeList.prdEP
                Case "prdRFMC"
                    gbRFMCEP.Visible = True
                    formType = formTypeList.prdRFMC
            End Select


            typeDataSetting()
            modeConfigSave()
            changeMode()

        End If
    End Sub

    Private Sub rdbStdMax_CheckedChanged(sender As Object, e As EventArgs) Handles rdbStdMax.CheckedChanged
        If rdbStdMax.Checked = True Then
            pnStandard_Max.Visible = True
            pnStandard_Al.Visible = False
        End If
    End Sub

    Private Sub rdbStdAl_CheckedChanged(sender As Object, e As EventArgs) Handles rdbStdAl.CheckedChanged
        If rdbStdAl.Checked = True Then
            pnStandard_Max.Visible = False
            pnStandard_Al.Visible = True
        End If
    End Sub

End Class
