Attribute VB_Name = "I7000u"

Option Explicit
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Global Port As Byte
Global BaudRate As Long
Global ToCheckSum As Byte
Global DataBit As Byte
Global Parity As Byte
Global StopBit As Byte
Global InData(0 To 999) As Single
Global Index As Integer
Global COMOpen As Integer

Global ConfigChange As Integer
Global flag As Integer

Global SendTo7000 As String
Global ReceiveFrom7000  As String
    
Global w7000(0 To 10) As Integer
Global f7000(0 To 10) As Single
Global Ret As Integer, status As Integer
Global Count As Integer

'===========
Global gcPort As Byte, gcDataBit As Byte, gcParity As Byte, gcStopBit As Byte
Global gdwBaudRate As Long
Global gszSend As String, gszReceive As String
Global gw7000(0 To 10) As Integer
Global gf7000(0 To 10) As Single


'*************************************
Public Sub IFillWordArray04(wArray() As Integer, ByVal wVal0 As Integer, ByVal wVal1 As Integer, _
                           ByVal wVal2 As Integer, ByVal wVal3 As Integer, ByVal wVal4 As Integer)
        wArray(0) = wVal0
        wArray(1) = wVal1
        wArray(2) = wVal2
        wArray(3) = wVal3
        wArray(4) = wVal4
End Sub

'*************************************
Public Sub IFillWordArray59(wArray() As Integer, ByVal wVal5 As Integer, ByVal wVal6 As Integer, _
                           ByVal wVal7 As Integer, ByVal wVal8 As Integer, ByVal wVal9 As Integer)
        wArray(5) = wVal5
        wArray(6) = wVal6
        wArray(7) = wVal7
        wArray(8) = wVal8
        wArray(9) = wVal9
End Sub

'*************************************
Public Sub IFillFloatArray04(fArray() As Single, ByVal fVal0 As Single, ByVal fVal1 As Single, _
                           ByVal fVal2 As Single, ByVal fVal3 As Single, ByVal fVal4 As Single)
        fArray(0) = fVal0
        fArray(1) = fVal1
        fArray(2) = fVal2
        fArray(3) = fVal3
        fArray(4) = fVal4
End Sub

'*************************************
Public Sub IFillFloatArray59(fArray() As Single, ByVal fVal5 As Single, ByVal fVal6 As Single, _
                           ByVal fVal7 As Single, ByVal fVal8 As Single, ByVal fVal9 As Single)
        fArray(5) = fVal5
        fArray(6) = fVal6
        fArray(7) = fVal7
        fArray(8) = fVal8
        fArray(9) = fVal9
End Sub

'*************************************
Public Function IOpenCom(ByVal cCOMPort As Byte, ByVal dwBaudRate As Long) As Integer
        IOpenCom = Open_Com(cCOMPort, dwBaudRate, 8, 0, 0)
End Function


'*************************************
Public Sub ISetCOMString(cb As ComboBox, iStart As Integer, iEnd As Integer)
    Dim i As Integer
    
    cb.Clear
    For i = iStart To iEnd
        cb.AddItem "COM" + Str(i)
    Next
    cb.ListIndex = 0
End Sub

'*************************************
Public Sub ISetBaudRateString(cb As ComboBox)
    cb.Clear
    cb.AddItem "115200"
    cb.AddItem "57600"
    cb.AddItem "38400"
    cb.AddItem "19200"
    cb.AddItem "9600"
    cb.AddItem "4800"
    cb.AddItem "2400"
    cb.AddItem "1200"
    cb.ListIndex = 0
End Sub

'*************************************
Public Function GetErrorString(ByVal wErrCode As Integer) As String
    Dim ErrString As String

    Select Case wErrCode
    Case 0
        ErrString = "No Error"
    Case 1
        ErrString = "Function Error"
    Case 2
        ErrString = "Port Error"
    Case 3
        ErrString = "Baud Rate Error"
    Case 4
        ErrString = "Data Error"
    Case 5
        ErrString = "Stop Error"
    Case 6
        ErrString = "Parity Error"
    Case 7
        ErrString = "CheckSum Error"
    Case 8
        ErrString = "ComPort Not Open"
    Case 9
        ErrString = "Send Thread Create Error"
    Case 10
        ErrString = "Send Command Error"
    Case 11
        ErrString = "Read Com Port Status Error"
    Case 12
        ErrString = "Result String Check Error"
    Case 13
        ErrString = "Command Error"
    'Case 14
    '    ErrString = ""
    Case 15
        ErrString = "Time Out"
    'Case 16
    '    ErrString = ""
    Case 17
        ErrString = "Module Id Error"
    Case 18
        ErrString = "AD Channel Error"
    Case 19
        ErrString = "Under Input Range"
    Case 20
        ErrString = "Exceed Input Range"
    Case 21
        ErrString = "Invalidate Counter No"
    Case 22
        ErrString = "Invalidate Counter Value"
    Case 23
        ErrString = "Invalidate Gate Mode"
    Case Else
        ErrString = "Unknown Error"
    End Select

    GetErrorString = ErrString
End Function

Public Function IGetErrorString(ByVal wErrCode As Integer) As String
        IGetErrorString = GetErrorString(wErrCode)
End Function

'*************************************

Public Function MakeDWord(wHi As Integer, wLo As Integer) As Long
    Dim HiPart As Long
    
    If wHi And &H8000& Then
        HiPart = (wHi And &H7FFF&) * 65536
        MakeDWord = (HiPart + (wLo And &HFFFF&)) Or &H80000000
    Else
        If wLo And &H8000 Then
            MakeDWord = (wHi * 65536) Or (wLo And &H7FFF) Or &H8000&
        Else
            MakeDWord = (wHi * 65536) + wLo
        End If
    End If
End Function

