Author Topic: 控制 Pole Display 的程序函數庫  (Read 5309 times)

admin

  • Administrator
  • *****
  • Posts: 0
    • View Profile
控制 Pole Display 的程序函數庫
« on: December 25, 2011, 12:26:51 PM »
可控制以下這幾款不同牌子及型號的顧客顯示屏
0=WD-202  1=ICD-2002  2=WD-304  3=VT-VFD220E, VFD650K  4=ACE

Code: [Select]
Option Explicit

Public MSCObject As MSComm
Public DisplayCommPort As Integer
Public DisplayCharLength As Integer
Public DisplayCodeSet As Integer    '0=WD-202  1=ICD-2002  2=WD-304  3=VT-VFD220E, VFD650K  4=ACE
Public OutPutStatus As Integer
Public LCDDisplayTop As Long
Public LCDDisplayLeft As Long

Sub InitDisplay()

    Select Case DisplayCodeSet
        Case 1
            'Set Overwrite Mode
            MSCObject.Output = Chr(27) & Chr(69) & Chr(88) & Chr(52)
            MSCObject.OutBufferCount = 0
    End Select

End Sub

Sub InitCharLength()

    Select Case DisplayCodeSet
        Case 0, 1, 3
            DisplayCharLength = 20
        Case 2
            DisplayCharLength = 30
        Case 4
            DisplayCharLength = 6
    End Select

End Sub

Sub ClearDisplay()

    If DisplayCommPort = 0 Then Exit Sub

    Select Case DisplayCodeSet
        Case 0, 2, 3
            MSCObject.Output = Chr(12)
        Case 1
            'MSCObject.Output = Chr(27) & Chr(64)
            MSCObject.Output = Chr(12)
    End Select
    MSCObject.OutBufferCount = 0

End Sub

Sub ClearRow(UpperRow As Boolean)

Dim k As Integer

    If DisplayCommPort = 0 Then Exit Sub

    If UpperRow = True Then
        MoveCursor (1)
    Else
        MoveCursor (2)
    End If
    Select Case DisplayCodeSet
        Case 0, 3
            MSCObject.Output = Chr(24)
        Case 1, 2
            Entry = Empty
            For k = 0 To DisplayCharLength - 1
                Entry = Entry & " "
            Next k
            MSCObject.Output = Entry
    End Select
    MSCObject.OutBufferCount = 0

End Sub

Sub MoveCursor(RowPosition As Integer, Optional CursorPosition As Integer = 1)

    If DisplayCommPort = 0 Then Exit Sub

    Select Case DisplayCodeSet
        Case 0
            MSCObject.Output = Chr(27) & Chr(108) & Chr(CursorPosition) & Chr(RowPosition)
        Case 1
            If RowPosition = 1 Then
                MSCObject.Output = Chr(27) & Chr(85)
            ElseIf RowPosition = 2 Then
                MSCObject.Output = Chr(27) & Chr(68)
            End If
            MSCObject.Output = Chr(13)
        Case 3
            If RowPosition = 1 Then
                MSCObject.Output = Chr(11)
            ElseIf RowPosition = 2 Then
                MSCObject.Output = Chr(11)
                MSCObject.Output = Chr(10)
            End If
    End Select
    MSCObject.OutBufferCount = 0

End Sub

Sub ULDisplay(DisplayString As String, Optional Clear As Boolean = True, Optional TrimString As Boolean = True)

    If DisplayCommPort = 0 Then Exit Sub
   
    If Clear = True Then
        Call ClearRow(True)
    Else
        Call MoveCursor(1)
    End If
    If TrimString = True Then
        MSCObject.Output = Trim(Left(DisplayString, DisplayCharLength))
    Else
        MSCObject.Output = Left(DisplayString, DisplayCharLength)
    End If
    MSCObject.OutBufferCount = 0

End Sub

Sub URDisplay(DisplayString As String, Optional Clear As Boolean = True)

Dim k As Integer

    If DisplayCommPort = 0 Then Exit Sub
   
    If Clear = True Then
        Call ClearRow(True)
    Else
        Call MoveCursor(1)
    End If
    Entry = Empty
    For k = 0 To DisplayCharLength - Len(Trim(Left(DisplayString, DisplayCharLength))) - 1
        Entry = Entry & " "
    Next k
    Entry = Entry & Trim(Left(DisplayString, DisplayCharLength))
    MSCObject.Output = Entry
    MSCObject.OutBufferCount = 0

End Sub

Sub UMDisplay(DisplayString As String, Optional Clear As Boolean = True)

Dim MidString As String

    If DisplayCommPort = 0 Then Exit Sub
   
    If Clear = True Then
        Call ClearRow(True)
    Else
        Call MoveCursor(1)
    End If
    MidString = Trim(Left(DisplayString, DisplayCharLength))
    MidString = Space(Int(((DisplayCharLength - Len(MidString)) / 2) + 0.99)) & MidString
    MSCObject.Output = MidString
    MSCObject.OutBufferCount = 0

End Sub

Sub LLDisplay(DisplayString As String, Optional Clear As Boolean = True, Optional TrimString As Boolean = True)
    On Error GoTo ErrHandler

    If DisplayCommPort = 0 Then Exit Sub
   
    If Clear = True Then
        Call ClearRow(False)
    Else
        Call MoveCursor(2)
    End If
    If TrimString = True Then
        MSCObject.Output = Trim(Left(DisplayString, DisplayCharLength))
    Else
        MSCObject.Output = Left(DisplayString, DisplayCharLength)
    End If
    MSCObject.OutBufferCount = 0

    Exit Sub
   
ErrHandler:
    'UpdateErrLog gstrCurrStaffName, gstrCurrStaffPC, gintCurrPlatform, "LLDisplay Module Error", Err.Number & "#" & Err.Description
    UpdateHistory gstrCurrStaffName, gstrCurrStaffPC, gintCurrPlatform, "LLDisplay Module Error", Err.Number & "#" & Err.Description

End Sub

Sub LRDisplay(DisplayString As String, Optional Clear As Boolean = True)

Dim k As Integer

    If DisplayCommPort = 0 Then Exit Sub
   
    If Clear = True Then
        Call ClearRow(False)
    Else
        Call MoveCursor(2)
    End If
    Entry = Empty
    For k = 0 To DisplayCharLength - Len(Trim(Left(DisplayString, DisplayCharLength))) - 1
        Entry = Entry & " "
    Next k
    Entry = Entry & Trim(Left(DisplayString, DisplayCharLength))
    MSCObject.Output = Entry
    MSCObject.OutBufferCount = 0

End Sub

Sub LMDisplay(DisplayString As String, Optional Clear As Boolean = True)

Dim MidString As String

    If DisplayCommPort = 0 Then Exit Sub
   
    If Clear = True Then
        Call ClearRow(False)
    Else
        Call MoveCursor(2)
    End If
    MidString = Trim(Left(DisplayString, DisplayCharLength))
    MidString = Space(Int(((DisplayCharLength - Len(MidString)) / 2) + 0.99)) & MidString
    MSCObject.Output = MidString
    MSCObject.OutBufferCount = 0

End Sub

Sub MixedDisplay(LeftString As String, RightString As String, UpperRow As Boolean, Optional DeleteLeft As Boolean = True)

Dim MixedString As String

    If DisplayCommPort = 0 Then Exit Sub

    If DeleteLeft = True Then
        LeftString = Left(LeftString, DisplayCharLength - Len(RightString) - 1)
    Else
        RightString = Right(RightString, DisplayCharLength - Len(LeftString) - 1)
    End If
    If UpperRow = True Then Call MoveCursor(1) Else Call MoveCursor(2)
    MixedString = LeftString & Space(DisplayCharLength - Len(LeftString) - Len(RightString)) & RightString
    MSCObject.Output = MixedString
    MSCObject.OutBufferCount = 0
   
End Sub

Public Sub StringDisplay(MixedString As Boolean, DisplayLine As Integer, DisplayString As String, Optional DisplayString2 As String = Empty, Optional DisplaySide As Integer = 0, Optional CutMethod As Integer = 0, Optional TrimString As Boolean = True)

On Error GoTo ErrHandler

Dim k As Integer
Dim LineChr As String
Dim ResultString As String

    If DisplayCommPort = 0 Or Not DisplayCodeSet = 2 Then Exit Sub
   
    Select Case DisplayLine
        Case 1      'Single Height Line 1
            LineChr = Chr$(&H41)
        Case 2      'Single Height Line 2
            LineChr = Chr$(&H42)
        Case 3      'Single Height Line 3
            LineChr = Chr$(&H43)
        Case 4      'Single Height Line 4
            LineChr = Chr$(&H44)
        Case 5      'Double Height Line 1
            LineChr = Chr$(&H45)
        Case 6      'Double Height Line 2
            LineChr = Chr$(&H46)
    End Select
   
    If MixedString = True Then
        'DisplayString = LeftString   DisplayString2 = RightString
        If DBLen(DisplayString) + DBLen(DisplayString2) > DisplayCharLength Then
            Do Until DBLen(DisplayString) + DBLen(DisplayString2) <= DisplayCharLength
                Select Case CutMethod
                    Case 0  'Cut String1 Left Side
                        DisplayString = Left(DisplayString, Len(DisplayString) - 1)
                    Case 1  'Cut String1 Right Side
                        DisplayString = Right(DisplayString, Len(DisplayString) - 1)
                    Case 2  'Cut String2 Left Side
                        DisplayString2 = Right(DisplayString2, Len(DisplayString2) - 1)
                    Case 3  'Cut String2 Right Side
                        DisplayString2 = Left(DisplayString2, Len(DisplayString2) - 1)
                End Select
            Loop
            ResultString = DisplayString & DisplayString2
        Else
            ResultString = DisplayString & Space(DisplayCharLength - DBLen(DisplayString) - DBLen(DisplayString2)) & DisplayString2
        End If
    Else
        Select Case DisplaySide
            Case 0      'Left
                If TrimString = True Then
                    ResultString = Trim(Left(DisplayString, DisplayCharLength))
                Else
                    ResultString = Left(DisplayString, DisplayCharLength)
                End If
            Case 1      'Right
                ResultString = Trim(Right(DisplayString, DisplayCharLength))
                ResultString = Space(DisplayCharLength - DBLen(ResultString)) & ResultString
            Case 2      'Middle
                ResultString = Trim(Left(DisplayString, DisplayCharLength))
                ResultString = Space(Int(((DisplayCharLength - DBLen(ResultString)) / 2) + 0.99)) & ResultString
        End Select
    End If
    MSCObject.Output = Chr$(&H1B) & Chr$(&H71) & LineChr & ResultString & Chr$(&HD)
    MSCObject.OutBufferCount = 0

    Exit Sub
   
ErrHandler:

    'UpdateErrLog gstrCurrStaffName, gstrCurrStaffPC, gintCurrPlatform, "StringDisplay Module Error", Err.Number & "#" & Err.Description
    UpdateHistory gstrCurrStaffName, gstrCurrStaffPC, gintCurrPlatform, "StringDisplay Module Error", Err.Number & "#" & Err.Description
End Sub

Sub MoveLogo(LCDDisplayForm As Form, LCDDisplayImage As Image)

Dim LogoTop As Long, LogoLeft As Long

    With LCDDisplayForm
        Randomize
        LogoTop = Int(((.Height - LCDDisplayImage.Height) * Rnd) + 1)
        Randomize
        LogoLeft = Int(((.Width - LCDDisplayImage.Width) * Rnd) + 1)
        LCDDisplayImage.Top = LogoTop
        LCDDisplayImage.Left = LogoLeft
    End With

End Sub