VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Demo : Enable/Disable Alarm"
   ClientHeight    =   5805
   ClientLeft      =   135
   ClientTop       =   1545
   ClientWidth     =   8040
   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     =   5805
   ScaleWidth      =   8040
   Begin VB.Frame Frame11 
      Caption         =   "Alarm Status:"
      ForeColor       =   &H00FF0000&
      Height          =   1128
      Left            =   132
      TabIndex        =   55
      Top             =   3288
      Width           =   3276
      Begin VB.Label lblAlarmStatus 
         Caption         =   "CH:1 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          =   156
         Index           =   1
         Left            =   1524
         TabIndex        =   57
         Top             =   384
         Width           =   1692
      End
      Begin VB.Label lblAlarmStatus 
         Caption         =   "CH:0 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          =   156
         Index           =   0
         Left            =   96
         TabIndex        =   56
         Top             =   360
         Width           =   1356
      End
      Begin VB.Image imgAlarm 
         Height          =   408
         Index           =   1
         Left            =   1872
         Top             =   600
         Width           =   540
      End
      Begin VB.Image imgAlarm 
         Height          =   408
         Index           =   0
         Left            =   288
         Top             =   588
         Width           =   540
      End
   End
   Begin VB.Frame fmeCounterSetting 
      Caption         =   "Counter Setting: "
      ForeColor       =   &H00FF0000&
      Height          =   2232
      Left            =   3624
      TabIndex        =   38
      Top             =   732
      Width           =   4128
      Begin VB.Frame Frame9 
         BackColor       =   &H0080FFFF&
         Caption         =   "Counter 1: "
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H000000FF&
         Height          =   1884
         Left            =   2148
         TabIndex        =   40
         Top             =   228
         Width           =   1896
         Begin VB.CommandButton cmdClearCount1 
            Caption         =   "Clearing Count"
            Height          =   432
            Left            =   108
            TabIndex        =   54
            Top             =   1320
            Width           =   1656
         End
         Begin VB.Frame Frame15 
            Caption         =   "Signal 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          =   456
            Left            =   96
            TabIndex        =   44
            Top             =   780
            Width           =   1680
            Begin VB.OptionButton opnSignalMode1 
               Caption         =   "Photo"
               BeginProperty Font 
                  Name            =   "MS Sans Serif"
                  Size            =   8.25
                  Charset         =   0
                  Weight          =   400
                  Underline       =   0   'False
                  Italic          =   0   'False
                  Strikethrough   =   0   'False
               EndProperty
               Height          =   240
               Index           =   1
               Left            =   852
               TabIndex        =   52
               Top             =   180
               Width           =   768
            End
            Begin VB.OptionButton opnSignalMode1 
               Caption         =   "TTL"
               BeginProperty Font 
                  Name            =   "MS Sans Serif"
                  Size            =   8.25
                  Charset         =   0
                  Weight          =   400
                  Underline       =   0   'False
                  Italic          =   0   'False
                  Strikethrough   =   0   'False
               EndProperty
               Height          =   240
               Index           =   0
               Left            =   156
               TabIndex        =   51
               Top             =   180
               Value           =   -1  'True
               Width           =   612
            End
         End
         Begin VB.Frame Frame13 
            Caption         =   "Counting: "
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   456
            Left            =   96
            TabIndex        =   43
            Top             =   240
            Width           =   1680
            Begin VB.OptionButton opnCounting1 
               Caption         =   "No"
               BeginProperty Font 
                  Name            =   "MS Sans Serif"
                  Size            =   8.25
                  Charset         =   0
                  Weight          =   400
                  Underline       =   0   'False
                  Italic          =   0   'False
                  Strikethrough   =   0   'False
               EndProperty
               Height          =   240
               Index           =   1
               Left            =   840
               TabIndex        =   50
               Top             =   168
               Width           =   660
            End
            Begin VB.OptionButton opnCounting1 
               Caption         =   "Yes"
               BeginProperty Font 
                  Name            =   "MS Sans Serif"
                  Size            =   8.25
                  Charset         =   0
                  Weight          =   400
                  Underline       =   0   'False
                  Italic          =   0   'False
                  Strikethrough   =   0   'False
               EndProperty
               Height          =   240
               Index           =   0
               Left            =   120
               TabIndex        =   49
               Top             =   180
               Value           =   -1  'True
               Width           =   576
            End
         End
      End
      Begin VB.Frame Frame8 
         BackColor       =   &H0080FFFF&
         Caption         =   "Counter 0: "
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H000000FF&
         Height          =   1872
         Left            =   144
         TabIndex        =   39
         Top             =   240
         Width           =   1872
         Begin VB.CommandButton cmdClear0 
            Caption         =   "Clearing Count"
            Height          =   432
            Left            =   120
            TabIndex        =   53
            Top             =   1320
            Width           =   1656
         End
         Begin VB.Frame Frame12 
            Caption         =   "Signal 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          =   456
            Left            =   108
            TabIndex        =   42
            Top             =   780
            Width           =   1680
            Begin VB.OptionButton opnSignalMode0 
               Caption         =   "Photo"
               BeginProperty Font 
                  Name            =   "MS Sans Serif"
                  Size            =   8.25
                  Charset         =   0
                  Weight          =   400
                  Underline       =   0   'False
                  Italic          =   0   'False
                  Strikethrough   =   0   'False
               EndProperty
               Height          =   240
               Index           =   1
               Left            =   840
               TabIndex        =   48
               Top             =   180
               Width           =   768
            End
            Begin VB.OptionButton opnSignalMode0 
               Caption         =   "TTL"
               BeginProperty Font 
                  Name            =   "MS Sans Serif"
                  Size            =   8.25
                  Charset         =   0
                  Weight          =   400
                  Underline       =   0   'False
                  Italic          =   0   'False
                  Strikethrough   =   0   'False
               EndProperty
               Height          =   240
               Index           =   0
               Left            =   168
               TabIndex        =   47
               Top             =   192
               Value           =   -1  'True
               Width           =   648
            End
         End
         Begin VB.Frame Frame10 
            Caption         =   "Counting: "
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   480
            Left            =   108
            TabIndex        =   41
            Top             =   228
            Width           =   1680
            Begin VB.OptionButton opnCounting0 
               Caption         =   "No"
               BeginProperty Font 
                  Name            =   "MS Sans Serif"
                  Size            =   8.25
                  Charset         =   0
                  Weight          =   400
                  Underline       =   0   'False
                  Italic          =   0   'False
                  Strikethrough   =   0   'False
               EndProperty
               Height          =   240
               Index           =   1
               Left            =   840
               TabIndex        =   46
               Top             =   192
               Width           =   648
            End
            Begin VB.OptionButton opnCounting0 
               Caption         =   "Yes"
               BeginProperty Font 
                  Name            =   "MS Sans Serif"
                  Size            =   8.25
                  Charset         =   0
                  Weight          =   400
                  Underline       =   0   'False
                  Italic          =   0   'False
                  Strikethrough   =   0   'False
               EndProperty
               Height          =   240
               Index           =   0
               Left            =   108
               TabIndex        =   45
               Top             =   192
               Value           =   -1  'True
               Width           =   600
            End
         End
      End
   End
   Begin VB.Frame fmeAlarmSetting 
      Caption         =   "Alarm Setting: "
      ForeColor       =   &H00FF0000&
      Height          =   2700
      Left            =   3612
      TabIndex        =   19
      Top             =   3012
      Width           =   4140
      Begin VB.Frame Frame4 
         BackColor       =   &H00C0C0C0&
         Caption         =   "Alarm Mode: "
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H000000FF&
         Height          =   492
         Left            =   108
         TabIndex        =   31
         Top             =   264
         Width           =   1995
         Begin VB.OptionButton opnAlarmMode 
            Caption         =   "7080"
            Height          =   252
            Index           =   0
            Left            =   72
            TabIndex        =   33
            Top             =   192
            Value           =   -1  'True
            Width           =   756
         End
         Begin VB.OptionButton opnAlarmMode 
            Caption         =   "7080D"
            Height          =   252
            Index           =   1
            Left            =   924
            TabIndex        =   32
            Top             =   192
            Width           =   975
         End
      End
      Begin VB.CommandButton cmdSetting 
         Caption         =   "&Setting"
         Height          =   492
         Left            =   2424
         TabIndex        =   30
         Top             =   264
         Width           =   1212
      End
      Begin VB.Frame Frame6 
         Caption         =   "Counter 1: "
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H000000FF&
         Height          =   1692
         Left            =   2160
         TabIndex        =   21
         Top             =   840
         Width           =   1812
         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            =   120
            TabIndex        =   29
            Text            =   "10000"
            Top             =   1200
            Width           =   1452
         End
         Begin VB.ComboBox cmbAlarmState 
            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
            ItemData        =   "Form1.frx":0000
            Left            =   120
            List            =   "Form1.frx":000A
            TabIndex        =   27
            Text            =   "Disable"
            Top             =   480
            Width           =   1452
         End
         Begin VB.Label lblAlarm1 
            Caption         =   "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          =   252
            Left            =   120
            TabIndex        =   28
            Top             =   960
            Width           =   1572
         End
         Begin VB.Label Label6 
            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          =   252
            Left            =   120
            TabIndex        =   26
            Top             =   240
            Width           =   1092
         End
      End
      Begin VB.Frame Frame5 
         Caption         =   "Counter 0: "
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H000000FF&
         Height          =   1692
         Left            =   120
         TabIndex        =   20
         Top             =   840
         Width           =   1812
         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            =   120
            TabIndex        =   25
            Text            =   "10000"
            Top             =   1200
            Width           =   1452
         End
         Begin VB.ComboBox cmbAlarmState 
            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
            ItemData        =   "Form1.frx":001F
            Left            =   132
            List            =   "Form1.frx":0029
            TabIndex        =   23
            Text            =   "Disable"
            Top             =   480
            Width           =   1452
         End
         Begin VB.Label lblAlarm0 
            Caption         =   "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          =   252
            Left            =   120
            TabIndex        =   24
            Top             =   960
            Width           =   1572
         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          =   252
            Left            =   120
            TabIndex        =   22
            Top             =   240
            Width           =   1092
         End
      End
   End
   Begin VB.Frame fmeCounterGateMode 
      Caption         =   "Counter Gate Mode: "
      ForeColor       =   &H00FF0000&
      Height          =   612
      Left            =   156
      TabIndex        =   15
      Top             =   4512
      Width           =   3288
      Begin VB.OptionButton Option1 
         Caption         =   "None"
         Height          =   252
         Index           =   2
         Left            =   2040
         TabIndex        =   18
         Top             =   240
         Value           =   -1  'True
         Width           =   852
      End
      Begin VB.OptionButton Option1 
         Caption         =   "High"
         Height          =   252
         Index           =   1
         Left            =   1092
         TabIndex        =   17
         Top             =   240
         Width           =   732
      End
      Begin VB.OptionButton Option1 
         Caption         =   "Low"
         Height          =   252
         Index           =   0
         Left            =   120
         TabIndex        =   16
         Top             =   240
         Width           =   732
      End
   End
   Begin VB.Frame Frame1 
      Caption         =   " Please Open Firstly "
      ForeColor       =   &H00FF0000&
      Height          =   3252
      Left            =   120
      TabIndex        =   1
      Top             =   0
      Width           =   3252
      Begin VB.ComboBox cmbFreqGateTime 
         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":003E
         Left            =   1680
         List            =   "Form1.frx":0048
         TabIndex        =   14
         Text            =   "0.1 sec."
         Top             =   2160
         Width           =   1452
      End
      Begin VB.CommandButton cmdOpen 
         BackColor       =   &H000000FF&
         Caption         =   "&Open Firstly"
         Default         =   -1  'True
         Height          =   492
         Left            =   960
         TabIndex        =   12
         Top             =   2640
         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            =   1680
         TabIndex        =   11
         Text            =   "1"
         Top             =   720
         Width           =   1452
      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":0060
         Left            =   1680
         List            =   "Form1.frx":006A
         TabIndex        =   9
         Text            =   "Disable"
         Top             =   1440
         Width           =   1452
      End
      Begin VB.ComboBox cmbModeSelect 
         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":007F
         Left            =   1680
         List            =   "Form1.frx":0089
         TabIndex        =   7
         Text            =   "Counter Mode"
         Top             =   1800
         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":00A7
         Left            =   1680
         List            =   "Form1.frx":00B7
         TabIndex        =   3
         Text            =   "COM1"
         Top             =   360
         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":00D3
         Left            =   1680
         List            =   "Form1.frx":00EF
         TabIndex        =   2
         Text            =   "9600"
         Top             =   1080
         Width           =   1452
      End
      Begin VB.Label Label7 
         Caption         =   "Freq. Gate Time:"
         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            =   120
         TabIndex        =   13
         Top             =   2160
         Width           =   1452
      End
      Begin VB.Label Label9 
         Caption         =   "Address[dec]:"
         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            =   120
         TabIndex        =   10
         Top             =   720
         Width           =   1332
      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            =   120
         TabIndex        =   8
         Top             =   1440
         Width           =   972
      End
      Begin VB.Label Label5 
         Caption         =   "Mode Select:"
         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            =   120
         TabIndex        =   6
         Top             =   1800
         Width           =   1212
      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          =   252
         Left            =   120
         TabIndex        =   5
         Top             =   360
         Width           =   972
      End
      Begin VB.Label Label4 
         Caption         =   "Baud Rate:"
         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            =   120
         TabIndex        =   4
         Top             =   1080
         Width           =   972
      End
   End
   Begin VB.CommandButton exitCmd 
      Caption         =   "E&xit"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   13.5
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   504
      Left            =   1020
      TabIndex        =   0
      Top             =   5208
      Width           =   1260
   End
   Begin VB.Label Label10 
      Caption         =   "Counter 0:"
      Height          =   252
      Left            =   3636
      TabIndex        =   37
      Top             =   60
      Width           =   1020
   End
   Begin VB.Label Label2 
      Caption         =   "Counter 1:"
      Height          =   252
      Left            =   5928
      TabIndex        =   36
      Top             =   60
      Width           =   972
   End
   Begin VB.Label lblCounter 
      BackColor       =   &H0000FFFF&
      BorderStyle     =   1  'Fixed Single
      Height          =   372
      Index           =   0
      Left            =   3624
      TabIndex        =   35
      Top             =   312
      Width           =   1680
   End
   Begin VB.Label lblCounter 
      BackColor       =   &H0000FFFF&
      BorderStyle     =   1  'Fixed Single
      Height          =   372
      Index           =   1
      Left            =   5916
      TabIndex        =   34
      Top             =   336
      Width           =   1656
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim mPort        As Integer
Dim mBaudrate    As Long
Dim mOldAddress, mNewAddress  As Integer
Dim mOldBaudrate, mNewBaudrate As Long
Dim mOldCheckSum, mNewCHecksum As Integer
Dim mRun7080 As Integer
Dim mDigitalOut(0 To 1) As Integer
Dim Counter As Long

Private Sub cmbChecksum_Change()
    mOldCheckSum = cmbChecksum.ListIndex
    Debug.Print "cmbChecksum_Change()"
End Sub

Private Sub cmbChecksum_Click()
    mOldCheckSum = cmbChecksum.ListIndex
    Debug.Print "cmbChecksum_Click()"
End Sub

'Private Sub cmbModeSelect_Change()
'    If cmbmodeselect.ListIndex = 1 Then
'        cmbfreqgatetime.enable = True
'        Debug.Print "Change Freq enable"
'    Else
'        cmbfreqgatetime.enable = False
'        Debug.Print "Change Freq Disable"
'    End If
'End Sub

Private Sub cmbModeSelect_Click()
    If cmbModeSelect.ListIndex = 1 Then
        cmbFreqGateTime.Enabled = True
        Debug.Print "Freq enable"
    Else
        cmbFreqGateTime.Enabled = False
        Debug.Print "Freq Disable"
    End If

End Sub

Private Sub cmdClear0_Click()
    Dim RetVal%
    
    If COMOpen = 0 Then
        Beep
        MsgBox "Please Open COM firstly !!!", vbCritical
        Exit Sub
    End If
    
        w7000(0) = mPort ' COM Port
        w7000(1) = mOldAddress ' Module Address
        w7000(2) = &H7080
        w7000(3) = mOldCheckSum  ' Checksum
        w7000(4) = 100 ' TimeOut = 0.1 second
        w7000(5) = 0   ' Counter 0
        w7000(6) = 0   ' string debug
        RetVal = ClearCounter_7080(w7000(0), f7000(0), SendTo7000, _
                                        ReceiveFrom7000)
        If RetVal > 0 Then
            Beep
            MsgBox "ClearCounter_7080() Error !", vbCritical, "Error Code:" + Str(RetVal)
            Exit Sub
        End If

End Sub

Private Sub cmdClearCount1_Click()
    Dim RetVal%
    
    If COMOpen = 0 Then
        Beep
        MsgBox "Please Open COM firstly !!!", vbCritical
        Exit Sub
    End If
    
        w7000(0) = mPort ' COM Port
        w7000(1) = mOldAddress ' Module Address
        w7000(2) = &H7080
        w7000(3) = mOldCheckSum  ' Checksum
        w7000(4) = 100 ' TimeOut = 0.1 second
        w7000(5) = 1   ' Counter 1
        w7000(6) = 0   ' string debug
        RetVal = ClearCounter_7080(w7000(0), f7000(0), SendTo7000, _
                                        ReceiveFrom7000)
        If RetVal > 0 Then
            Beep
            MsgBox "ClearCounter_7080() Error !", vbCritical, "Error Code:" + Str(RetVal)
            Exit Sub
        End If

End Sub

Private Sub cmdOpen_Click()
    Dim AA$, NN$, TT$, CC$, FF$, msg$
    Dim NewAddress%, i%
    Dim DataFormat%, ConfigChange%
    Dim RetVal%, wT%, FreqGateTime%
    Dim frm7080Cmd    As String
    Dim frm7080RecBuf As String
    
    '-------- open the COM Port and store some configuration ----
    If COMOpen = 0 Then
        Debug.Print "COM Open ..."
         OpenCom
    End If
    
    '************************************************************
    '----- Now are setting ------
    frm7080Cmd = Space(80)
    frm7080RecBuf = Space(80)
    
    If Val(txtAddress.Text) > 255 Then
        MsgBox "The Module Address > 255, Enter again !", vbCritical, "7017"
    End If
    
    If mOldAddress < 16 Then
        AA$ = "0" + Hex(mOldAddress)
    Else
        AA$ = Hex(mOldAddress)
    End If
    
    NN$ = AA$
    
    Select Case cmbModeSelect.ListIndex
        Case 0
            TT = "50"
        Case 1
            TT = "51"
    End Select
    
    Select Case cmbBaudrate.ListIndex
      Case 0  ' 115200
            CC$ = "0A"
      Case 1  ' 57600
            CC$ = "09"
      Case 2  ' 38400
            CC$ = "08"
      Case 3  ' 19200
            CC$ = "07"
      Case 4  ' 9600
            CC$ = "06"
      Case 5  ' 4800
            CC$ = "05"
      Case 6  ' 2400
            CC$ = "04"
      Case 7  ' 1200
            CC$ = "03"
    End Select
    
    
    If cmbModeSelect.ListIndex = 0 Then  ' Counter Mode
        FreqGateTime = 0
    Else     ' Freq Mode
        FreqGateTime = cmbFreqGateTime.ListIndex
    End If
    DataFormat = 64 * mOldCheckSum + FreqGateTime * 4
    
    If DataFormat < 15 Then
        FF$ = "0" + Hex(DataFormat)
    Else
        FF$ = Hex(DataFormat)
    End If
    
    Debug.Print "AA="; AA$
    Debug.Print "NN="; NN$
    Debug.Print "TT="; TT$
    Debug.Print "CC="; CC$
    Debug.Print "FF="; FF$
    frm7080Cmd = "%" + AA$ + NN$ + TT$ + CC$ + FF$
    Debug.Print "mPort=" + Str(mPort)
    Debug.Print "mOldCheckSum=" + Str(mOldCheckSum)
    Debug.Print "frm7080Cmd="; frm7080Cmd
    
            ConfigChange = 0
            wT = 100
            RetVal = Send_Receive_Cmd(mPort, frm7080Cmd, frm7080RecBuf, 100, mOldCheckSum, wT)
            Sleep (100)
            Debug.Print "frm7080RecBuf->"; frm7080RecBuf
            If RetVal = 0 Then
               If Mid(frm7080RecBuf, 1, 1) = "!" Then
                   If ConfigChange Then
                       msg$ = "Setting Configguration OK !!!" + vbCrLf + _
                            "Please Turn off the power of I-7000 module," + vbCrLf + _
                            "then Turn On again to take effect the setting !!!"
                   Else
                      msg$ = "Setting Configuration OK !!!" + vbCrLf
                   End If
                   Beep
                 
                   MsgBox msg$, vbInformation, "7080"
               End If
            Else
              MsgBox "Error code:" & Str(RetVal), vbCritical, "Send_receive_Cmd()"
              Exit Sub
            End If
    
           '******************************************************
           '------- w7000(5)=0  Setting as 7080 alarm mode -------
           '------- w7000(5)=1  Setting as 7080D alarm mode ------
            w7000(0) = mPort ' COM Port
            w7000(1) = mOldAddress ' Module Address
            w7000(2) = &H7080
            w7000(3) = mOldCheckSum  ' Checksum
            w7000(4) = 100 ' TimeOut = 0.1 second
            w7000(5) = 0 ' setting in 7080 Alarm Mode
            w7000(6) = 0   ' string debug
            RetVal = SetModuleMode_7080(w7000(0), f7000(0), SendTo7000, _
                                                        ReceiveFrom7000)
            If RetVal > 0 Then
                  Beep
                  MsgBox "SetModuleMode_7080() Error !", vbCritical, "Error Code:" + Str(RetVal)
                  Exit Sub
            End If
            '--------- disable Counter 0 Alarm ------------
            w7000(5) = 0
            RetVal = DisableCounterAlarm_7080(w7000(0), f7000(0), SendTo7000, _
                                                    ReceiveFrom7000)
            '--------- disable Counter 1 Alarm ------------
            w7000(5) = 1
            RetVal = DisableCounterAlarm_7080(w7000(0), f7000(0), SendTo7000, _
                                                    ReceiveFrom7000)
            
            '--- Turn off the Digital output firstly ---
            w7000(0) = mPort ' COM Port
            w7000(1) = mOldAddress ' Module Address
            w7000(2) = &H7080
            w7000(3) = mOldCheckSum ' Checksum
            w7000(4) = 100 ' TimeOut = 0.1 second
            w7000(5) = mDigitalOut(1) * 2 + mDigitalOut(0)
            w7000(6) = 0   ' string debug
            RetVal = DigitalOut(w7000(0), f7000(0), SendTo7000, ReceiveFrom7000)
            If RetVal > 0 Then
                MsgBox "DigitalOut_7080() Error !", vbCritical, "Error Code:" + Str(RetVal)
            End If
   
            If cmbModeSelect.ListIndex = 1 Then  ' Frequcncy mode
                fmeCounterSetting.Enabled = False
                fmeAlarmSetting.Enabled = False
                fmeCounterGateMode.Enabled = False
                MsgBox "The Frequcecy mode is selected," + vbCrLf + _
                    "Please change to Counter Mode for alarm demo !", vbInformation
                
            End If
            
            Call ReadingCounter
End Sub

'Private Sub Command1_Click()
'
'    If COMOpen = 0 Then
'        Beep
'        MsgBox "Please Open COM firstly !!!", vbCritical
'        Exit Sub
'    End If
'
'    w7000(0) = mPort        ' COM Port
'    w7000(1) = mOldAddress ' Module Address
'    w7000(2) = &H7080   ' module ID
'    w7000(4) = 100     ' TimeOut = 0.1 second
'
'    w7000(5) = 0       ' channel no
'    w7000(6) = 1       ' string debug
'
'    f7000(0) = Val(analogoutText.Text)
'    Ret = AnalogOut_7080(w7000(0), f7000(0), SendTo7000, ReceiveFrom7000)
'
'    If Ret <> 0 Then
'           Beep
'           A$ = "The Error Code:" + Str$(Ret)
'           MsgBox A$, 0, "AnalogOut_7080() error !!!"
'           Close_Com (Port)
'           End
'    End If
'
'    Counter = Counter + 1
'    A$ = "Counter=" + Str$(Counter)
'    A$ = A$ + "  The Analog Output value:" + Format$(f7000(0), "0.###")
'    Label2.Caption = A$
'    Beep
'End Sub

Private Sub cmdSetting_Click()
    Dim Counter0AlarmValue As Double
    Dim Counter1AlarmValue As Double
    Dim RetVal%, SettingSuccess%, OutStatus%
    Dim SignalMode%
   
    If COMOpen = 0 Then
        Beep
        MsgBox "Please Open COM firstly !!!", vbCritical
        Exit Sub
    End If
   
    If cmbModeSelect.ListIndex = 1 Then  ' frequency mode
        Beep
        MsgBox "Please setting Counter Mode !", vbInformation
        Exit Sub
    End If
    
   
    '**************************************************************
    '--------- Module Alarm mode: ----------------
    '---------- 7080 or 7080D Alarm Mode ---------
    '**************************************************************
    If opnAlarmMode(0).Value Then
        w7000(5) = 0    ' 7080 Alarm Mode
    Else
        w7000(5) = 1    ' 7080D Alarm Mode
    End If
    w7000(0) = mPort ' COM Port
    w7000(1) = mOldAddress ' Module Address
    w7000(2) = &H7080
    w7000(3) = mOldCheckSum  ' Checksum
    w7000(4) = 100 ' TimeOut = 0.1 second
    w7000(6) = 0   ' string debug
    RetVal = SetModuleMode_7080(w7000(0), f7000(0), SendTo7000, _
                                                    ReceiveFrom7000)
                                                    
    Debug.Print "Mode:" + Str(w7000(5))
    If RetVal > 0 Then
        Beep
        MsgBox "SetModuleMode_7080() Error !", vbCritical, "Error Code:" + Str(RetVal)
        Exit Sub
    End If

   
   '***************************************
    Counter0AlarmValue = Val(txtAlarmValue(0).Text)
    Counter1AlarmValue = Val(txtAlarmValue(1).Text)
   '------- Set Counter 0's Alarm Limit Count -----
    w7000(0) = mPort ' COM Port
    w7000(1) = mOldAddress ' Module Address
    w7000(2) = &H7080
    w7000(3) = mOldCheckSum  ' Checksum
    w7000(4) = 100 ' TimeOut = 0.1 second
    w7000(5) = 0   ' Counter 0
    w7000(6) = 0   ' string debug
           
    RetVal = SetAlarmLimitValue_7080(w7000(0), f7000(0), SendTo7000, _
                                        ReceiveFrom7000, Counter0AlarmValue)
    If RetVal > 0 Then
        Beep
        MsgBox "SetAlarmLimitValue_7080() Error !", vbCritical, "Error Code:" + Str(RetVal)
        Exit Sub
    End If
     '------- Set Counter 1's Alarm Limit Count -----
    w7000(5) = 1   ' Counter
          
    RetVal = SetAlarmLimitValue_7080(w7000(0), f7000(0), SendTo7000, _
                                        ReceiveFrom7000, Counter1AlarmValue)
    If RetVal > 0 Then
        Beep
        MsgBox "SetAlarmLimitValue_7080() Error !", vbCritical, "Error Code:" + Str(RetVal)
        Exit Sub
    End If
    
    '**************************************************************
    '--------- Counter Alarm mode: ----------------
    '---------  7080: Disable, Enable -------------
    '---------  7080D: None, Momentary, Latch -----
    '**************************************************************
    If opnAlarmMode(0).Value Then    ' 7080 Alarm Mode
        '--------- Counter 0 ----------------
        w7000(5) = 0
        If cmbAlarmState(0).ListIndex = 0 Then   ' Counter 0 Disable
            RetVal = DisableCounterAlarm_7080(w7000(0), f7000(0), SendTo7000, _
                                                    ReceiveFrom7000)
            If RetVal > 0 Then
                Beep
                MsgBox "DisableCounterAlarm_7080() Error !", vbCritical, "Error Code:" + Str(RetVal)
                Exit Sub
            End If
        Else   '  Counter 0 Enable
             RetVal = EnableCounterAlarm_7080(w7000(0), f7000(0), SendTo7000, _
                                                    ReceiveFrom7000)
            If RetVal > 0 Then
                Beep
                MsgBox "EnableCounterAlarm_7080() Error !", vbCritical, "Error Code:" + Str(RetVal)
                Exit Sub
           End If
       End If
        '--------- Counter 1 ----------------
        w7000(5) = 1
        If cmbAlarmState(1).ListIndex = 0 Then   ' Counter 1 Disable
            RetVal = DisableCounterAlarm_7080(w7000(0), f7000(0), SendTo7000, _
                                                    ReceiveFrom7000)
            If RetVal > 0 Then
                Beep
                MsgBox "DisableCounterAlarm_7080() Error !", vbCritical, "Error Code:" + Str(RetVal)
                Exit Sub
           End If
        Else   '  Counter 1 Enable
             RetVal = EnableCounterAlarm_7080(w7000(0), f7000(0), SendTo7000, _
                                                    ReceiveFrom7000)
            If RetVal > 0 Then
                Beep
                MsgBox "EnableCounterAlarm_7080() Error !", vbCritical, "Error Code:" + Str(RetVal)
                Exit Sub
            End If
       End If
        
    Else    ' 7080D Alarm mode
        Select Case cmbAlarmState(0).ListIndex
            Case 0
                w7000(0) = mPort ' COM Port
                w7000(1) = mOldAddress ' Module Address
                w7000(2) = &H7080
                w7000(3) = mOldCheckSum  ' Checksum
                w7000(4) = 100 ' TimeOut = 0.1 second
                w7000(5) = 1   ' Don't case
                w7000(6) = 0   ' string debug
                RetVal = DisableCounterAlarm_7080D(w7000(0), f7000(0), SendTo7000, _
                                                         ReceiveFrom7000)
                If RetVal > 0 Then
                    Beep
                    MsgBox "DisableCounterAlarm_7080D() Error !", vbCritical, "Error Code:" + Str(RetVal)
                    Exit Sub
                End If
            Case 1, 2
                w7000(0) = mPort ' COM Port
                w7000(1) = mOldAddress ' Module Address
                w7000(2) = &H7080
                w7000(3) = mOldCheckSum  ' Checksum
                w7000(4) = 100 ' TimeOut = 0.1 second
                w7000(5) = cmbAlarmState(0).ListIndex - 1  ' 0: momentary  1:Latch
                w7000(6) = 0   ' string debug
                RetVal = EnableCounterAlarm_7080D(w7000(0), f7000(0), SendTo7000, _
                                                            ReceiveFrom7000)
                If RetVal > 0 Then
                    Beep
                    MsgBox "EnableCounterAlarm_7080D() Error !", vbCritical, "Error Code:" + Str(RetVal)
                    Exit Sub
               End If
        End Select
    End If
    
    If opnAlarmMode(0).Value Then
        lblAlarmStatus(0).Caption = "CH:0 Alarm Off"
        lblAlarmStatus(1).Caption = "CH:1 Alarm Off"
    Else
        lblAlarmStatus(0).Caption = "CH:0 Hi Alarm Off"
        lblAlarmStatus(1).Caption = "CH:1 Hi-Hi Alarm Off"
    End If
    
    Beep
    MsgBox "Setting Successful !!!", vbInformation

End Sub

Private Sub exitCmd_Click()
  Dim Response%
  
  Beep
  Response = MsgBox("Exit this demo?", vbYesNo)
  If Response = vbNo Then
    Exit Sub
  End If
  
  
  mRun7080 = 0
  'Sleep (100)
  
  '------- CLOSE_COM -------------------------
  Close_Com (mPort)
    
  Unload Me
End Sub

Private Sub Form_Load()
    cmbCOMPort.ListIndex = 1
    cmbChecksum.ListIndex = 0
    cmbModeSelect.ListIndex = 0
    cmbBaudrate.ListIndex = 4
    cmbFreqGateTime.ListIndex = 0
    DataBit = 8    ' 8 data bit
    Parity = 0     ' Non Parity
    StopBit = 0    ' One Stop Bit
    COMOpen = 0
    Index = 0
    Counter = 0
    ConfigChange = 0
    
    cmbFreqGateTime.Enabled = False
    
    SendTo7000 = Space(80)
    ReceiveFrom7000 = Space(80)
    
    cmbAlarmState(0).ListIndex = 0
    cmbAlarmState(1).ListIndex = 0
    
    imgAlarm(0).Picture = LoadPicture(App.Path + "\off2.ico")
    imgAlarm(1).Picture = LoadPicture(App.Path + "\off2.ico")
    
   End Sub

Private Sub Form_Unload(Cancel As Integer)
    If COMOpen > 0 Then
        Close_Com (Port)
    End If
End Sub




Public Function OpenCom()
    Dim A$, B$
    Dim i, Response, RetValue As Integer
    Dim Cmd As String
    
    Cmd = Space(80)
    
    A$ = Space(80)
    B$ = Space(80)
    mPort = cmbCOMPort.ListIndex + 1
        
    ' decide the baud rate
    Select Case cmbBaudrate.ListIndex
        Case 0
             mBaudrate = 115200
        Case 1
             mBaudrate = 57600
        Case 2
             mBaudrate = 38400
        Case 3
             mBaudrate = 19200
        Case 4
             mBaudrate = 9600
        Case 5
             mBaudrate = 4800
        Case 6
             mBaudrate = 2400
        Case 7
             mBaudrate = 1200
    End Select
        
      
    RetValue = Open_Com(mPort, mBaudrate, DataBit, Parity, StopBit)
    If RetValue > 0 Then
        Beep
        Response = MsgBox("Quit this demo?", vbYesNo, "OPEN_COM Error Code:" + Str(RetValue))
        If Response = vbYes Then
            Debug.Print "Yes, quit the demo"
            Close_Com (mPort)
            End
        End If
    End If
  
    mOldAddress = Val(txtAddress.Text)
    mOldCheckSum = cmbChecksum.ListIndex
  
    COMOpen = 1
    
End Function

'Private Sub imgDigitalOut_Click(Index As Integer)
'    If COMOpen = 0 Then
'        Beep
'        MsgBox "Please Open COM Port Firstly !!!", vbCritical
'        Exit Sub
'    End If
'
'    mDigitalOut(Index) = 1 - mDigitalOut(Index)
'    If mDigitalOut(Index) Then
'        imgDigitalOut(Index).Picture = LoadPicture(App.Path + "\on2.ico")
'    Else
'        imgDigitalOut(Index).Picture = LoadPicture(App.Path + "\off2.ico")
'    End If
'
'       w7000(0) = mPort ' COM Port
'       w7000(1) = mOldAddress ' Module Address
'       w7000(2) = &H7080
'       w7000(3) = mOldCheckSum ' Checksum
'       w7000(4) = 100 ' TimeOut = 0.1 second
'       w7000(5) = mDigitalOut(1) * 2 + mDigitalOut(0)
'       w7000(6) = 0   ' string debug
'
'       RetVal = DigitalOut(w7000(0), f7000(0), SendTo7000, ReceiveFrom7000)
'       If RetVal > 0 Then
'          'DescribeErrorCode ModuleConfig(gSetupModuleIndex).ModuleType, RetVal
'          MsgBox "DigitalOut() Error !", vbCritical, "Error Code:" + Str(RetVal)
'       End If
'
'
'End Sub

    


Private Sub opnAlarmMode_Click(Index As Integer)
    Select Case Index
        Case 0
            If opnAlarmMode(Index).Value = True Then
                Frame6.Caption = "Counter 1:"
                Label6.Visible = True
                cmbAlarmState(0).Visible = True
                cmbAlarmState(1).Visible = True
                lblAlarm0.Caption = "Alarm Value:"
                lblAlarm1.Caption = "Alarm Value:"
                '--- Setting List item --------
                cmbAlarmState(0).Clear
                cmbAlarmState(0).AddItem "Disable"
                cmbAlarmState(0).AddItem "Enable"
                cmbAlarmState(0).Text = "Disable"
                cmbAlarmState(0).ListIndex = 0
                cmbAlarmState(1).Clear
                cmbAlarmState(1).AddItem "Disable"
                cmbAlarmState(1).AddItem "Enable"
                cmbAlarmState(1).Text = "Disable"
                cmbAlarmState(1).ListIndex = 0
            End If
        Case 1
            If opnAlarmMode(Index).Value = True Then
                Frame6.Caption = "Counter 0:"
                Label6.Visible = False
                cmbAlarmState(Index).Visible = False
                lblAlarm0.Caption = "Hi Alarm Value:"
                lblAlarm1.Caption = "Hi-Hi Alarm Value:"
                '--- Setting List item --------
                cmbAlarmState(0).Clear
                cmbAlarmState(0).AddItem "Disable"
                cmbAlarmState(0).AddItem "Momentary"
                cmbAlarmState(0).AddItem "Latch"
                cmbAlarmState(0).Text = "Disable"
                cmbAlarmState(0).ListIndex = 0
            End If
    End Select
End Sub


'Private Sub opnClearCount0_Click(Index As Integer)
'    Dim RetVal%
'
'    If COMOpen = 0 Then
'        Beep
'        MsgBox "Please Open COM firstly !!!", vbCritical
'        Exit Sub
'    End If
'
'    If opnClearCount0(0).Value Then
'        w7000(0) = mPort ' COM Port
'        w7000(1) = mOldAddress ' Module Address
'        w7000(2) = &H7080
'        w7000(3) = mOldCheckSum  ' Checksum
'        w7000(4) = 100 ' TimeOut = 0.1 second
'        w7000(5) = 0   ' Counter 0
'        w7000(6) = 0   ' string debug
'        RetVal = ClearCounter_7080(w7000(0), f7000(0), SendTo7000, _
'                                        ReceiveFrom7000)
'        If RetVal > 0 Then
'            Beep
'            MsgBox "ClearCounter_7080() Error !", vbCritical, "Error Code:" + Str(RetVal)
'            Exit Sub
'        End If
'    End If
'End Sub


Private Sub opnCounting0_Click(Index As Integer)
        Dim Counting%, RetVal
        
    If COMOpen = 0 Then
        Beep
        MsgBox "Please Open COM firstly !!!", vbCritical
        Exit Sub
    End If
        
        If opnCounting0(0).Value Then
            Counting = 1
        Else
            Counting = 0
        End If

        w7000(0) = mPort ' COM Port
        w7000(1) = mOldAddress ' Module Address
        w7000(2) = &H7080
        w7000(3) = mOldCheckSum  ' Checksum
        w7000(4) = 100 ' TimeOut = 0.1 second
        w7000(5) = 0   ' Counter 0
        w7000(6) = 0   ' string debug
        w7000(7) = Counting   ' 1: Counting    0: Stop Counting
        
        RetVal = StartCounting_7080(w7000(0), f7000(0), SendTo7000, _
                                         ReceiveFrom7000)
        If RetVal > 0 Then
            Beep
            MsgBox "StartCounting_7080() Error !", vbCritical, "Error Code:" + Str(RetVal)
            Exit Sub
        End If
End Sub

Private Sub opnCounting1_Click(Index As Integer)
        Dim Counting%, RetVal
        
    If COMOpen = 0 Then
        Beep
        MsgBox "Please Open COM firstly !!!", vbCritical
        Exit Sub
    End If
        
        If opnCounting1(0).Value Then
            Counting = 1
        Else
            Counting = 0
        End If

        w7000(0) = mPort ' COM Port
        w7000(1) = mOldAddress ' Module Address
        w7000(2) = &H7080
        w7000(3) = mOldCheckSum  ' Checksum
        w7000(4) = 100 ' TimeOut = 0.1 second
        w7000(5) = 1   ' Counter 1
        w7000(6) = 0   ' string debug
        w7000(7) = Counting   ' 1: Counting    0: Stop Counting
        
        RetVal = StartCounting_7080(w7000(0), f7000(0), SendTo7000, _
                                         ReceiveFrom7000)
        If RetVal > 0 Then
            Beep
            MsgBox "StartCounting_7080() Error !", vbCritical, "Error Code:" + Str(RetVal)
            Exit Sub
        End If

End Sub

Private Sub opnSignalMode0_Click(Index As Integer)
    Dim RetVal%, SignalMode%, SettingSuccess%
    
    If COMOpen = 0 Then
        Beep
        MsgBox "Please Open COM firstly !!!", vbCritical
        Exit Sub
    End If
    
    '********************************************************
    '***** setting Counter 0 and 1 signal mode *****
    If (opnSignalMode0(0).Value = True) And (opnSignalMode1(0).Value = True) Then
        SignalMode = 0
    ElseIf (opnSignalMode0(0).Value = False) And (opnSignalMode1(0).Value = False) Then
        SignalMode = 1
    ElseIf (opnSignalMode0(0).Value = True) And (opnSignalMode1(0).Value = False) Then
        SignalMode = 2
    ElseIf (opnSignalMode0(0).Value = False) And (opnSignalMode1(0).Value = True) Then
        SignalMode = 3
    End If
    
    Debug.Print "SignalMode:" + Str(SignalMode)
    
    w7000(0) = mPort ' COM Port
    w7000(1) = mOldAddress ' Module Address
    w7000(2) = &H7080
    w7000(3) = mOldCheckSum  ' Checksum
    w7000(4) = 100 ' TimeOut = 0.1 second
    w7000(5) = SignalMode  ' counter 0 and 1 signal mode
    w7000(6) = 0   ' string debug
    RetVal = SetInputSignalMode_7080(w7000(0), f7000(0), SendTo7000, _
                                         ReceiveFrom7000)

    If RetVal > 0 Then
        Beep
        MsgBox "SetInputSignalMode_7080() Error !", vbCritical, "Error Code:" + Str(RetVal)
        Exit Sub
    End If
End Sub

Private Sub opnSignalMode1_Click(Index As Integer)
    Dim RetVal%, SignalMode%, SettingSuccess%
    
    If COMOpen = 0 Then
        Beep
        MsgBox "Please Open COM firstly !!!", vbCritical
        Exit Sub
    End If
    
    '********************************************************
    '***** setting Counter 0 and 1 signal mode *****
    If (opnSignalMode0(0).Value = True) And (opnSignalMode1(0).Value = True) Then
        SignalMode = 0
    ElseIf (opnSignalMode0(0).Value = False) And (opnSignalMode1(0).Value = False) Then
        SignalMode = 1
    ElseIf (opnSignalMode0(0).Value = True) And (opnSignalMode1(0).Value = False) Then
        SignalMode = 2
    ElseIf (opnSignalMode0(0).Value = False) And (opnSignalMode1(0).Value = True) Then
        SignalMode = 3
    End If
    
    Debug.Print "SignalMode:" + Str(SignalMode)
    
    w7000(0) = mPort ' COM Port
    w7000(1) = mOldAddress ' Module Address
    w7000(2) = &H7080
    w7000(3) = mOldCheckSum  ' Checksum
    w7000(4) = 100 ' TimeOut = 0.1 second
    w7000(5) = SignalMode  ' counter 0 and 1 signal mode
    w7000(6) = 0   ' string debug
    RetVal = SetInputSignalMode_7080(w7000(0), f7000(0), SendTo7000, _
                                         ReceiveFrom7000)

    If RetVal > 0 Then
        Beep
        MsgBox "SetInputSignalMode_7080() Error !", vbCritical, "Error Code:" + Str(RetVal)
        Exit Sub
    End If
End Sub

Private Sub Option1_Click(Index As Integer)
    Dim RetVal%
    
    If COMOpen = 0 Then
        Beep
        MsgBox "Please Open COM Port Firstly !!!", vbCritical
        Exit Sub
    End If
    
       '************************************************************
       '---------  setting the gate mode  -----------------------
       w7000(0) = mPort ' COM Port
       w7000(1) = mOldAddress ' Module Address
       w7000(2) = &H7080
       w7000(3) = mOldCheckSum ' Checksum
       w7000(4) = 100 ' TimeOut = 0.1 second
       w7000(5) = Index  '0:Low  1:High  2:None
       w7000(6) = 0   ' string debug
       RetVal = SetGateMode_7080(w7000(0), f7000(0), SendTo7000, ReceiveFrom7000)
       If RetVal > 0 Then
            Beep
            MsgBox "SetGateMode_7080() Error !", vbCritical, "Error Code:" + Str(RetVal)
            Exit Sub
       End If

End Sub


Public Sub ReadingCounter()
    Dim length As Integer
    Dim A$
    Dim CounterValue0 As Long
    Dim CounterValue1 As Long
    Dim RetVal%
    Dim OldAlarmStatus%, NewAlarmStatus%
  
    If COMOpen = 0 Then
        Beep
        MsgBox "Please Open COM Port Firstly !!!", vbCritical
        Exit Sub
    End If
    
    mRun7080 = 1
    OldAlarmStatus = 0
    While mRun7080
       '************************************************************
       '---------  read 7080 Counter/Freq 0  -----------------------
       w7000(0) = mPort ' COM Port
       w7000(1) = mOldAddress ' Module Address
       w7000(2) = &H7080
       w7000(3) = mOldCheckSum ' Checksum
       w7000(4) = 100 ' TimeOut = 0.1 second
       w7000(5) = 0   ' Counter 0
       w7000(6) = 0   ' string debug
           
       RetVal = CounterIn_7080(w7000(0), f7000(0), SendTo7000, ReceiveFrom7000)
       If RetVal > 0 Then
          'DescribeErrorCode ModuleConfig(gSetupModuleIndex).ModuleType, RetVal
       Else
          CounterValue0 = MakeDWord(w7000(7), w7000(8))
          lblCounter(0).Caption = CounterValue0
       End If
       
       '--------- read 7080 Counter/Freq 1 -------
       w7000(5) = 1
       RetVal = CounterIn_7080(w7000(0), f7000(0), SendTo7000, ReceiveFrom7000)
       If RetVal > 0 Then
            Beep
            MsgBox "CounterIn_7080() Error !", vbCritical, "Error Code:" + Str(RetVal)
            Exit Sub
       Else
          CounterValue1 = MakeDWord(w7000(7), w7000(8))
          lblCounter(1).Caption = CounterValue1
       End If
       
       '***********************************************
       '--------- Reading Alarm Status ----------------
       w7000(0) = mPort ' COM Port
       w7000(1) = mOldAddress ' Module Address
       w7000(2) = &H7080
       w7000(3) = mOldCheckSum  ' Checksum
       w7000(4) = 100 ' TimeOut = 0.1 second
       w7000(5) = 0   ' Don't Care
       w7000(6) = 0   ' string debug
       RetVal = ReadOutputAlarmState_7080(w7000(0), f7000(0), SendTo7000, _
                                                         ReceiveFrom7000)
       If RetVal > 0 Then
            Beep
            MsgBox "ReadOutputAlarmState_7080() Error !", vbCritical, "Error Code:" + Str(RetVal)
            Exit Sub
       End If
       NewAlarmStatus = w7000(8)
       If NewAlarmStatus <> OldAlarmStatus Then
            Select Case NewAlarmStatus
                Case 0
                    imgAlarm(0).Picture = LoadPicture(App.Path + "\off2.ico")
                    imgAlarm(1).Picture = LoadPicture(App.Path + "\off2.ico")
                    If opnAlarmMode(0).Value Then   ' 7080 Alarm Mode
                        lblAlarmStatus(0).Caption = "CH:0 Alarm Off"
                        lblAlarmStatus(1).Caption = "CH:1 Alarm Off"
                    Else                            ' 7080D Alarm Mode
                        lblAlarmStatus(0).Caption = "CH:0 Hi Alarm Off"
                        lblAlarmStatus(1).Caption = "CH:0 Hi-Hi Alarm Off"
                    End If
                Case 1
                    imgAlarm(0).Picture = LoadPicture(App.Path + "\on2.ico")
                    imgAlarm(1).Picture = LoadPicture(App.Path + "\off2.ico")
                    If opnAlarmMode(0).Value Then   ' 7080 Alarm Mode
                        lblAlarmStatus(0).Caption = "CH:0 Alarm On"
                        lblAlarmStatus(1).Caption = "CH:1 Alarm Off"
                    Else                            ' 7080D Alarm Mode
                        lblAlarmStatus(0).Caption = "CH:0 Hi Alarm On"
                        lblAlarmStatus(1).Caption = "CH:1 Hi-Hi Alarm Off"
                    End If
               Case 2
                    imgAlarm(0).Picture = LoadPicture(App.Path + "\off2.ico")
                    imgAlarm(1).Picture = LoadPicture(App.Path + "\on2.ico")
                    If opnAlarmMode(0).Value Then   ' 7080 Alarm Mode
                        lblAlarmStatus(0).Caption = "CH:0 Alarm Off"
                        lblAlarmStatus(1).Caption = "CH:1 Alarm On"
                    Else                            ' 7080D Alarm Mode
                        lblAlarmStatus(0).Caption = "CH:0 Hi Alarm"
                        lblAlarmStatus(1).Caption = "CH:1 Hi-Hi Alarm"
                    End If
                Case 3
                    imgAlarm(0).Picture = LoadPicture(App.Path + "\on2.ico")
                    imgAlarm(1).Picture = LoadPicture(App.Path + "\on2.ico")
                    If opnAlarmMode(0).Value Then   ' 7080 Alarm Mode
                        lblAlarmStatus(0).Caption = "CH:0 Alarm On"
                        lblAlarmStatus(1).Caption = "CH:1 Alarm On"
                    Else                            ' 7080D Alarm Mode
                        lblAlarmStatus(0).Caption = "CH:0 Hi Alarm On"
                        lblAlarmStatus(1).Caption = "CH:0 Hi-Hi Alarm On"
                    End If
            End Select
       End If
       OldAlarmStatus = NewAlarmStatus
       
       DoEvents
    Wend

End Sub
