VERSION 5.00
Begin VB.Form Form1 
   ClientHeight    =   4815
   ClientLeft      =   3030
   ClientTop       =   2310
   ClientWidth     =   7845
   BeginProperty Font 
      Name            =   "MS Sans Serif"
      Size            =   9.75
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   LinkMode        =   1  'Source
   LinkTopic       =   "Form1"
   PaletteMode     =   1  'UseZOrder
   ScaleHeight     =   4815
   ScaleWidth      =   7845
   Begin VB.Frame Frame3 
      Caption         =   "Analogout of 7021"
      Height          =   1455
      Left            =   120
      TabIndex        =   35
      Top             =   2640
      Width           =   3495
      Begin VB.TextBox Text1 
         Height          =   330
         Left            =   1920
         TabIndex        =   40
         Text            =   "2"
         Top             =   720
         Width           =   1455
      End
      Begin VB.HScrollBar HScroll1 
         Height          =   255
         Left            =   120
         Max             =   100
         TabIndex        =   36
         Top             =   360
         Width           =   3255
      End
      Begin VB.Label Label15 
         Caption         =   "Address of 7021G"
         Height          =   255
         Left            =   120
         TabIndex        =   39
         Top             =   720
         Width           =   1695
      End
      Begin VB.Label Label14 
         Height          =   255
         Left            =   2160
         TabIndex        =   38
         Top             =   1080
         Width           =   1095
      End
      Begin VB.Label Label2 
         Caption         =   "Output value of 7021G"
         Height          =   255
         Left            =   120
         TabIndex        =   37
         Top             =   1080
         Width           =   2535
      End
   End
   Begin VB.CommandButton CmdActive 
      Caption         =   "Start"
      BeginProperty Font 
         Name            =   "sө"
         Size            =   12
         Charset         =   136
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   450
      Left            =   1800
      TabIndex        =   34
      Top             =   4200
      Width           =   615
   End
   Begin VB.Timer Timer1 
      Left            =   3240
      Top             =   1680
   End
   Begin VB.TextBox txtEventCounter 
      BackColor       =   &H0000FFFF&
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   360
      Left            =   5712
      TabIndex        =   32
      Top             =   276
      Width           =   1824
   End
   Begin VB.TextBox txtAnalogInput 
      BackColor       =   &H0000FFFF&
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   360
      Left            =   3840
      TabIndex        =   31
      Top             =   300
      Width           =   1485
   End
   Begin VB.Frame fmeDigitalOut 
      Caption         =   "DigitalOut"
      ForeColor       =   &H00FF0000&
      Height          =   1044
      Left            =   3720
      TabIndex        =   25
      Top             =   1920
      Width           =   2700
      Begin VB.Image imgDigitalOut 
         Height          =   420
         Index           =   1
         Left            =   1680
         Top             =   495
         Width           =   510
      End
      Begin VB.Image imgDigitalOut 
         Height          =   420
         Index           =   0
         Left            =   336
         Top             =   504
         Width           =   516
      End
      Begin VB.Label Label13 
         Caption         =   "DO:1"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   216
         Left            =   1680
         TabIndex        =   27
         Top             =   276
         Width           =   948
      End
      Begin VB.Label Label12 
         Caption         =   "DO:0"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   210
         Left            =   240
         TabIndex        =   26
         Top             =   270
         Width           =   945
      End
   End
   Begin VB.Frame Frame2 
      Caption         =   "DigitalIn"
      ForeColor       =   &H00FF0000&
      Height          =   1044
      Left            =   6612
      TabIndex        =   21
      Top             =   1920
      Width           =   1164
      Begin VB.Label Label7 
         Caption         =   "DI: OFF"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   216
         Left            =   216
         TabIndex        =   22
         Top             =   264
         Width           =   708
      End
      Begin VB.Image imgDigitalIn 
         Height          =   420
         Left            =   252
         Top             =   480
         Width           =   540
      End
   End
   Begin VB.CommandButton CmdClear 
      Caption         =   "Clear Counter"
      BeginProperty Font 
         Name            =   "sө"
         Size            =   12
         Charset         =   136
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   435
      Left            =   0
      TabIndex        =   20
      Top             =   4200
      Width           =   1650
   End
   Begin VB.Frame Frame11 
      Caption         =   "Alarm State:"
      ForeColor       =   &H00FF0000&
      Height          =   1032
      Left            =   3720
      TabIndex        =   14
      Top             =   672
      Width           =   4020
      Begin VB.CommandButton cmdClearLatch 
         Caption         =   "Clear Latch"
         BeginProperty Font 
            Name            =   "sө"
            Size            =   12
            Charset         =   136
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   432
         Left            =   2520
         TabIndex        =   33
         Top             =   480
         Width           =   1380
      End
      Begin VB.Label lblHighAlarm 
         Caption         =   "High Alarm: OFF"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   210
         Left            =   1560
         TabIndex        =   30
         Top             =   240
         Width           =   1350
      End
      Begin VB.Label lblLowAlarm 
         Caption         =   "Low Alarm: OFF"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   216
         Left            =   84
         TabIndex        =   29
         Top             =   252
         Width           =   1260
      End
      Begin VB.Image imgAlarm 
         Height          =   405
         Index           =   1
         Left            =   1680
         Top             =   495
         Width           =   540
      End
      Begin VB.Image imgAlarm 
         Height          =   408
         Index           =   0
         Left            =   288
         Top             =   480
         Width           =   540
      End
   End
   Begin VB.Frame fmeAlarmSetting 
      Caption         =   "Configuration of Alarm: "
      ForeColor       =   &H00FF0000&
      Height          =   1536
      Left            =   3720
      TabIndex        =   10
      Top             =   3120
      Width           =   4020
      Begin VB.ComboBox cmbAlarmMode 
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   315
         ItemData        =   "Form1.frx":0000
         Left            =   240
         List            =   "Form1.frx":000D
         TabIndex        =   28
         Text            =   "Disable"
         Top             =   480
         Width           =   1524
      End
      Begin VB.TextBox txtAlarmValue 
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   288
         Index           =   1
         Left            =   2040
         TabIndex        =   17
         Text            =   "0"
         Top             =   1080
         Width           =   1452
      End
      Begin VB.TextBox txtAlarmValue 
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   288
         Index           =   0
         Left            =   240
         TabIndex        =   16
         Text            =   "0"
         Top             =   1080
         Width           =   1488
      End
      Begin VB.CommandButton cmdSetting 
         Caption         =   "SET"
         BeginProperty Font 
            Name            =   "sө"
            Size            =   12
            Charset         =   136
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   384
         Left            =   2040
         TabIndex        =   11
         Top             =   360
         Width           =   1212
      End
      Begin VB.Label Label6 
         Caption         =   "High Alarm Value:"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   2040
         TabIndex        =   19
         Top             =   840
         Width           =   1410
      End
      Begin VB.Label Label5 
         Caption         =   "Low Alarm Value:"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   240
         TabIndex        =   18
         Top             =   840
         Width           =   1410
      End
      Begin VB.Label Label1 
         Caption         =   "Alarm Mode"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   240
         TabIndex        =   15
         Top             =   240
         Width           =   1095
      End
   End
   Begin VB.Frame Frame1 
      Caption         =   "Configuration"
      ForeColor       =   &H00FF0000&
      Height          =   2490
      Left            =   120
      TabIndex        =   1
      Top             =   48
      Width           =   3420
      Begin VB.ComboBox cmbModuleID 
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   288
         ItemData        =   "Form1.frx":002C
         Left            =   1440
         List            =   "Form1.frx":0039
         TabIndex        =   23
         Text            =   "7011"
         Top             =   408
         Width           =   1452
      End
      Begin VB.TextBox txtAddress 
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   288
         Left            =   1440
         TabIndex        =   9
         Text            =   "1"
         Top             =   1188
         Width           =   1428
      End
      Begin VB.ComboBox cmbChecksum 
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   288
         ItemData        =   "Form1.frx":004F
         Left            =   1428
         List            =   "Form1.frx":0059
         TabIndex        =   7
         Text            =   "Disable"
         Top             =   2004
         Width           =   1452
      End
      Begin VB.ComboBox cmbCOMPort 
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   288
         ItemData        =   "Form1.frx":006E
         Left            =   1440
         List            =   "Form1.frx":008D
         TabIndex        =   3
         Text            =   "COM1"
         Top             =   828
         Width           =   1452
      End
      Begin VB.ComboBox cmbBaudrate 
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   288
         ItemData        =   "Form1.frx":00C7
         Left            =   1440
         List            =   "Form1.frx":00E3
         TabIndex        =   2
         Text            =   "9600"
         Top             =   1596
         Width           =   1428
      End
      Begin VB.Label Label11 
         Caption         =   "Module ID:"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   252
         Left            =   156
         TabIndex        =   24
         Top             =   480
         Width           =   972
      End
      Begin VB.Label Label9 
         Caption         =   "Address"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   150
         TabIndex        =   8
         Top             =   1200
         Width           =   1230
      End
      Begin VB.Label Label8 
         Caption         =   "CheckSum"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   252
         Left            =   168
         TabIndex        =   6
         Top             =   2004
         Width           =   972
      End
      Begin VB.Label Label3 
         Caption         =   "Com Port:"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   150
         TabIndex        =   5
         Top             =   840
         Width           =   975
      End
      Begin VB.Label Label4 
         Caption         =   "Baudrate"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   120
         TabIndex        =   4
         Top             =   1620
         Width           =   975
      End
   End
   Begin VB.CommandButton CmdExit 
      Caption         =   "Exit"
      BeginProperty Font 
         Name            =   "sө"
         Size            =   12
         Charset         =   136
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   444
      Left            =   2640
      TabIndex        =   0
      Top             =   4200
      Width           =   660
   End
   Begin VB.Label Label10 
      Caption         =   "Analogin of 7012"
      ForeColor       =   &H00FF0000&
      Height          =   255
      Left            =   3840
      TabIndex        =   13
      Top             =   0
      Width           =   1665
   End
   Begin VB.Label txtEventCount 
      Caption         =   "Even Counter"
      ForeColor       =   &H00FF0000&
      Height          =   255
      Left            =   5760
      TabIndex        =   12
      Top             =   0
      Width           =   1440
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

Private Sub cmbChecksum_Change()
                                    'CheckSum of Module select
    CheckSum = cmbChecksum.ListIndex
End Sub

Private Sub cmbChecksum_Click()
                                    'CheckSum of Module select
    CheckSum = cmbChecksum.ListIndex
End Sub

Private Sub CmdClear_Click()
    Dim Ret As Integer
    
    If COMOpen = 0 Then                        'OpenPort Function
         OpenCom
    End If
    w7000(0) = cmbCOMPort.ListIndex + 1       'ComPort Select
    w7000(1) = Val("&H" & txtAddress.Text)    'Module Address
    w7000(2) = Val("&H" & cmbModuleID.Text)    'Module ID
    w7000(3) = cmbChecksum.ListIndex           'CheckSum of module
    w7000(4) = 100                            'TIMEOUT of module
    w7000(6) = 0                               ' string debug
    Ret = ClearEventCounter(w7000(0), f7000(0), SendTo7000, ReceiveFrom7000)
    If Ret > 0 Then
         MsgBox "ClearEventCounter() Error !", vbCritical, _
                                  "Error Code:" + Str(Ret)
    End If
End Sub

Private Sub cmdClearLatch_Click()
    Dim Ret As Integer
    
    If COMOpen = 0 Then                        'OpenPort Function
        OpenCom
    End If
    w7000(0) = cmbCOMPort.ListIndex + 1        'ComPort Select
    w7000(1) = Val("&H" & txtAddress.Text)     'Module Address
    w7000(2) = Val("&H" & cmbModuleID.Text)    'Module ID
    w7000(3) = cmbChecksum.ListIndex           'CheckSum of module
    w7000(4) = 100                             'TIMEOUT of module
    w7000(6) = 0                               ' string debug
    Ret = ClearLatchAlarm(w7000(0), f7000(0), SendTo7000, ReceiveFrom7000)
    If Ret > 0 Then
         MsgBox "ClearLatchAlarm() Error !", vbCritical, "Error Code:" + Str(Ret)
    End If

End Sub

Private Function fDisableAlarm()
                                                'Disable Alarm Function
    If COMOpen = 0 Then
         OpenCom
    End If
    '--------- Disable Alarm ----------------
    
    w7000(0) = cmbCOMPort.ListIndex + 1       'ComPort Select
    w7000(1) = Val("&H" & txtAddress.Text)    'Module Address
    w7000(2) = Val("&H" & 7012)               'Module ID
    w7000(3) = cmbChecksum.ListIndex          'CheckSum of module
    w7000(4) = 100                            'TIMEOUT of module
    w7000(5) = 0
    w7000(6) = 0                               ' string debug
    Ret = DisableAlarm(w7000(0), f7000(0), SendTo7000, ReceiveFrom7000)
    If Ret > 0 Then
         MsgBox "DisableAlarm() !", vbCritical, "Error Code:" + Str(Ret)
         Close_Com (Port)
         End
   End If
    
End Function
Private Function fEnableAlarm()
                                                'Enable Alarm Function
    If COMOpen = 0 Then
         OpenCom
    End If

    '--------- Enable Alarm ----------------
    w7000(0) = cmbCOMPort.ListIndex + 1       'ComPort Select
    w7000(1) = Val("&H" & txtAddress.Text)    'Module Address
    w7000(2) = Val("&H" & 7012)               'Module ID
    w7000(3) = cmbChecksum.ListIndex          'CheckSum of module
    w7000(4) = 100                            'TIMEOUT of module
    ' Enable Alarm Mode  'w7000(5)=0  Momentary,  w7000(5)=1  Latch
    w7000(5) = cmbAlarmMode.ListIndex - 1
    w7000(6) = 0
    Ret = EnableAlarm(w7000(0), f7000(0), SendTo7000, ReceiveFrom7000)
    If Ret > 0 Then
         MsgBox "EnableAlarm() !", vbCritical, "Error Code:" + Str(Ret)
         Close_Com (Port)
         End
    End If
    flag = 1
End Function

Private Function fSetAlarmLimitValue()
                                            'Set Alarm Limit value of module
    Dim LoAlarmValue As Single
    Dim HiAlarmValue As Single
    Dim Ret As Integer
    If COMOpen = 0 Then
         OpenCom
    End If
    LoAlarmValue = Val(txtAlarmValue(0).Text)
    HiAlarmValue = Val(txtAlarmValue(1).Text)
    '--------- Parameter ----------------
    w7000(0) = cmbCOMPort.ListIndex + 1      'ComPort Select
    w7000(1) = Val("&H" & txtAddress.Text)   'Module Address
    w7000(2) = Val("&H" & 7012)              'Module ID
    w7000(3) = CheckSum                      'CheckSum of module
    w7000(4) = 100                           'TIMEOUT of module
    w7000(5) = 0                             'Set Low Alarm value
    w7000(6) = 0
    f7000(0) = LoAlarmValue                  'Low Alarm value
    Ret = SetAlarmLimitValue(w7000(0), f7000(0), SendTo7000, ReceiveFrom7000)
    If Ret > 0 Then
         MsgBox "SetAlarmLimitValue() !", vbCritical, "Error Code:" + Str(Ret)
         Close_Com (Port)
         End
    End If
    w7000(5) = 1                              'Set High Alarm value
    f7000(0) = HiAlarmValue                   'High Alarm value
    Ret = SetAlarmLimitValue(w7000(0), f7000(0), SendTo7000, ReceiveFrom7000)
    If Ret > 0 Then
         MsgBox "SetAlarmLimitValue() !", vbCritical, "Error Code:" + Str(Ret)
         Close_Com (Port)
         End
    End If
End Function
Private Function fReadAlarmLimitValue()
                                              'Read Alarm Limit value
    Dim LoAlarmValue As Single
    Dim HiAlarmValue As Single
    Dim Ret As Integer
    If COMOpen = 0 Then
         OpenCom
    End If
    LoAlarmValue = Val(txtAlarmValue(0).Text)
    HiAlarmValue = Val(txtAlarmValue(1).Text)
    '---------  ----------------
    w7000(0) = cmbCOMPort.ListIndex + 1      'ComPort Select
    w7000(1) = Val("&H" & txtAddress.Text)   'Module Address
    w7000(2) = Val("&H" & cmbModuleID.Text)  'Module ID
    w7000(3) = CheckSum                      'CheckSum of module
    w7000(4) = 100                           'TIMEOUT of module
    w7000(5) = 0                             'Read Low Alarm value Mode
    w7000(6) = 0
    Ret = ReadAlarmLimitValue(w7000(0), f7000(0), SendTo7000, ReceiveFrom7000)
    If Ret > 0 Then
         MsgBox "SetAlarmLimitValue() !", vbCritical, "Error Code:" + Str(Ret)
         Close_Com (Port)
         End
    End If
    LoAlarmValue = f7000(0)                  'Low Alarm Value
    w7000(5) = 1                             'Read High Alarm value Mode
    Ret = ReadAlarmLimitValue(w7000(0), f7000(0), SendTo7000, ReceiveFrom7000)
    If Ret > 0 Then
         MsgBox "SetAlarmLimitValue() !", vbCritical, "Error Code:" + Str(Ret)
         Close_Com (Port)
         End
    End If
    HiAlarmValue = f7000(0)                  'High Alarm value
    txtAlarmValue(0).Text = LoAlarmValue
    txtAlarmValue(1).Text = HiAlarmValue
End Function
Private Function fReadOutputAlarmState()
                                            'Read Output Alarm State
    Dim AlarmMode As Integer
    Dim DigitalOutData As Integer
    Dim DigitalOut(0 To 1) As Integer
    Dim Ret As Integer
    If COMOpen = 0 Then
         OpenCom
    End If
    
    w7000(0) = cmbCOMPort.ListIndex + 1         'COM Port
    w7000(1) = Val("&H" & txtAddress.Text)      ' Module Address
    w7000(2) = Val("&H" & cmbModuleID.Text)     ' Module Type
    w7000(3) = CheckSum                         ' Checksum
    w7000(4) = 100                              ' TimeOut = 0.1 second
    'w7000(5) = 0 no use
                                                'Low Alarm Value
    w7000(6) = 0
    Ret = ReadOutputAlarmState(w7000(0), f7000(0), SendTo7000, ReceiveFrom7000)
    If Ret > 0 Then
         MsgBox "SetAlarmLimitValue() !", vbCritical, "Error Code:" + Str(Ret)
         Close_Com (Port)
         End
    End If
    AlarmMode = w7000(7)                        '0: Alarm Disable 1: Momentary 2: Latch
    cmbAlarmMode.ListIndex = AlarmMode
    DigitalOutData = w7000(8)
    DigitalOut(0) = DigitalOutData Mod 2
    DigitalOut(1) = DigitalOutData \ 2
    '--------- Digital Input Lamp ---------------
    'Dispaly the picture of ligh
    imgDigitalIn.Picture = LoadPicture(App.Path + "\off2.ico")
    '-------- Alarm Status ------------
      
         
    If AlarmMode > 0 Then  ' when Alarm Enabled
         '------- Digital Out Lamp --------
         '-------- Alarm Lamp --------
         
            If DigitalOut(0) Then               'Display the Picture of the Low Alarm  state is "On"
                imgDigitalOut(0).Picture = LoadPicture(App.Path + "\on2.ico")
                imgAlarm(0).Picture = LoadPicture(App.Path + "\on2.ico")
                lblLowAlarm.Caption = "Low Alarm ON"
            Else                                'Display the Picture of the Low Alarm  state is "Off"
                imgDigitalOut(0).Picture = LoadPicture(App.Path + "\off2.ico")
                imgAlarm(0).Picture = LoadPicture(App.Path + "\off2.ico")
                lblLowAlarm.Caption = "Low Alarm Off"
            End If
            If DigitalOut(1) Then               'Display the Picture of the High Alarm  state is "On"
                imgDigitalOut(1).Picture = LoadPicture(App.Path + "\on2.ico")
                imgAlarm(1).Picture = LoadPicture(App.Path + "\on2.ico")
                lblHighAlarm.Caption = "High Alarm ON"
            Else                                'Display the Picture of the High Alarm  state is "Off"
                imgDigitalOut(1).Picture = LoadPicture(App.Path + "\off2.ico")
                imgAlarm(1).Picture = LoadPicture(App.Path + "\off2.ico")
                lblHighAlarm.Caption = "High Alarm Off"
            End If
        Else                                    ' when Alarm Disabled
                                                'Display all  Picture of the Alarm  state is "Of"
            '------- Digital Out Lamp --------
            imgDigitalOut(0).Picture = LoadPicture(App.Path + "\off2.ico")
            imgDigitalOut(1).Picture = LoadPicture(App.Path + "\off2.ico")
            '-------- Alarm Lamp --------
            imgAlarm(0).Picture = LoadPicture(App.Path + "\off2.ico")
            imgAlarm(1).Picture = LoadPicture(App.Path + "\off2.ico")
        End If
End Function

Private Sub cmdSetting_Click()
    'Set Alarm Mode function
    Dim LoAlarmValue As Single
    Dim HiAlarmValue As Single
    Dim Ret%, SettingSuccess%
    SettingSuccess = 1
    If COMOpen = 0 Then
         OpenCom
    End If
    
    fSetAlarmLimitValue                  'Set Alarm Limit value function
    
    If cmbAlarmMode.ListIndex = 0 Then   'Alarm Mode Select
         fDisableAlarm                   'Disable Alarm function
    Else
         fEnableAlarm                    'Enable Alarm Function
    End If
   
 
    If SettingSuccess Then
        Beep
        MsgBox "Setting Successful !", vbInformation
    Else
        MsgBox "Setting Failure !", vbCritical
    End If
   
End Sub

Private Sub CmdExit_Click()
                                        'Exit
  If COMOpen = True Then
       Close_Com (Port)
  End If
  Unload Me
End Sub

Private Sub CmdActive_Click()
                                        'Enable Test function
     If CmdActive.Caption = "Stop" Then
        CmdActive.Caption = "Start"
        Close_Com (Port)
        COMOpen = 0
        Timer1.Enabled = False          'Disable TIMER
        Frame1.Enabled = True           'Set frame1 is enable
        Text1.Enabled = True
        Exit Sub
    End If
    
    CmdActive.Caption = "Stop"
    Frame1.Enabled = False              'Set FRAME1 is false
                                        'Open Port function
    If COMOpen = 0 Then
         OpenCom
    End If
        
    Text1.Enabled = False
    Timer1.Enabled = True               'Enable TIMER
End Sub

Private Sub Form_Load()
                                        'Form load
    cmbCOMPort.ListIndex = 0
    cmbChecksum.ListIndex = 0
    cmbBaudrate.ListIndex = 4
    cmbAlarmMode.ListIndex = 0
    cmbModuleID.ListIndex = 1

    COMOpen = 0
    Index = 0
    Counter = 0
    Timer1.Interval = 200
    Timer1.Enabled = False
    SendTo7000 = Space(80)
    ReceiveFrom7000 = Space(80)
    
    fReadOutputAlarmState
    fReadAlarmLimitValue
       
End Sub

Private Sub Form_Unload(Cancel As Integer)
                                        'Using "Unload Form" to free memory
    If COMOpen > 0 Then
        Close_Com (Port)
    End If
    End
End Sub

Public Function OpenCom()
                                        'Open Function
    Dim i%, Response%, Ret%, Successful%
    
    COMOpen = 0
    Port = cmbCOMPort.ListIndex + 1
    BaudRate = Val(cmbBaudrate.Text)
    DataBit = 8                         ' 8 data bit
    Parity = 0                          ' Non Parity
    StopBit = 0                         ' One Stop Bit
      
    Ret = Open_Com(Port, BaudRate, DataBit, Parity, StopBit)
    If Ret > 0 Then
        COMOpen = 0
        Beep
        Successful = 0
        Response = MsgBox("Quit this demo?", vbYesNo, "OPEN_COM Error Code:" + Str(Ret))
        If Response = vbYes Then
            Close_Com (Port)
            Unload Me
        End If
    End If
  
    COMOpen = 1
End Function

Private Sub GSlider1_Click()

End Sub

Private Sub HScroll1_Change()
                                                        'Using HScroll1 to control the output of 7021
Label14.Caption = HScroll1.Value * 0.1
End Sub

Private Sub Timer1_Timer()
                                    'Enable TIMER
    Dim Ret As Integer
    Dim NewDigitalIn As Integer
    If COMOpen = 0 Then
        OpenCom
    End If
                                    'Using 7021 to simulate analogin source
    w7000(0) = Port
    w7000(1) = Val("&H" & Text1.Text)
    w7000(2) = Val("&H7021")
    w7000(3) = CheckSum
    w7000(4) = 100
    w7000(5) = 0
    w7000(6) = 0
    f7000(0) = HScroll1.Value * 0.1
    
    Ret = AnalogOut(w7000(0), f7000(0), SendTo7000, ReceiveFrom7000)
    
   
    Debug.Print "Ret value:"; Ret
    
    If Ret > 0 Then
         MsgBox "AnalogOut() Error !", vbCritical, "Error Code:" + Str(Ret)
         Close_Com (Port)
    End If
                                                'Read the analogin value of 7012
    w7000(0) = Port                             ' COM Port
    w7000(1) = Val("&H" & txtAddress.Text)      ' Module Address
    w7000(2) = Val("&H" & cmbModuleID.Text)     ' Module Type
    w7000(3) = CheckSum                         ' Checksum
    w7000(4) = 100                              ' TimeOut = 0.1 second
    w7000(5) = 0                                ' Low Alarm Value
    w7000(6) = 0                                ' string debug
    Ret = AnalogIn(w7000(0), f7000(0), SendTo7000, ReceiveFrom7000)
            If Ret > 0 Then
                MsgBox "AnalogIn() Error !", vbCritical, "Error Code:" + Str(Ret)
            Else
               txtAnalogInput.Text = Format(f7000(0), "00.000")
            End If
                                                '---- Checking "ThermocoupleOpen_7011" of  7011 has been enable
        If (w7000(2) Or &H3000) = &H7011 Then
            Ret = ThermocoupleOpen_7011(w7000(0), f7000(0), SendTo7000, ReceiveFrom7000)
            If w7000(5) Then
                txtAnalogInput.FontSize = 10
                txtAnalogInput.Text = "7011 T/C Open !!!"
            End If
        End If
    fReadOutputAlarmState                'Read OutputAlarmState function
    
                                         'Read Even Counter
    Ret = ReadEventCounter(w7000(0), f7000(0), SendTo7000, ReceiveFrom7000)
    
    Debug.Print "RET ="; Ret
    Debug.Print "W7000(7) ="; w7000(7)
                                        
    If Ret > 0 Then
         MsgBox "ReadEventCounter() Error !", vbCritical, "Error Code:" + Str(Ret)
    End If
    
    txtEventCounter.Text = MakeDWord(0, w7000(7))
    
    '************ Digital In ***************
    Ret = DigitalIn(w7000(0), f7000(0), SendTo7000, ReceiveFrom7000)
    If Ret > 0 Then
          MsgBox "DigitalIn() Error !", vbCritical, "Error Code:" + Str(Ret)
    End If
    NewDigitalIn = w7000(5)
    If NewDigitalIn Then
        imgDigitalIn.Picture = LoadPicture(App.Path + "\on2.ico")
        Label7.Caption = "DI:0 ON"
    Else
        imgDigitalIn.Picture = LoadPicture(App.Path + "\off2.ico")
        Label7.Caption = "DI:0 OFF"
    End If
End Sub

