Attribute VB_Name = "Module1"
'定义需要用到的数据结构
Public Type CANETEINFO
    desip(15) As Byte '//目标IP地址
    desport As Integer  '//目标端口号
    blisten As Byte '//工作模式,0表示正常模式,1表示只听模式
End Type  '//存储CANET-E的特定信息

Public Type ZNE100INFO
    baud As Byte
'    /*
'    300,600,1200,2400,4800,9600,19200,38400,57600,115200,230400,576000,1152000
'    对应关系，为0表示300Bps，12表示1152000Bps
'    ZNE-100,ZNE-100T,ZNE-100TI最大支持波特率115200
'    ZNE-200,ZNE-200T最大支持波特率1152000
'    NETCOM-10最大支持波特率230400
'    */
    
    databits As Byte  '//范围05h～08h
    stopbits As Byte  '//01h或02h
    checkbits As Byte  '//00h表示无校验位，01h表示Even，02h表示Odd，3表示Mark，4表示Space
End Type  '///存储ZNE系列模块的串口信息

Public Type DEVINFO
    bmoduletype As Byte
'    //模块型号,0x01-ZNE100,0x02-ZNE-100T,0x04-ZNE-200T,
'    //0x05-NETCOM-10,0x06-ZNE-200,0x08-ZNE-100TI,0x11-CANETE
'
    mname(10) As Byte '//模块名称
    ip(15) As Byte '//IP地址
    mask(15) As Byte '//子网掩码
    gateip(15) As Byte '//网关
    macaddr(17) As Byte '//MAC地址
    
    bstaticip As Byte  '//00h表示静态配置IP地址，01h表示使用DHCP动态获取IP地址
    workport As Long  '//工作端口
    
    
    timeout As Long '//在ZNE-100T,ZNE-200,ZNE-200T,ZNE-100TI,NETCOM-10时有效
    tcptimeout As Long '//在ZNE-100时有效

    '//用于ZNE系列产品
    desip(15) As Byte '//目标IP地址
    desport As Integer '//目标端口号
    workmode As Integer '//工作模式
    '//1-"TCP Server",2-"UDP",3-"TCP Client",4-"Real COM",5-"Group Mode",
    '//6-"TCP Auto"
    
    ZNE100INFO As ZNE100INFO
    CANETEINFO As CANETEINFO
End Type  '//存储设备相关信息


Declare Function ZNET_Init Lib "ZNET100.dll" () As Long
Declare Function ZNET_Uninit Lib "ZNET100.dll" () As Long
Declare Function ZNET_SearchBroadcast Lib "ZNET100.dll" () As Long
Declare Function ZNET_SearchIP Lib "ZNET100.dll" (ByVal szip As String) As Long
Declare Function ZNET_GetDeviceInformation Lib "ZNET100.dll" (ByVal szip As String, ByRef pinfo As DEVINFO) As Long
Declare Function ZNET_Stop Lib "ZNET100.dll" () As Long
Declare Function ZNET_RecDevice Lib "ZNET100.dll" (ByRef pinfo As DEVINFO, ByRef plen As Long) As Long
Declare Function ZNET_ModifyDevice Lib "ZNET100.dll" (ByVal szip As String, ByVal szpwd As String, ByRef pinfo As DEVINFO) As Long
Declare Sub ZNET_ModifyComCfg Lib "ZNET100.dll" (ByVal szip As String, ByRef pinfo As ZNE100INFO)

'//适用于ZNE-100T,ZNET-200,ZNET-200T,NETCOM-10,ZNET-100TI
Declare Function ZNET_ResetDevice Lib "ZNET100.dll" (ByVal szip As String) As Long

'//适用于ZNE-100T,ZNET-200,ZNET-200T,ZNET-100TI
Declare Function ZNET_GetIOStat Lib "ZNET100.dll" (ByVal szip As String, ByVal port As Long, _
                                                    ByRef pdirection As Byte, ByRef pelevel As Byte) As Long
Declare Function ZNET_SetIOStat Lib "ZNET100.dll" (ByVal szip As String, ByVal port As Long, ByVal ctltype As Byte, _
                                                    ByRef pdirection As Byte, ByRef pelevel As Byte) As Long
'//type=0,表示更改输入输出方向状态，elevel忽略
'//type=1,表示更改电平状态，direction忽略
'//type=2,表示全部更改

'//适用于ZNET-200,ZNE-200T,NETCOM-10,ZNE-100T,ZNET-100TI
Declare Function ZNET_ResetDevTCP Lib "ZNET100.dll" (ByVal szip As String, ByVal port As Long) As Long

'//适用于ZNET-200,ZNE-200T,ZNET-100TI
Declare Function ZNET_GetADC Lib "ZNET100.dll" (ByVal szip As String, ByVal port As Long, ByRef padc0 As Integer, ByRef padc1 As Integer) As Long
'padc0和padc1只有低10位有效


Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)



Public Function ConvertBytetoStr(bytearr() As Byte, arrlen As Long) As String
    Dim str As String
    Dim i As Long
    
    str = ""
    For i = 0 To arrlen - 1
        If bytearr(i) = 0 Then
            Exit For
        End If
        str = str + Chr(bytearr(i))
    Next

    ConvertBytetoStr = str
End Function

Public Sub convertstrtobyte(ByVal str As String, bytearr() As Byte)
    Dim i, slen As Long
    slen = Len(str)
    
    For i = 0 To slen - 1
        bytearr(i) = Asc(Mid(str, i + 1, 1))
    Next
    bytearr(slen) = 0
    
End Sub

