VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Demo : Single Channel Analog In for 7017, 7018"
   ClientHeight    =   4305
   ClientLeft      =   2835
   ClientTop       =   2280
   ClientWidth     =   7710
   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     =   4305
   ScaleWidth      =   7710
   Begin VB.TextBox channelText 
      Height          =   360
      Left            =   5640
      TabIndex        =   17
      Text            =   "0"
      Top             =   1920
      Width           =   1812
   End
   Begin VB.Frame Frame1 
      Caption         =   "Setting I-7000 Configuration  "
      BeginProperty Font 
         Name            =   "Courier"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   3012
      Left            =   120
      TabIndex        =   6
      Top             =   1200
      Width           =   4812
      Begin VB.ComboBox typeCombo 
         Height          =   336
         ItemData        =   "Form1.frx":0000
         Left            =   120
         List            =   "Form1.frx":000A
         TabIndex        =   16
         Text            =   "7017"
         Top             =   480
         Width           =   1212
      End
      Begin VB.Frame Frame3 
         Caption         =   "CheckSum"
         Height          =   732
         Left            =   240
         TabIndex        =   12
         Top             =   1920
         Width           =   4332
         Begin VB.OptionButton chksumOption 
            Caption         =   "Disable"
            Height          =   372
            Index           =   1
            Left            =   2640
            TabIndex        =   14
            Top             =   240
            Value           =   -1  'True
            Width           =   1332
         End
         Begin VB.OptionButton chksumOption 
            Caption         =   "Enable"
            Height          =   372
            Index           =   0
            Left            =   240
            TabIndex        =   13
            Top             =   240
            Width           =   1332
         End
      End
      Begin VB.ComboBox comCombo 
         Height          =   336
         ItemData        =   "Form1.frx":001A
         Left            =   1800
         List            =   "Form1.frx":002A
         TabIndex        =   8
         Text            =   "COM1"
         Top             =   480
         Width           =   1332
      End
      Begin VB.ComboBox baudCombo 
         Height          =   336
         ItemData        =   "Form1.frx":0046
         Left            =   3360
         List            =   "Form1.frx":0062
         TabIndex        =   7
         Text            =   "9600"
         Top             =   480
         Width           =   1332
      End
      Begin VB.Label Label9 
         Caption         =   "Type Name:"
         Height          =   372
         Left            =   120
         TabIndex        =   15
         Top             =   240
         Width           =   1332
      End
      Begin VB.Label Label3 
         Caption         =   "COM Port:"
         Height          =   372
         Left            =   1800
         TabIndex        =   10
         Top             =   240
         Width           =   1332
      End
      Begin VB.Label Label4 
         Caption         =   "Baud Rate:"
         Height          =   372
         Left            =   3360
         TabIndex        =   9
         Top             =   240
         Width           =   1212
      End
   End
   Begin VB.TextBox Text1 
      Height          =   372
      Left            =   2520
      TabIndex        =   4
      Top             =   360
      Width           =   1692
   End
   Begin VB.Timer Timer1 
      Enabled         =   0   'False
      Interval        =   1200
      Left            =   5280
      Top             =   360
   End
   Begin VB.TextBox addressText 
      Height          =   360
      Left            =   5640
      TabIndex        =   3
      Text            =   "2"
      Top             =   960
      Width           =   1812
   End
   Begin VB.CommandButton Command1 
      Caption         =   "Analog In"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   612
      Left            =   5640
      TabIndex        =   1
      Top             =   2640
      Width           =   1812
   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          =   612
      Left            =   5640
      TabIndex        =   0
      Top             =   3600
      Width           =   1812
   End
   Begin VB.Label Label1 
      Caption         =   "Channel No:"
      Height          =   252
      Left            =   5640
      TabIndex        =   18
      Top             =   1680
      Width           =   2052
   End
   Begin VB.Label Label8 
      Caption         =   "COM Port:"
      Height          =   372
      Left            =   720
      TabIndex        =   11
      Top             =   3720
      Width           =   1332
   End
   Begin VB.Label Label7 
      Caption         =   "The Analog Input Value:"
      Height          =   252
      Left            =   360
      TabIndex        =   5
      Top             =   360
      Width           =   2172
   End
   Begin VB.Label Label6 
      Caption         =   "Module Address[Hex]:"
      Height          =   252
      Left            =   5640
      TabIndex        =   2
      Top             =   720
      Width           =   2052
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command2_Click()
    Close (Port)
End Sub

Private Sub baudCombo_Click()
    ConfigChange = 1
    If COMOpen > 0 Then
        Close_Com (Port)
    End If
End Sub


Private Sub chksumOption_Click(Index As Integer)
    ConfigChange = 1
    If COMOpen > 0 Then
        Close_Com (Port)
    End If
End Sub


Private Sub comCombo_Click()
    ConfigChange = 1
    If COMOpen > 0 Then
        Close_Com (Port)
    End If

End Sub


Private Sub Command1_Click()
    
      
    SendTo7000 = Space(100)
    ReceiveFrom7000 = Space(100)
    
    If COMOpen = 0 Or ConfigChange > 0 Then
        OpenCom
    End If
      
    'Debug.Print "------------------------------------"
    'Debug.Print "Port=" & Str(Port)
      
      
    w7000(0) = comCombo.ListIndex + 1 ' COM Port
    
    w7000(1) = Val("&H" & addressText.Text) ' Module Address
    Select Case typeCombo.ListIndex   ' Module ID
       Case 0
           w7000(2) = &H7017
       Case 1
           w7000(2) = &H7018
    End Select
    
    If chksumOption(0).Value Then
        w7000(3) = 1       ' CheckSum Enable
    Else
        w7000(3) = 0
    End If
    
    w7000(4) = 100     ' TimeOut = 0.1 second
 
    w7000(5) = Val(channelText.Text)   ' channel no
    w7000(6) = 1       ' string debug
    
    Ret = AnalogIn(w7000(0), f7000(0), SendTo7000, ReceiveFrom7000)
    
    If Ret <> 0 Then
           Beep
           A$ = "The Error Code:" + Str$(Ret)
           MsgBox A$, 0, "_AnalogIn() error !!!"
           Close_Com (Port)
           End
    End If
     
    If w7000(6) = 1 Then
        Label7.Caption = SendTo7000
        Label8.Caption = ReceiveFrom7000
    End If
    
    Text1.Text = Format$(f7000(0), "0.###")
    
    'Timer1.Enabled = True
  
End Sub

Private Sub exitCmd_Click()
  '------- CLOSE_COM -------------------------
    If COMOpen > 0 Then
        Close_Com (Port)
    End If
    End
End Sub

Private Sub Form_Load()
    typeCombo.ListIndex = 0
    comCombo.ListIndex = 1
    baudCombo.ListIndex = 2
    DataBit = 8    ' 8 data bit
    Parity = 0     ' Non Parity
    StopBit = 0    ' One Stop Bit
    COMOpen = 0
    Index = 0
    ConfigChange = 0
   End Sub

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


Private Sub Timer1_Timer()
   
    If COMOpen = 0 Then
        MsgBox "Please Open COM, firstly", vbOKOnly, "Error Occur !!!"
        Exit Sub
    End If
  
    If COMOpen = 0 Then
        MsgBox "Please Open COM, firstly", vbOKOnly, "Error Occur !!!"
        Exit Sub
    End If
      
      
 
    Ret = AnalogIn(w7000(0), f7000(0), SendTo7000, ReceiveFrom7000)
    
    If Ret <> 0 Then
           Beep
           A$ = "The Error Code:" + Str$(Ret)
           MsgBox A$, 0, "_AnalogIn() error !!!"
           End
    End If
    
 
    Text1.Text = Format$(f7000(0), "0.###")
     

   
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)
    ' decide the COM Port
    Port = comCombo.ListIndex + 1
        
    ' decide the baud rate
    Select Case baudCombo.ListIndex
        Case 0
             BaudRate = 115200
        Case 1
             BaudRate = 57600
        Case 2
             BaudRate = 38400
        Case 3
             BaudRate = 19200
        Case 4
             BaudRate = 9600
        Case 5
             BaudRate = 4800
        Case 6
             BaudRate = 2400
        Case 7
             BaudRate = 1200
    End Select
        
      
    RetValue = Open_Com(Port, BaudRate, DataBit, Parity, StopBit)
    If RetValue > 0 Then
        Beep
        Response = MsgBox("Quit this demo?", vbYesNo, "OPEN_COM Error Code:" + Str(RetValue))
        If Response = vbYes Then
             ' Close_Com (Port)
        End
        End If
    End If

    COMOpen = 1
    ConfigChange = 0
End Function

Private Sub typeCombo_Click()
    ConfigChange = 1
    If COMOpen > 0 Then
        Close_Com (Port)
    End If
End Sub


