Attribute VB_Name = "common"
'
' Copyright(c) Fujitsu Isotec Limited 2007.
'
Public prt_log(16) As String
Public all_log(16) As String
Public log_linecount As Long
Public set_error_event As Long


Public Function PPW_BinaryConversion(ByVal Para As Long) As Long
    Dim func As String
    Dim msg As String
    Dim rtn_l As Long
    func = "BinaryConversion(" + BinaryConversion_msg(Para) + ")"
    OPOS_Tester.Printer1.BinaryConversion = Para
    rtn_l = OPOS_Tester.Printer1.ResultCode
    msg = ResultCode_msg(rtn_l)
    Call PrPrintLog("PPW", func, msg)
    PPW_BinaryConversion = rtn_l
End Function

Public Function PPR_BinaryConversion() As Long
    Dim rtn_l As Long
    Dim msg As String
    rtn_l = OPOS_Tester.Printer1.BinaryConversion
    msg = BinaryConversion_msg(rtn_l)
    Call PrPrintLog("PPR", "BinaryConversion", "[" + msg + "]")
    PPR_BinaryConversion = rtn_l
End Function

Public Function BinaryConversion_msg(ByVal Code As Long) As String
    Dim msg As String
    Select Case Code
        Case OPOS_BC_NONE
            msg = "OPOS_BC_NONE"
        Case OPOS_BC_NIBBLE
            msg = "OPOS_BC_NIBBLE"
        Case OPOS_BC_DECIMAL
            msg = "OPOS_BC_DECIMAL"
        Case Else
            msg = "UNDEFINE " + Str$(Code)
    End Select
    BinaryConversion_msg = msg
End Function

Public Function PM_PrintBarCode(ByVal Station As Long, ByVal data As String, ByVal symbology As Long, ByVal Hight As Long, ByVal width As Long, ByVal alignment As Long, ByVal textposition As Long) As Long
    Dim func As String
    Dim rtn_l As Long
    Dim msg As String
    func = "PrintBarCode(" + PrinterStation_msg(Station) + " " + PrintBarCode_msg(symbology) + ")"
    rtn_l = OPOS_Tester.Printer1.PrintBarCode(Station, data, symbology, Hight, width, alignment, textposition)
    msg = ResultCode_msg(rtn_l)
    Call PrPrintLog("PM ", func, msg)
    PM_PrintBarCode = rtn_l
End Function

Public Function PM_PrintMemoryBitmap(ByVal Station As Long, ByVal filename As String, ByVal Type_i As Long, ByVal width As Long, ByVal alignment As Long) As Long
    Dim func As String
    Dim rtn_l As Long
    Dim msg As String
    func = "PrintMemoryBitmap(" + PrinterStation_msg(Station) + ")"
    rtn_l = OPOS_Tester.Printer1.PrintMemoryBitmap(Station, filename, Type_i, width, alignment)
    msg = ResultCode_msg(rtn_l)
    Call PrPrintLog("PM ", func, msg)
    PM_PrintMemoryBitmap = rtn_l
End Function

Public Function PrinterStation_msg(ByVal Code As Long) As String
    Dim msg As String
    Select Case Code
        Case PTR_S_JOURNAL
            msg = "PTR_S_JOURNAL"
        Case PTR_S_RECEIPT
            msg = "PTR_S_RECEIPT"
        Case PTR_S_SLIP
            msg = "PTR_S_SLIP"
        Case PTR_S_JOURNAL_RECEIPT
            msg = "PTR_S_JOURNAL_RECEIPT"
        Case PTR_S_JOURNAL_SLIP
            msg = "PTR_S_JOURNAL_SLIP"
        Case PTR_S_RECEIPT_SLIP
            msg = "PTR_S_RECEIPT_SLIP"
        Case PTR_TWO_RECEIPT_JOURNAL
            msg = "PTR_TWO_RECEIPT_JOURNAL"
        Case PTR_TWO_SLIP_JOURNAL
            msg = "PTR_TWO_SLIP_JOURNAL"
        Case PTR_TWO_SLIP_RECEIPT
            msg = "PTR_TWO_SLIP_RECEIPT"
        Case Else
            msg = "UNDEFINE " + Str$(Code)
    End Select
    PrinterStation_msg = msg
End Function

Public Function PrintBarCode_msg(ByVal Code As Long) As String
    Dim msg As String
    Select Case Code
        Case PTR_BC_LEFT
            msg = "PTR_BC_LEFT"
        Case PTR_BC_CENTER
            msg = "PTR_BC_CENTER"
        Case PTR_BC_RIGHT
            msg = "PTR_BC_RIGHT"
        Case PTR_BC_TEXT_NONE
            msg = "PTR_BC_TEXT_NONE"
        Case PTR_BC_TEXT_ABOVE
            msg = "PTR_BC_TEXT_ABOVE"
        Case PTR_BC_TEXT_BELOW
            msg = "PTR_BC_TEXT_BELOW"
        Case PTR_BCS_UPCA
            msg = "PTR_BCS_UPCA"
        Case PTR_BCS_UPCE
            msg = "PTR_BCS_UPCE"
        Case PTR_BCS_JAN8
            msg = "PTR_BCS_JAN8"
        Case PTR_BCS_EAN8
            msg = "PTR_BCS_EAN8"
        Case PTR_BCS_JAN13
            msg = "PTR_BCS_JAN13"
        Case PTR_BCS_EAN13
            msg = "PTR_BCS_EAN13"
        Case PTR_BCS_TF
            msg = "PTR_BCS_TF"
        Case PTR_BCS_ITF
            msg = "PTR_BCS_ITF"
        Case PTR_BCS_Codabar
            msg = "PTR_BCS_Codabar"
        Case PTR_BCS_Code39
            msg = "PTR_BCS_Code39"
        Case PTR_BCS_Code93
            msg = "PTR_BCS_Code93"
        Case PTR_BCS_Code128
            msg = "PTR_BCS_Code128"
        Case PTR_BCS_UPCA_S
            msg = "PTR_BCS_UPCA_S"
        Case PTR_BCS_UPCE_S
            msg = "PTR_BCS_UPCE_S"
        Case PTR_BCS_UPCD1
            msg = "PTR_BCS_UPCD1"
        Case PTR_BCS_UPCD2
            msg = "PTR_BCS_UPCD2"
        Case PTR_BCS_UPCD3
            msg = "PTR_BCS_UPCD3"
        Case PTR_BCS_UPCD4
            msg = "PTR_BCS_UPCD4"
        Case PTR_BCS_UPCD5
            msg = "PTR_BCS_UPCD5"
        Case PTR_BCS_EAN8_S
            msg = "PTR_BCS_EAN8_S"
        Case PTR_BCS_EAN13_S
            msg = "PTR_BCS_EAN13_S"
        Case PTR_BCS_EAN128
            msg = "PTR_BCS_EAN128"
        Case PTR_BCS_OCRA
            msg = "PTR_BCS_OCRA"
        Case PTR_BCS_OCRB
            msg = "PTR_BCS_OCRB"
        Case PTR_BCS_PDF417
            msg = "PTR_BCS_PDF417"
        Case PTR_BCS_MAXICODE
            msg = "PTR_BCS_MAXICODE"
            
        Case PTR_BCS_GS1DATABAR
            msg = "PTR_BCS_GS1DATABAR"
        Case PTR_BCS_GS1DATABAR_E
            msg = "PTR_BCS_GS1DATABAR_E"
        Case PTR_BCS_GS1DATABAR_S
            msg = "PTR_BCS_GS1DATABAR_S"
        Case PTR_BCS_GS1DATABAR_E_S
            msg = "PTR_BCS_GS1DATABAR_E_S"
            
        Case PTR_BCS_QRCODE
            msg = "PTR_BCS_QRCODE"
        Case PTR_BCS_UQRCODE
            msg = "PTR_BCS_UQRCODE"
        
        Case PTR_BCS_OTHER
            msg = "PTR_BCS_OTHER"
        Case Else
            msg = "UNDEFINE " + Str$(Code)
    End Select
    PrintBarCode_msg = msg
End Function

Public Function ResultCode_msg(ByVal Code As Long) As String
    Dim msg As String
    Select Case Code
        Case OPOS_SUCCESS
            msg = "OPOS_SUCCESS"
        Case OPOS_E_CLOSED
            msg = "OPOS_E_CLOSED"
        Case OPOS_E_CLAIMED
            msg = "OPOS_E_CLAIMED"
        Case OPOS_E_NOTCLAIMED
            msg = "OPOS_E_NOTCLAIMED"
        Case OPOS_E_NOSERVICE
            msg = "OPOS_E_NOSERVICE"
        Case OPOS_E_DISABLED
            msg = "OPOS_E_DISABLED"
        Case OPOS_E_ILLEGAL
            msg = "OPOS_E_ILLEGAL"
        Case OPOS_E_NOHARDWARE
            msg = "OPOS_E_NOHARDWARE"
        Case OPOS_E_OFFLINE
            msg = "OPOS_E_OFFLINE"
        Case OPOS_E_NOEXIST
            msg = "OPOS_E_NOEXIST"
        Case OPOS_E_EXISTS
            msg = "OPOS_E_EXISTS"
        Case OPOS_E_FAILURE
            msg = "OPOS_E_FAILURE"
        Case OPOS_E_TIMEOUT
            msg = "OPOS_E_TIMEOUT"
        Case OPOS_E_BUSY
            msg = "OPOS_E_BUSY"
        Case OPOS_E_EXTENDED
            msg = "OPOS_E_EXTENDED(" + ResultCodeExtended_msg(OPOS_Tester.Printer1.ResultCodeExtended) + ")"
                
        Case CFV_FIRMWARE_OLDER
            msg = "CFV_FIRMWARE_OLDER"
        Case CFV_FIRMWARE_SAME
            msg = "CFV_FIRMWARE_SAME"
        Case CFV_FIRMWARE_NEWER
            msg = "CFV_FIRMWARE_NEWER"
        Case CFV_FIRMWARE_DIFFERENT
            msg = "CFV_FIRMWARE_DIFFERENT"
        Case CFV_FIRMWARE_UNKNOWN
            msg = "CFV_FIRMWARE_UNKNOWN"
                
        Case Else
            msg = "UNDEFINE " + Str$(Code)
    End Select
    ResultCode_msg = msg
End Function
    
Public Function ResultCodeExtended_msg(ByVal Code As Long) As String
    Dim msg As String
    Select Case Code
        Case OPOS_EPTR_COVER_OPEN
            msg = "OPOS_EPTR_COVER_OPEN"
        Case OPOS_EPTR_JRN_EMPTY
            msg = "OPOS_EPTR_JRN_EMPTY"
        Case OPOS_EPTR_REC_EMPTY
            msg = "OPOS_EPTR_REC_EMPTY"
        Case OPOS_EPTR_SLP_EMPTY
            msg = "OPOS_EPTR_SLP_EMPTY"
        Case OPOS_EPTR_SLP_FORM
            msg = "OPOS_EPTR_SLP_FORM"
        Case OPOS_EPTR_TOOBIG
            msg = "OPOS_EPTR_TOOBIG"
        Case OPOS_EPTR_BADFORMAT
            msg = "OPOS_EPTR_BADFORMAT"
        Case OPOS_EPTR_JRN_CARTRIDGE_REMOVED
            msg = "OPOS_EPTR_JRN_CARTRIDGE_REMOVED"
        Case OPOS_EPTR_JRN_CARTRIDGE_EMPTY
            msg = "OPOS_EPTR_JRN_CARTRIDGE_EMPTY"
        Case OPOS_EPTR_JRN_HEAD_CLEANING
            msg = "OPOS_EPTR_JRN_HEAD_CLEANING"
        Case OPOS_EPTR_REC_CARTRIDGE_REMOVED
            msg = "OPOS_EPTR_REC_CARTRIDGE_REMOVED"
        Case OPOS_EPTR_REC_CARTRIDGE_EMPTY
            msg = "OPOS_EPTR_REC_CARTRIDGE_EMPTY"
        Case OPOS_EPTR_REC_HEAD_CLEANING
            msg = "OPOS_EPTR_REC_HEAD_CLEANING"
        Case OPOS_EPTR_SLP_CARTRIDGE_REMOVED
            msg = "OPOS_EPTR_SLP_CARTRIDGE_REMOVED"
        Case OPOS_EPTR_SLP_CARTRIDGE_EMPTY
            msg = "OPOS_EPTR_SLP_CARTRIDGE_EMPTY"
        Case OPOS_EPTR_SLP_HEAD_CLEANING
            msg = "OPOS_EPTR_SLP_HEAD_CLEANING"
        Case OPOS_FIT_EPTR_PAPERLAYOUT
            msg = "OPOS_FIT_EPTR_PAPERLAYOUT"
        Case OPOS_FIT_EPTR_CUTTERJAM
            msg = "OPOS_FIT_EPTR_CUTTERJAM"
        Case Else
            msg = "UNDEFINE " + Str$(Code)
    End Select
    ResultCodeExtended_msg = msg
End Function

Public Sub PrPrintLog(ByVal Control As String, ByVal func As String, ByVal value As String)
    Dim msg As String
    Dim i As Long
    Dim log As String
        
    msg = (Time$ + " " + Control + " " + func + " >> " + value + Chr(&HD) + Chr(&HA))
        
    all_log(0) = msg + all_log(0)
    log_linecount = (log_linecount + 1) And &H3F
    If log_linecount = 0 Then
        For i = 14 To 0 Step -1
            all_log(i + 1) = all_log(i)
        Next i
        all_log(0) = ""
    End If
        
    log = ""
    prt_log(0) = msg
    For i = 14 To 0 Step -1
        log = prt_log(i) + log
        prt_log(i + 1) = prt_log(i)
    Next i
    OPOS_Tester.TextBoxlog.Text = log
        
    DoEvents
End Sub

Public Sub Msg_Box(ByVal err As Boolean)
    Call TextBoxlog_Click
    If err = False Then
        MsgBox ("Test : Success")
    Else
        MsgBox ("Test : Fail")
    End If
End Sub

Public Sub TextBoxlog_Click()
    Dim i As Long
    Dim log As String
        log = ""
        For i = 15 To 0 Step -1
            log = all_log(i) + log
        Next i
        OPOS_Tester.TextBoxlog.Text = log
        DoEvents
End Sub

Public Function tp_BinaryConversion(ByVal mode As Long, ByVal idata As Long) As String
    Dim odata As String
    odata = ""
    idata = idata And &HFF
    Select Case mode
        Case OPOS_BC_NONE
            If idata >= &H80 Then idata = 0
            odata = Chr(idata)
        Case OPOS_BC_NIBBLE
            'odata = Chr((idata >> 4) + &H30) + Chr((idata And &HF) + &H30)
            odata = Chr(Int(idata / 16) + &H30) + Chr((idata And &HF) + &H30)
        Case OPOS_BC_DECIMAL
            odata = Mid$(Str$(idata + 1000), 3, 3)
    End Select
    tp_BinaryConversion = odata
End Function

