VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Demo : General Purpose Demo"
   ClientHeight    =   5655
   ClientLeft      =   1380
   ClientTop       =   1080
   ClientWidth     =   9690
   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     =   5655
   ScaleWidth      =   9690
   Begin VB.CommandButton Command2 
      Caption         =   "Send Binary"
      Height          =   570
      Left            =   5715
      TabIndex        =   27
      Top             =   4755
      Width           =   1905
   End
   Begin VB.CommandButton Command1 
      Caption         =   "Timer"
      Height          =   615
      Left            =   6240
      TabIndex        =   26
      Top             =   600
      Width           =   735
   End
   Begin VB.Timer Timer1 
      Enabled         =   0   'False
      Interval        =   5000
      Left            =   5400
      Top             =   480
   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          =   3612
      Left            =   240
      TabIndex        =   6
      Top             =   1920
      Width           =   5052
      Begin VB.Frame Frame3 
         Caption         =   "CheckSum"
         Height          =   1212
         Left            =   3120
         TabIndex        =   17
         Top             =   240
         Width           =   1692
         Begin VB.OptionButton chksumOption 
            Caption         =   "Off"
            Height          =   372
            Index           =   1
            Left            =   240
            TabIndex        =   22
            Top             =   720
            Value           =   -1  'True
            Width           =   1332
         End
         Begin VB.OptionButton chksumOption 
            Caption         =   "On"
            Height          =   372
            Index           =   0
            Left            =   240
            TabIndex        =   21
            Top             =   360
            Width           =   1332
         End
      End
      Begin VB.ComboBox stopbitCombo 
         Height          =   336
         ItemData        =   "Form1.frx":0000
         Left            =   1680
         List            =   "Form1.frx":000D
         TabIndex        =   16
         Text            =   "1"
         Top             =   2160
         Width           =   1092
      End
      Begin VB.Frame Frame2 
         Caption         =   "Parity"
         Height          =   1572
         Left            =   3120
         TabIndex        =   14
         Top             =   1920
         Width           =   1692
         Begin VB.OptionButton parityOption 
            Caption         =   "Even Parity"
            Height          =   252
            Index           =   2
            Left            =   120
            TabIndex        =   20
            Top             =   1080
            Width           =   1452
         End
         Begin VB.OptionButton parityOption 
            Caption         =   "Odd Parity"
            Height          =   252
            Index           =   1
            Left            =   120
            TabIndex        =   19
            Top             =   720
            Width           =   1452
         End
         Begin VB.OptionButton parityOption 
            Caption         =   "Non Parity"
            Height          =   252
            Index           =   0
            Left            =   120
            TabIndex        =   18
            Top             =   360
            Value           =   -1  'True
            Width           =   1452
         End
      End
      Begin VB.ComboBox databitCombo 
         Height          =   336
         ItemData        =   "Form1.frx":001C
         Left            =   240
         List            =   "Form1.frx":002C
         TabIndex        =   13
         Text            =   "8"
         Top             =   2160
         Width           =   1092
      End
      Begin VB.ComboBox comCombo 
         Height          =   336
         ItemData        =   "Form1.frx":003C
         Left            =   240
         List            =   "Form1.frx":004C
         TabIndex        =   8
         Text            =   "COM1"
         Top             =   480
         Width           =   1212
      End
      Begin VB.ComboBox baudCombo 
         Height          =   336
         ItemData        =   "Form1.frx":0068
         Left            =   1680
         List            =   "Form1.frx":0084
         TabIndex        =   7
         Text            =   "9600"
         Top             =   480
         Width           =   1332
      End
      Begin VB.Label Label10 
         Caption         =   "Stop Bit:"
         Height          =   252
         Left            =   1680
         TabIndex        =   15
         Top             =   1920
         Width           =   972
      End
      Begin VB.Label Label9 
         Caption         =   "Data Bits:"
         Height          =   252
         Left            =   240
         TabIndex        =   12
         Top             =   1920
         Width           =   1332
      End
      Begin VB.Label Label3 
         Caption         =   "COM Port:"
         Height          =   372
         Left            =   240
         TabIndex        =   10
         Top             =   240
         Width           =   1332
      End
      Begin VB.Label Label4 
         Caption         =   "Baud Rate:"
         Height          =   372
         Left            =   1680
         TabIndex        =   9
         Top             =   240
         Width           =   1212
      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          =   612
      Left            =   5700
      TabIndex        =   5
      Top             =   5340
      Width           =   1932
   End
   Begin VB.TextBox receiveText 
      Height          =   372
      Left            =   5640
      TabIndex        =   4
      Top             =   3360
      Width           =   3840
   End
   Begin VB.CommandButton runCmd 
      Caption         =   "&Send Command"
      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            =   5664
      TabIndex        =   2
      Top             =   3972
      Width           =   1932
   End
   Begin VB.TextBox commandText 
      Height          =   372
      Left            =   5640
      TabIndex        =   0
      Text            =   "$02M"
      Top             =   2520
      Width           =   1812
   End
   Begin VB.Label Label6 
      Caption         =   "Counter=0"
      Height          =   252
      Left            =   240
      TabIndex        =   25
      Top             =   600
      Width           =   3252
   End
   Begin VB.Label Label5 
      Caption         =   "Ret="
      Height          =   252
      Left            =   240
      TabIndex        =   24
      Top             =   240
      Width           =   3252
   End
   Begin VB.Label Label11 
      Height          =   492
      Left            =   360
      TabIndex        =   23
      Top             =   1080
      Width           =   3972
   End
   Begin VB.Label Label8 
      Caption         =   "COM Port:"
      Height          =   372
      Left            =   720
      TabIndex        =   11
      Top             =   3720
      Width           =   1332
   End
   Begin VB.Label Label2 
      Caption         =   "Receive String:"
      Height          =   372
      Left            =   5640
      TabIndex        =   3
      Top             =   3120
      Width           =   1812
   End
   Begin VB.Label Label1 
      Caption         =   "Command String:"
      Height          =   252
      Left            =   5640
      TabIndex        =   1
      Top             =   2280
      Width           =   1572
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim iCount As Integer
Private Sub Command2_Click()
Dim ret As Integer
Dim wT As Integer
Dim buf(0 To 10) As Byte
Dim data(0 To 4) As Byte
Dim recStr As String
Dim i As Integer

recStr = ""
data(0) = &H1
data(1) = &H46
data(2) = &H0
data(3) = &H12
data(4) = &H60
ret = Open_Com(2, 9600, 8, 0, 0)
ret = Send_Binary(2, data(0), 5)
ret = Receive_Binary(2, buf(0), 400, 9, wT)
For i = 0 To 8
    recStr = recStr + Right("0" & Hex(buf(i)), 2)
Next i
receiveText = recStr
ret = Close_Com(2)
    
End Sub


Private Sub baudCombo_Change()
    ConfigChange = 1
End Sub

Private Sub chksumOption_Click(Index As Integer)
    ConfigChange = 1
    ToCheckSum = 1 - Index
End Sub

Private Sub comCombo_Click()
    ConfigChange = 1
End Sub


Private Sub Command1_Click()
    Timer1.Enabled = Not Timer1.Enabled
End Sub

Private Sub commandText_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
        KeyAscii = 0
        runCmd_Click
    End If
    
    If KeyAscii > 96 And KeyAscii < 123 Then
        KeyAscii = KeyAscii - 32
    End If

End Sub

Private Sub databitCombo_Change()
    ConfigChange = 1
End Sub

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

Private Sub Form_Load()
    comCombo.ListIndex = 1
    baudCombo.ListIndex = 2
    DataBit = 8    ' 8 data bit
    Parity = 0     ' Non Parity
    StopBit = 0    ' One Stop Bit
    COMOpen = 0
    Index = 0
    Counter = 0
    ConfigChange = 0
    If chksumOption(0).Value Then
        ToCheckSum = 1
    Else
        ToCheckSum = 0
    End If
    
    SendTo7000 = Space(80)
    receivefrom7000 = Space(80)
   End Sub

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



Private Sub parityOption_Click(Index As Integer)
    ConfigChange = 1
End Sub

Private Sub runCmd_Click()
    Dim length As Integer
    Dim A$
    Dim i As Long
    'Dim Cmd As String
    'Dim Buf As String
    Dim ret, status As Integer
    Dim wT As Integer
  
    If COMOpen = 0 Or ConfigChange = 1 Then
         OpenCom
    End If
   
    wT = 100
    SendTo7000 = commandText.Text
    ret = Send_Receive_Cmd(port, SendTo7000, receivefrom7000, 100, ToCheckSum, wT)
   
    If ret > 0 Then
        Beep
        A$ = "The Error Code:" + Str$(ret)
        MsgBox A$, 0, "Send_Receive_Cmd() error !!!"
        End
    End If
   
    
    Counter = Counter + 1
    Label5 = "Ret=" + Str$(ret)
    Label6 = "Counter=" + Str$(Counter)
    
    receiveText.Text = receivefrom7000
    Beep
    '------------------------------------------
   
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
        
    'whether or not to add checksum
    If chksumOption(0).Value Then
        ToCheckSum = 1
    Else
        ToCheckSum = 0
    End If
    
    ' decide the Data Bits
    For i = 0 To 2
        If parityOption(i).Value Then Exit For
    Next i
    Select Case i
        Case 0
             ParityBit = 0
        Case 1
             ParityBit = 1
        Case 2
             ParityBit = 2
    End Select
    
    Select Case databitCombo.ListIndex
        Case 0
             DataBit = 5
        Case 1
             DataBit = 6
        Case 2
             DataBit = 7
        Case 3
             DataBit = 8
    End Select
    
        
    ' decide the Stop Bits
    Select Case databitCombo.ListIndex
        Case 0
             StopBit = 0
        Case 1
             StopBit = 1
        Case 2
             StopBit = 2
    End Select
      
    RetValue = Open_Com(port, BaudRate, DataBit, Parity, StopBit)
    'ret = Open_Com(2, 9600, 8, 0, 0)
    If RetValue > 0 Then
        Beep
        'A$ = "The Error Code:" + Str$(RetValue)
        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 stopbitCombo_Change()
    ConfigChange = 1
End Sub


Private Sub Timer1_Timer()
    Dim A As String

    runCmd_Click
    DoEvents
    'A = ((Mid(commandText.Text, 3, 1) + 1) Mod 4) + 1
    iCount = iCount + 1
    If iCount > 4 Then iCount = 1
    A = iCount
    commandText.Text = Mid(commandText.Text, 1, 2) + A + "M"
End Sub
