VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "ZNE-200T操作"
   ClientHeight    =   7530
   ClientLeft      =   2730
   ClientTop       =   2955
   ClientWidth     =   10260
   LinkTopic       =   "Form1"
   ScaleHeight     =   7530
   ScaleWidth      =   10260
   Begin VB.Frame Frame7 
      Caption         =   "ZNE-200T操作"
      Height          =   2055
      Left            =   5160
      TabIndex        =   44
      Top             =   5280
      Width           =   4935
      Begin VB.CommandButton Command10 
         Caption         =   "复位设备(TCP)"
         Height          =   375
         Left            =   1680
         TabIndex        =   54
         Top             =   1320
         Width           =   1575
      End
      Begin VB.CommandButton Command8 
         Caption         =   "获取ADC"
         Height          =   375
         Left            =   3480
         TabIndex        =   53
         Top             =   720
         Width           =   1095
      End
      Begin VB.TextBox Text16 
         Height          =   315
         Left            =   2400
         TabIndex        =   52
         Top             =   720
         Width           =   975
      End
      Begin VB.TextBox Text15 
         Height          =   315
         Left            =   720
         TabIndex        =   50
         Top             =   720
         Width           =   975
      End
      Begin VB.TextBox Text14 
         Height          =   375
         Left            =   3360
         TabIndex        =   48
         Top             =   240
         Width           =   1095
      End
      Begin VB.TextBox Text12 
         Height          =   375
         Left            =   480
         TabIndex        =   46
         Top             =   240
         Width           =   1695
      End
      Begin VB.Label Label20 
         Caption         =   "ADC1："
         Height          =   255
         Left            =   1800
         TabIndex        =   51
         Top             =   840
         Width           =   615
      End
      Begin VB.Label Label19 
         Caption         =   "ADC0："
         Height          =   255
         Left            =   120
         TabIndex        =   49
         Top             =   840
         Width           =   615
      End
      Begin VB.Label Label18 
         Caption         =   "IO控制端口："
         Height          =   255
         Left            =   2280
         TabIndex        =   47
         Top             =   360
         Width           =   1095
      End
      Begin VB.Label Label14 
         Caption         =   "IP："
         Height          =   255
         Left            =   120
         TabIndex        =   45
         Top             =   360
         Width           =   375
      End
   End
   Begin VB.TextBox Text9 
      Height          =   350
      Left            =   8640
      TabIndex        =   34
      Top             =   2760
      Width           =   975
   End
   Begin VB.TextBox Text8 
      Height          =   350
      Left            =   5640
      TabIndex        =   33
      Text            =   "192.168.0.100"
      Top             =   2760
      Width           =   1695
   End
   Begin VB.Frame Frame4 
      Caption         =   "ZNE-100T&&ZNE-200T操作"
      Height          =   2655
      Left            =   5160
      TabIndex        =   30
      Top             =   2520
      Width           =   4935
      Begin VB.Frame Frame6 
         Height          =   735
         Left            =   120
         TabIndex        =   42
         Top             =   1800
         Width           =   4695
         Begin VB.CommandButton Command9 
            Caption         =   "复位设备(UDP)"
            Height          =   375
            Left            =   1440
            TabIndex        =   43
            Top             =   240
            Width           =   1335
         End
      End
      Begin VB.Frame Frame5 
         Height          =   1215
         Left            =   120
         TabIndex        =   35
         Top             =   600
         Width           =   4695
         Begin VB.CommandButton Command7 
            Caption         =   "更改IO状态"
            Height          =   375
            Left            =   2760
            TabIndex        =   41
            Top             =   720
            Width           =   1215
         End
         Begin VB.CommandButton Command5 
            Caption         =   "获取IO状态"
            Height          =   375
            Left            =   840
            TabIndex        =   40
            Top             =   720
            Width           =   1215
         End
         Begin VB.TextBox Text11 
            Height          =   350
            Left            =   3360
            TabIndex        =   39
            Top             =   240
            Width           =   495
         End
         Begin VB.TextBox Text10 
            Height          =   350
            Left            =   1560
            TabIndex        =   37
            Top             =   240
            Width           =   495
         End
         Begin VB.Label Label13 
            Caption         =   "IO电平状态："
            Height          =   255
            Left            =   2280
            TabIndex        =   38
            Top             =   360
            Width           =   1095
         End
         Begin VB.Label Label12 
            Caption         =   "IO输入输出方向："
            Height          =   255
            Left            =   120
            TabIndex        =   36
            Top             =   360
            Width           =   1455
         End
      End
      Begin VB.Label Label17 
         Caption         =   "IO控制端口："
         Height          =   255
         Left            =   2400
         TabIndex        =   32
         Top             =   360
         Width           =   1095
      End
      Begin VB.Label Label16 
         Caption         =   "IP："
         Height          =   255
         Left            =   120
         TabIndex        =   31
         Top             =   360
         Width           =   375
      End
   End
   Begin VB.TextBox Text7 
      Height          =   350
      Left            =   3480
      TabIndex        =   18
      Top             =   2760
      Width           =   1455
   End
   Begin VB.CommandButton Command3 
      Caption         =   "获取设备信息"
      Height          =   375
      Left            =   3120
      TabIndex        =   3
      Top             =   1560
      Width           =   1335
   End
   Begin VB.CommandButton Command2 
      Caption         =   "指定IP搜索"
      Height          =   375
      Left            =   1680
      TabIndex        =   2
      Top             =   1560
      Width           =   1215
   End
   Begin VB.TextBox Text1 
      Height          =   350
      Left            =   2280
      TabIndex        =   1
      Text            =   "192.168.0.100"
      Top             =   720
      Width           =   2055
   End
   Begin VB.CommandButton Command1 
      Caption         =   "广播搜索"
      Height          =   375
      Index           =   0
      Left            =   240
      TabIndex        =   0
      Top             =   1080
      Width           =   975
   End
   Begin VB.Frame Frame1 
      Height          =   2175
      Left            =   1440
      TabIndex        =   4
      Top             =   120
      Width           =   3255
      Begin VB.Label Label2 
         Caption         =   "IP："
         Height          =   255
         Left            =   360
         TabIndex        =   5
         Top             =   720
         Width           =   375
      End
   End
   Begin VB.TextBox Text2 
      Height          =   350
      Left            =   5280
      TabIndex        =   6
      Text            =   "192.168.0.100"
      Top             =   360
      Width           =   1815
   End
   Begin VB.CommandButton Command4 
      Caption         =   "更改"
      Height          =   375
      Left            =   6720
      TabIndex        =   7
      Top             =   1800
      Width           =   1215
   End
   Begin VB.Frame Frame2 
      Height          =   2175
      Left            =   4800
      TabIndex        =   8
      Top             =   120
      Width           =   5175
      Begin VB.TextBox Text5 
         Height          =   350
         Left            =   2160
         TabIndex        =   15
         Top             =   1200
         Width           =   1815
      End
      Begin VB.TextBox Text4 
         Height          =   350
         Left            =   2160
         TabIndex        =   13
         Top             =   720
         Width           =   1815
      End
      Begin VB.TextBox Text3 
         Height          =   350
         Left            =   3480
         TabIndex        =   11
         Top             =   240
         Width           =   1455
      End
      Begin VB.Label Label5 
         Caption         =   "新工作端口："
         Height          =   255
         Left            =   960
         TabIndex        =   14
         Top             =   1320
         Width           =   1095
      End
      Begin VB.Label Label4 
         Caption         =   "更改为：新IP："
         Height          =   255
         Left            =   840
         TabIndex        =   12
         Top             =   840
         Width           =   1335
      End
      Begin VB.Label Label1 
         Caption         =   "IP："
         Height          =   255
         Left            =   140
         TabIndex        =   10
         Top             =   350
         Width           =   375
      End
      Begin VB.Label Label3 
         Caption         =   "验证密码："
         Height          =   255
         Left            =   2520
         TabIndex        =   9
         Top             =   360
         Width           =   975
      End
   End
   Begin VB.TextBox Text6 
      Height          =   350
      Left            =   600
      TabIndex        =   16
      Text            =   "192.168.0.100"
      Top             =   2760
      Width           =   1695
   End
   Begin VB.CommandButton Command6 
      Caption         =   "更改"
      Height          =   375
      Left            =   2040
      TabIndex        =   17
      Top             =   4440
      Width           =   1335
   End
   Begin VB.Frame Frame3 
      Caption         =   "ZNE-100 && ZNE-100T&&ZNE-200T&&NETCOM-10S 操作"
      Height          =   2655
      Left            =   120
      TabIndex        =   19
      Top             =   2520
      Width           =   4935
      Begin VB.ComboBox Combo4 
         Height          =   315
         ItemData        =   "Form1.frx":0000
         Left            =   3480
         List            =   "Form1.frx":0013
         Style           =   2  'Dropdown List
         TabIndex        =   29
         Top             =   1200
         Width           =   1215
      End
      Begin VB.ComboBox Combo3 
         Height          =   315
         ItemData        =   "Form1.frx":003D
         Left            =   1200
         List            =   "Form1.frx":0047
         Style           =   2  'Dropdown List
         TabIndex        =   27
         Top             =   1200
         Width           =   1215
      End
      Begin VB.ComboBox Combo2 
         Height          =   315
         ItemData        =   "Form1.frx":0051
         Left            =   3480
         List            =   "Form1.frx":0061
         Style           =   2  'Dropdown List
         TabIndex        =   25
         Top             =   720
         Width           =   1215
      End
      Begin VB.ComboBox Combo1 
         Height          =   315
         ItemData        =   "Form1.frx":0071
         Left            =   1200
         List            =   "Form1.frx":0093
         Style           =   2  'Dropdown List
         TabIndex        =   23
         Top             =   720
         Width           =   1215
      End
      Begin VB.Label Label11 
         Caption         =   "校验位："
         Height          =   255
         Left            =   2640
         TabIndex        =   28
         Top             =   1320
         Width           =   735
      End
      Begin VB.Label Label10 
         Caption         =   "停止位："
         Height          =   255
         Left            =   360
         TabIndex        =   26
         Top             =   1320
         Width           =   855
      End
      Begin VB.Label Label9 
         Caption         =   "数据位："
         Height          =   255
         Left            =   2640
         TabIndex        =   24
         Top             =   840
         Width           =   735
      End
      Begin VB.Label Label8 
         Caption         =   "波特率："
         Height          =   255
         Left            =   360
         TabIndex        =   22
         Top             =   840
         Width           =   855
      End
      Begin VB.Label Label6 
         Caption         =   "IP："
         Height          =   255
         Left            =   120
         TabIndex        =   21
         Top             =   360
         Width           =   375
      End
      Begin VB.Label Label7 
         Caption         =   "验证密码："
         Height          =   255
         Left            =   2400
         TabIndex        =   20
         Top             =   360
         Width           =   975
      End
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False


Private Sub Command1_Click(Index As Integer)
    Dim count, i As Long
    Dim info(50) As DEVINFO
    Dim slen, getlen As Long
    Dim str, strtmp As String
    
    count = 5
    slen = 50
    str = "搜索到设备:" + vbCrLf
    strtmp = ""

    ZNET_SearchBroadcast '广播搜索
    While count > 0 '搜索超时时间设为5秒
        getlen = ZNET_RecDevice(info(0), slen)
        While getlen > 0
            If getlen > 0 Then '此时表示搜索到设备
                For i = 0 To getlen - 1
                    
                    strtmp = strtmp + "IP:" + _
                        ConvertBytetoStr(info(i).ip, 16) + " " + "MAC:" + _
                        ConvertBytetoStr(info(i).macaddr, 18) + vbCrLf
                Next
            End If
            getlen = ZNET_RecDevice(info(0), slen)
        Wend
        Sleep 1000
        count = count - 1
    Wend
    ZNET_Stop '广播搜索，指定IP搜索操作完后都必须调用此函数来停止
    
    MsgBox strtmp

End Sub

Private Sub Command10_Click()
    Dim strip, strport As String
    strip = Text12.Text
    strport = Text14.Text
    If ZNET_ResetDevTCP(strip, Val(strport)) <> 1 Then
        MsgBox "复位设备失败"
    Else
        MsgBox "复位设备成功"
    End If

End Sub

Private Sub Command2_Click()
    Dim strip, strtmp As String
    Dim count As Long
    Dim info(50) As DEVINFO
    Dim slen, getlen, i As Long
    
    count = 5
    slen = 50
    strtmp = "搜索到设备:" + vbCrLf
    strip = Text1.Text

    ZNET_SearchIP strip  '指定IP搜索
    While count > 0
        getlen = ZNET_RecDevice(info(0), slen)
        While getlen > 0
            For i = 0 To getlen - 1
                If strip = ConvertBytetoStr(info(i).ip, 16) Then
                    strtmp = strtmp + "IP:" + _
                        ConvertBytetoStr(info(i).ip, 16) + " " + "MAC:" + _
                        ConvertBytetoStr(info(i).macaddr, 18) + vbCrLf
                        ZNET_Stop  '广播搜索，指定IP搜索操作完后都必须调用此函数来停止
                        MsgBox strtmp
                        Exit Sub
                End If
            Next
            getlen = ZNET_RecDevice(info(0), slen)
        Wend
        Sleep 1000
        count = count - 1
    Wend
    ZNET_Stop  '广播搜索，指定IP搜索操作完后都必须调用此函数来停止
End Sub

Private Sub Command3_Click()
    Dim strip, strtmp As String
    Dim info As DEVINFO
    strtmp = "设备信息:" + vbCrLf
    strip = Text1.Text

    If ZNET_GetDeviceInformation(strip, info) = 1 Then
        strtmp = strtmp + "设备名称:" + ConvertBytetoStr(info.mname, 11) + vbCrLf
        strtmp = strtmp + "设备IP:" + ConvertBytetoStr(info.ip, 16) + vbCrLf
        strtmp = strtmp + "网关:" + ConvertBytetoStr(info.gateip, 16) + vbCrLf
        strtmp = strtmp + "子网掩码:" + ConvertBytetoStr(info.mask, 16) + vbCrLf
        strtmp = strtmp + "MAC地址:" + ConvertBytetoStr(info.macaddr, 18) + vbCrLf
        strtmp = strtmp + "工作端口:" + str(info.workport) + vbCrLf
        MsgBox strtmp
    End If

End Sub

Private Sub Command4_Click()
    Dim strip, strpwd, strnewip, strtmp As String
    Dim port As Long
    Dim info As DEVINFO
    Dim res As Long
    
    port = Val(Text5.Text)
    strpwd = Text3.Text
    strnewip = Text4.Text
    strip = Text2.Text
    
    If ZNET_GetDeviceInformation(strip, info) = 1 Then
        convertstrtobyte strnewip, info.ip
        info.workport = port
        If ZNET_ModifyDevice(strip, strpwd, info) = 1 Then
            MsgBox "更改成功"
        End If
    End If
End Sub

Private Sub Command5_Click()
    Dim strip, strtmp As String
    Dim dir, elevel As Byte
    Dim port As Long
    
    strip = Text8.Text
    port = Val(Text9.Text)
    
    If ZNET_GetIOStat(strip, port, dir, elevel) = 0 Then
        MsgBox "获取IO口状态失败"
        Exit Sub
    End If
    
    Text10.Text = Hex(dir)
    Text11.Text = Hex(elevel)

End Sub

Private Sub Command6_Click()
    Dim strip, strpwd As String
    Dim info As DEVINFO
    Dim res As Long
    
    strip = Text6.Text
    strpwd = Text7.Text

    If ZNET_GetDeviceInformation(strip, info) = 1 Then
        info.ZNE100INFO.baud = Combo1.ListIndex
        info.ZNE100INFO.checkbits = Combo4.ListIndex
        info.ZNE100INFO.databits = 5 + Combo2.ListIndex
        info.ZNE100INFO.stopbits = 1 + Combo3.ListIndex
        If ZNET_ModifyDevice(strip, strpwd, info) = 1 Then
            MsgBox "更改成功"
        End If
    End If
End Sub

Private Sub Command7_Click()
    Dim strip, strtmp As String
    Dim dir, elevel As Byte
    Dim port As Long
    
    strip = Text8.Text
    port = Val(Text9.Text)
    dir = Val("&H" + Text10.Text)
    elevel = Val("&H" + Text11.Text)

    If ZNET_SetIOStat(strip, port, 2, dir, elevel) = 0 Then
        MsgBox "更改IO口状态失败"
        Exit Sub
    End If

    Text10.Text = Hex(dir)
    Text11.Text = Hex(elevel)
    
End Sub

Private Sub Command8_Click()
    Dim strip, strtmp As String
    Dim adc0, adc1 As Integer
    Dim port As Long
    
    strip = Text12.Text
    port = Val(Text14.Text)
    
    If ZNET_GetADC(strip, port, adc0, adc1) = 0 Then
        MsgBox "获取ADC状态失败"
        Exit Sub
    End If
    
    Text15.Text = Hex(adc0)
    Text16.Text = Hex(adc1)
End Sub

Private Sub Command9_Click()
    Dim strip As String
    strip = Text8.Text
    If ZNET_ResetDevice(strip) <> 1 Then
        MsgBox "复位设备失败"
    End If
End Sub

Private Sub Form_Load()
    ZNET_Init  '初始化连接，一般在程序启动后运行此函数
End Sub

Private Sub Form_Unload(Cancel As Integer)
    ZNET_Uninit '关闭连接，一般在程序退出时调用此函数
End Sub


