本示例设备介绍:IC卡实时在线消费机售饭机食堂打卡机可编程二次开发人脸指纹4G网-淘宝网 (taobao.com)
设备向服务器发送的指令格式,每个字段用半角逗号(,)分隔。 | ||||
序号 | 指令名称 | 指令格式 | 指令说明 | 示例 |
1 | 响应服务器的搜索 | 100,包序列号,终端IP,子网掩码,网关IP,远程电脑主机IP,端口号,终端硬件号 | 响应电脑发出的搜寻局域网内所有终端设备指令000,就是电脑软件用广播式向39190端口发送字符串“000” | 100,00009,192.168.1.218,255.255.255.0,192.168.1.1,192.168.1.3,39169,1234567890 |
2 | 开机信息 | 101,包序列号,终端IP,远程电脑主机IP,机号,时间 | 1、设备开机时向电脑发送的开机信息,电脑可以根据这条信息发送相应的开机提示信息。 2、电脑发送002查询设备时间时,也是响应这条信息。 |
101,00009,192.168.1.1,192.168.1.3,00002,2012-04-20 11:12:13 |
3 | 普通消费模式下刷卡 | 102,包序列号,终端IP,远程电脑主机IP,机号,卡号 | 当设备消费模式不是定额方式或计次方式时,刷卡后设备向电脑发送此信息。 | 102,00009,192.168.1.1,192.168.1.3,00002,8888888888 |
4 | 输入消费金额后刷卡、定额模式下刷卡 | 103,包序列号,终端IP,远程电脑主机IP,机号,卡号,消费额,时间,2 | 1、设备消费模式为普通模式、快捷键模式时,先按金额后刷卡; 2、设备消费模式为定额方式时刷卡; 3、服务器端此时应用008指令回应消费成功或006指令回应消费失败。 |
103,00009,192.168.1.1,192.168.1.3,00002, 8888888888,5.50, 2012-04-20 11:12:13,2 |
5 | 计次刷卡消费 | 104,包序列号,终端IP,远程电脑主机IP,机号,卡号,时间 | 在设备设定为计次消费模式下时,刷卡后直接发送至服务器 | 104,00009,192.168.1.1,192.168.1.3,00002,8888888888,2012-04-20 11:12:13 |
6 | 记帐信息 | 105,包序列号,终端IP,远程电脑主机IP,机号,卡号,消费额,消费时间,状态(0:金额消费 1:计次),记录地址标识,总记录数 | 电脑没回应的情况下,消费信息将先记账,在网络联通后,向服务器发送 | 105,00009,192.168.1.1,192.168.1.3,00002,8888888888,5.50,2012-04-20 11:12:13,1,12345678,18 |
7 | 键盘输入 | 106,包序列号,终端IP,远程电脑主机IP,机号,键盘输入信息 | 向服务器发送键盘指令,操作方法是先按设备【Func】进菜单,选【发送数字指令】,输入数字后,按回车发送 | 106,00009,192.168.1.1,192.168.1.3,00002,11 |
8 | 取餐模式下刷卡 | 108,包序列号,终端IP,远程电脑主机IP,机号,卡号,时间 | 设备设定为取餐模式下时,刷卡后直接发送至服务器 | 108,00009,192.168.1.1,192.168.1.3,00002,8888888888,2012-04-20 11:12:13 |
9 | 响应服务器发过来的显示指令 | 109,包序列号,终端IP,远程电脑主机IP,机号,接收到的指令 | 响应服务器发来的006、008、009、010、103指令,服务器端可通过此指令终止重发机制 | |
响应电脑 | 112,包序列号,终端IP,远程电脑主机IP,机号,返回值 | 返回值: 0表示成功; 1表示广播式发送成功 2表示接收器和读卡器无线通讯失败 |
||
向应服务器查询信息 | 114,包序列号,终端IP,远程电脑主机IP,机号,卡号,查询指令,时间 | |||
响应服务器的015指令 | 115,包序列号,终端IP,远程电脑主机IP,机号,返回值 | |||
10 | 二维码扫描信息 | 125,包序列号,终端IP,远程电脑主机IP,机号,二维码格式标识,二维码信息(可以包含逗号) | 125,00004,192.168.1.228,192.168.1.168,00003,0, http://wwww.baidu.com,abc | |
11 | 输入金额后再扫二维码 | 128,包序列号,终端IP,远程电脑主机IP,机号,口令,消费额,时间,二维码格式标识,二维码信息(可以包含逗号) | 128,00004,192.168.1.228,192.168.1.168,00003,12345,5.50, 2012-04-20 11:12:13,0, http://wwww.baidu.com,abc | |
12 | 门禁机刷卡 | 150,包序列号,终端IP,远程电脑主机IP,机号,卡号,读头号,对应的门或继电器号,门磁未关秒数(0门已关),密码类别(0密码无效/1刷卡后按密码/2补签密码/3防迫胁密码/4开门密码),密码(最多10位数字),时间 | 150,00055,192.168.1.228,192.168.1.168,00001,0305912578,0,0,0,0,00000000,2020-01-01 08:18:18 | |
服务器向设备发送的指令,每个字段用半角逗号(,)分隔。 | ||||
序号 | 指令名称 | 指令格式 | 指令说明 | 示例 |
1 | 搜寻设备 | 000 | 搜寻局域网内所有终端设备指令,终端会向主机回应100指令 | 000 |
2 | 确认信息已收到 | 001,包序列号 | 用于告诉终端,信息已收到,不需要重发3次相同信息了。 | 001,00009 |
3 | 读设备时间 | 002,机号 | 读取终端时间,终端收到这些指令后会回应101指令(请看表1),00000表示任意机号 | 002,00002 |
4 | 改设备时间 | 003,机号,时间 | 设定终端设备时间,终端收到这些指令后会回应101指令 | 003,00002,2012-04-20 11:12:13 |
5 | 更改机备IP地址 | 004,终端IP,子网掩码,网关IP,网送MAC,远程电脑主机IP,远程电脑主机MAC,是否自动搜出MAC,端口号,终端硬件号 | 设定指定的终端IP地址等参数。 是否自动搜出MAC取值说明: 1:为自动搜出远程主机MAC 2:为自动搜出网关的MAC 4:为当设备IP在局域网中有冲突时,自动获取可用的IP(也就是开启DHCP功能) 8:允许保存DHCP自动获取的IP |
004,192.168.1.228,255.255.255.0,192.168.1.1,AA-BB-CC-DD-EE-FF,255.255.255.255, AA-BB-CC-DD-EE-FF,0,39190,0138215662 |
6 | 扣款不成功 | 006,机号,卡号,信息,显示延时(秒),蜂鸣器发声(种类见表3),语音(种类见表4) | 扣款不成功时,服务器向终端发送的显示及声响信息,此信息仅在设备刷卡后显示“正在等待电脑回应..”时有效。 | 006,00002,1234567890,此卡尚未开户\,余额信息不存在,10,0,1 要让设备显示逗号用“\,”表示。 显示换行用“\n”表示。 |
7 | 扣款成功 | 008,机号,卡号,消费额,信息,显示延时(秒),蜂鸣器发声(种类见表3),语音(种类见表4) | 扣款成功时,服务器向终端发送的显示及声响信息,此信息仅在设备刷卡后显示“正在等待电脑回应..”时有效。 | 008,00002,1234567890,5.50,姓名 扣费成功\n余额12256.60元\n,10,1,1 要让设备显示逗号用“\,”表示。 显示换行用“\n”表示。 |
8 | 驱动显示及响声 | 009,机号,信息,显示延时(秒),蜂鸣器发声(种类见表3),语音(种类见表4) | 服务器发送,用于驱动终端设备显示信息及声响。 | 009,00002,显示信息,10,1,1 要让设备显示逗号用“\,”表示。 显示换行用“\n”表示。 |
9 | 清除记帐记录 | 011,机号,卡号,消费额,消费时间,记录地址标识 | 清除一条已经上传的记帐记录,使设备继续上传剩余的记账记录 | 011,00002,8888888888,5.50,2012-04-20 11:12:13,12345678 |
10 | 更改设备的管理员密码 | 012,机号,新密码(必须为6位数字),012-012::012-012(这个固定常量用于防止网络干扰误改) | 更改设备的管理员密码 | 012,00002,123456,012-012::012-012(这个固定常量用于防止网络干扰误改) |
11 | 门禁机开门成功指令 | 050,机号,卡号(号卡为0表示外接按钮),信息,显示延时(秒,为0时不驱动显示,保留门禁机原来的显示不动),蜂鸣器发声(种类见表3),语音(种类见表4),读头号或按钮号,对应的门或继电器号,继电器开关保续时间(20毫秒为一个单位),门磁未关报警秒数 | 开门成功时,电脑向终端发送的显示及声响信息,此信息仅在设备刷卡后显示“正在等待电脑回应..”时有效。 | 050,00002,1234567890,姓名:张三丰 开门成功,20,2,0,0,0,300,0 |
12 | 门禁机禁止开门提示 | 051,机号,卡号(号卡为0表示外接按钮),信息,显示延时(秒,为0时不驱动显示,保留门禁机原来的显示不动),蜂鸣器发声(种类见表3),语音(种类见表4) | 开门不成功时,电脑向终端发送的显示及声响信息,此信息仅在设备刷卡后显示“正在等待电脑回应..”时有效。 | 051,00002,1234567890,姓名:张三丰 禁止通行!,20,6,0 |
本示例所用设备详细介绍:IC卡实时在线消费机售饭机食堂打卡机可编程二次开发人脸指纹4G网-淘宝网 (taobao.com)
Imports System.Net.Sockets
Imports System.Net
Imports System.Text
Imports System.Threading
Imports System.Net.NetworkInformation
Imports System.Management
Public Class Form1
Dim PortNumber As Integer ''侦听端口号
Dim ListenerThre As Thread ''侦听线程
Dim LocalIp As String ''本地ip64
Dim ready As Boolean = False ''线程运行标识
Dim machinnos As String
Dim RemoteIPoint As IPEndPoint
Dim BeepCode As String
Dim VoiceCode As String
Public ListenerSock As Socket ''侦听socket
Public SendBufStr(7950) As String
Public SendPoinMax As Integer
Public SendPoin As Integer
Public SendAgain As Integer
Public SendCount As Boolean
Public sendcode As String
Public RegCard As String
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Delegate Sub EditUi(ByVal data0 As String, ByVal data1 As String) '线程内更新UI传送两个参数
Delegate Sub EditTC(ByVal con As Integer, ByVal data1 As String)
'声明并初始化排序变量
Public _ListViewSorter As ListViewSorter.EnumSortOrder = ListViewSorter.EnumSortOrder.Ascending
Private Sub Form1_Disposed(sender As Object, e As EventArgs) Handles Me.Disposed
End
'ready = False
'ListenerSock.Close()
'ListenerThre.Abort()
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'Control.CheckForIllegalCrossThreadCalls = False '经典解决“线程间操作无效: 从不是创建控件的线程访问它 ,尽量不要用这种方式
getIp()
ComboBox2.SelectedIndex = 0
ComboBox3.SelectedIndex = 1
ComboBox4.SelectedIndex = 16
ComboBox5.SelectedIndex = 1
StartListener() ''开始侦听
End Sub
Private Sub StartListener()
Dim LocalPoint As IPEndPoint
PortNumber = TextBox6.Text
While Not ready
Try
LocalPoint = New IPEndPoint(IPAddress.Parse(LocalIp), PortNumber)
ListenerSock = New Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp)
ListenerSock.Bind(LocalPoint)
ListenerThre = New Thread(AddressOf ThrListener)
ListenerThre.Start()
ready = True
'ListBox1.Items.Add(LocalPoint.ToString() & "已开始侦听......")
Catch ex As Exception
ListenerSock.Close()
ready = False
MsgBox(" 有其它应用程序占用了 " & LocalPoint.ToString() & " ,请检查并关闭此应用后再打开本程序。", vbCritical + vbOKOnly, "警告")
End
End Try
End While
End Sub
Public Sub getIp() '获取本机所有网卡的IP
Dim Address() As System.Net.IPAddress
Dim i As Integer
Address = Dns.GetHostByName(Dns.GetHostName()).AddressList
If UBound(Address) < 0 Then
MsgBox("未能查找到本台电脑安装的网卡,暂不能启动本软件。", MsgBoxStyle.Critical + vbOKOnly, "注意")
End
Else
For i = 0 To UBound(Address)
ComboBox1.Items.Add(Address(i).ToString())
Next
ComboBox1.SelectedIndex = 0
LocalIp = ComboBox1.Text.Trim()
End If
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
Try
ListenerSock.Close()
ready = False
ListenerThre.Abort()
LocalIp = ComboBox1.Text.Trim()
StartListener() '开始侦听已选网卡的UDP端口
Catch
End Try
End Sub
Private Sub ThrListener() '侦听线程
While ready
Try
Dim bytes(1024) As Byte
Dim dataArray() As String
Dim RemotePoint As System.Net.EndPoint = New System.Net.IPEndPoint(System.Net.IPAddress.Any, 0)
Dim NumGet As Integer
Dim Msg As String
Dim Sendinf As String
Dim SendBuf As Byte()
Dim i As Integer
Dim DevBufferIpAddrStr As String
Dim DevBufferRemoteAddrStr As String
Dim DevBufferCardCode As String
Dim DevBufferUseTimeStr As String
Dim DevRecFramesStr As String
Dim DevBufferMachinStr As String
Dim DevBufferDatetimeStr As String
Dim DevBufferCardidStr As String
Dim DevBufferUseMoneryStr As String
Dim DevBufferReaderStr As String
Dim DevBufferDoorNoStr As String
Dim DevBufferDelayStr As String
Dim DevBufferPasswPropStr As String
Dim DevBufferPassWStr As String
Dim DevBufferStaryStr As String
Dim DevBufferRecordAddStr As String
Dim DevBufferAllNoStr As String
Dim DevBufferFunctionStr1 As String
Dim DevBufferFunctionStr2 As String
Dim DevBufferSerialNumStr As String
Dim DevBufferInputKeyStr As String
Dim DevBufferCommandStr As String
Dim DevBufferQrcodeInfStr As String
Dim DevBufferStateStr As String
Dim DevBufferRandomCode As String
Dim DevBufferSwitchStr As String
Dim DevBufferFireStr As String
NumGet = ListenerSock.ReceiveFrom(bytes, RemotePoint)
Msg = Encoding.GetEncoding(936).GetString(bytes, 0, NumGet)
'Msg = Encoding.UTF8.GetString(bytes, 0, NumGet) '读取中文wifi名称时,需用utf8解码
Me.Invoke(New EditUi(AddressOf EditUiNow), Now() & (" FromIP:" & Convert.ToString(RemotePoint) + " ").Substring(0, 30) & "Data:", Msg) '用Invoke跨线程更新UI
Me.Invoke(New EditTC(AddressOf EditTCNow), 3, Convert.ToString(RemotePoint)) '用Invoke跨线程更新UI
dataArray = Split(Convert.ToString(Msg), ",")
Select Case dataArray(0)
Case "101" '接收到 1、终端开机时向电脑发送的开机信息, 2、电脑发送002查询设备时间所返回的信息
DevRecFramesStr = dataArray(1) '包序列号
DevBufferIpAddrStr = dataArray(2) '终端IP
DevBufferRemoteAddrStr = dataArray(3) '远程电脑指机IP
DevBufferMachinStr = dataArray(4) '机号
DevBufferDatetimeStr = dataArray(5) '日期时间*/
If dataArray.Length > 6 Then '2018年以后的设备有唯一硬件序号*/
DevBufferSerialNumStr = dataArray(6)
End If
Sendinf = "001," + DevRecFramesStr '向设备发此数据表示已收到信息,否则设备会连续发三次
SendBuf = Encoding.GetEncoding(936).GetBytes(Sendinf)
ListenerSock.SendTo(SendBuf, SendBuf.Length, SocketFlags.None, RemotePoint)
Me.Invoke(New EditTC(AddressOf EditTCNow), 2, Now() & (" SendTo:" & Convert.ToString(RemotePoint) + " ").Substring(0, 30) & "Data:" & Sendinf)
Dim SystemTimeStr As String = String.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now)
If DevBufferDatetimeStr.Substring(0, 16) <> SystemTimeStr.Substring(0, 16) Then
Sendinf = "003," & DevRecFramesStr & "," & SystemTimeStr
SendBuf = Encoding.GetEncoding(936).GetBytes(Sendinf)
ListenerSock.SendTo(SendBuf, SendBuf.Length, SocketFlags.None, RemotePoint)
Me.Invoke(New EditTC(AddressOf EditTCNow), 2, Now() & (" SendTo:" & Convert.ToString(RemotePoint) + " ").Substring(0, 30) & "Data:" & Sendinf)
End If
Me.Invoke(New EditTC(AddressOf EditTCNow), 1, DevBufferDatetimeStr) '用Invoke跨线程更新UI
Case "102" '刷卡后设备向电脑发送此信息
DevRecFramesStr = dataArray(1) '包序列号
DevBufferIpAddrStr = dataArray(2) '终端IP
DevBufferRemoteAddrStr = dataArray(3) '远程电脑指机IP
DevBufferMachinStr = dataArray(4) '机号
DevBufferCardidStr = dataArray(5) '十位物理卡号
If dataArray.Length > 6 Then
DevBufferSerialNumStr = dataArray(6) '2018年以后的设备有唯一硬件序号
End If
Sendinf = "001," + DevRecFramesStr '向设备发此数据表示已收到信息,否则设备会连续发三次
SendBuf = Encoding.GetEncoding(936).GetBytes(Sendinf)
ListenerSock.SendTo(SendBuf, SendBuf.Length, SocketFlags.None, RemotePoint)
Me.Invoke(New EditTC(AddressOf EditTCNow), 2, Now() & (" SendTo:" & Convert.ToString(RemotePoint) + " ").Substring(0, 30) & "Data:" & Sendinf)
'此处加入业务对数据库的查、增、删、减操作
Sendinf = "009," & DevBufferMachinStr & "," & "{卡号:}" & DevBufferCardidStr & "\n" & TextBox5.Text.Trim() & "," & Format(NumericUpDown2.Value, "0") & "," & BeepCode & "," & VoiceCode
SendBuf = Encoding.GetEncoding(936).GetBytes(Sendinf)
ListenerSock.SendTo(SendBuf, SendBuf.Length, SocketFlags.None, RemotePoint)
Me.Invoke(New EditTC(AddressOf EditTCNow), 2, Now() & (" SendTo:" & Convert.ToString(RemotePoint) + " ").Substring(0, 30) & "Data:" & Sendinf)
Case "103" '按消费金额后刷卡 向电脑发送此信息
DevRecFramesStr = dataArray(1) '包序列号
DevBufferIpAddrStr = dataArray(2) '终端IP
DevBufferRemoteAddrStr = dataArray(3) '远程电脑指机IP
DevBufferMachinStr = dataArray(4) '机号
DevBufferCardidStr = dataArray(5) '卡号
DevBufferUseMoneryStr = dataArray(6) '消费额
DevBufferUseTimeStr = dataArray(7) '消费时间
If dataArray.Length > 8 Then
DevBufferSerialNumStr = dataArray(8) '2018年以后的设备有唯一硬件序号
End If
Sendinf = "001," + DevRecFramesStr '向设备发此数据表示已收到信息,否则设备会连续发三次
SendBuf = Encoding.GetEncoding(936).GetBytes(Sendinf)
ListenerSock.SendTo(SendBuf, SendBuf.Length, SocketFlags.None, RemotePoint)
Me.Invoke(New EditTC(AddressOf EditTCNow), 2, Now() & (" SendTo:" & Convert.ToString(RemotePoint) + " ").Substring(0, 30) & "Data:" & Sendinf)
'此处加入业务对数据库的查、增、删、减操作
'008指令返回本次消费成功,006指令返回本次消费失败,正式系统开发时要有重发机制*
Select Case VoiceCode
Case "1" '提示消费成功并显示消费金额
Sendinf = "008," & DevBufferMachinStr & "," & DevBufferCardidStr & "," & DevBufferUseMoneryStr & "," & TextBox5.Text.Trim() & "," & Format(NumericUpDown2.Value, "0") & "," & BeepCode & "," & VoiceCode
Case Else '其它提示
Sendinf = "006," & DevBufferMachinStr & "," & DevBufferCardidStr & "," & TextBox5.Text.Trim() & "," & Format(NumericUpDown2.Value, "0") & "," & BeepCode & "," & VoiceCode
End Select
SendBuf = Encoding.GetEncoding(936).GetBytes(Sendinf)
ListenerSock.SendTo(SendBuf, SendBuf.Length, SocketFlags.None, RemotePoint)
Me.Invoke(New EditTC(AddressOf EditTCNow), 2, Now() & (" SendTo:" & Convert.ToString(RemotePoint) + " ").Substring(0, 30) & "Data:" & Sendinf)
Case "104" '计次模式下刷卡 向电脑发送此信息
DevRecFramesStr = dataArray(1) '包序列号
DevBufferIpAddrStr = dataArray(2) '终端IP
DevBufferRemoteAddrStr = dataArray(3) '远程电脑指机IP
DevBufferMachinStr = dataArray(4) '机号
DevBufferCardidStr = dataArray(5) '卡号
DevBufferUseTimeStr = dataArray(6) '消费时间
If dataArray.Length > 7 Then
DevBufferSerialNumStr = dataArray(7) '2018年以后的设备有唯一硬件序号
End If
Sendinf = "001," + DevRecFramesStr '向设备发此数据表示已收到信息,否则设备会连续发三次
SendBuf = Encoding.GetEncoding(936).GetBytes(Sendinf)
ListenerSock.SendTo(SendBuf, SendBuf.Length, SocketFlags.None, RemotePoint)
Me.Invoke(New EditTC(AddressOf EditTCNow), 2, Now() & (" SendTo:" & Convert.ToString(RemotePoint) + " ").Substring(0, 30) & "Data:" & Sendinf)
'此处加入业务对数据库的查、增、删、减操作
'008指令返回本次消费成功,006指令返回本次消费失败,正式系统开发时要有重发机制*
Select Case VoiceCode
Case "1" '提示消费成功并显示消费金额
Sendinf = "008," & DevBufferMachinStr & "," & DevBufferCardidStr & ",0," & TextBox5.Text.Trim() & "," & Format(NumericUpDown2.Value, "0") & "," & BeepCode & "," & VoiceCode
Case Else '其它提示
Sendinf = "006," & DevBufferMachinStr & "," & DevBufferCardidStr & "," & TextBox5.Text.Trim() & "," & Format(NumericUpDown2.Value, "0") & "," & BeepCode & "," & VoiceCode
End Select
SendBuf = Encoding.GetEncoding(936).GetBytes(Sendinf)
ListenerSock.SendTo(SendBuf, SendBuf.Length, SocketFlags.None, RemotePoint)
Me.Invoke(New EditTC(AddressOf EditTCNow), 2, Now() & (" SendTo:" & Convert.ToString(RemotePoint) + " ").Substring(0, 30) & "Data:" & Sendinf)
Case "105" '接收到 脱网记账消费记录,消费机开启记账功能,有脱机记账消费记录网络恢复正常自动向电脑发送此信息
DevRecFramesStr = dataArray(1) '包序列号
DevBufferIpAddrStr = dataArray(2) '终端IP
DevBufferRemoteAddrStr = dataArray(3) '远程电脑指机IP
DevBufferMachinStr = dataArray(4) '机号
DevBufferCardidStr = dataArray(5) '卡号
DevBufferUseMoneryStr = dataArray(6) '消费金额
DevBufferUseTimeStr = dataArray(7) '消费时间
DevBufferStaryStr = dataArray(8) '消费方式 0扣费 1计次*/
DevBufferRecordAddStr = dataArray(9) '记录地址标识*/
DevBufferAllNoStr = dataArray(10) '总计录数*/
If dataArray.Length > 11 Then
DevBufferSerialNumStr = dataArray(11) '2018年以后的设备有唯一硬件序号
End If
Sendinf = "001," + DevRecFramesStr '向设备发此数据表示已收到信息,否则设备会连续发三次
SendBuf = Encoding.GetEncoding(936).GetBytes(Sendinf)
ListenerSock.SendTo(SendBuf, SendBuf.Length, SocketFlags.None, RemotePoint)
Me.Invoke(New EditTC(AddressOf EditTCNow), 2, Now() & (" SendTo:" & Convert.ToString(RemotePoint) + " ").Substring(0, 30) & "Data:" & Sendinf)
If IsDateTime(DevBufferUseTimeStr) = False Then '判断消费时间是否正确
DevBufferUseTimeStr = "9999-99-99 99:99:99" '如果消费时间不正确,需更为 9999-99-99 99:99:99 才能将此条记录删除 */
End If
'此处加入业务对数据库的查、增、删、减操作
'清除设备内当前这条已上传的记录,驱动设备继续上传剩下的记录
If CheckBox3.Checked Then
Sendinf = "011," & DevBufferMachinStr & "," & DevBufferCardidStr & "," & DevBufferUseMoneryStr & "," & DevBufferUseTimeStr & "," & DevBufferRecordAddStr
SendBuf = Encoding.GetEncoding(936).GetBytes(Sendinf)
ListenerSock.SendTo(SendBuf, SendBuf.Length, SocketFlags.None, RemotePoint)
Me.Invoke(New EditTC(AddressOf EditTCNow), 2, Now() & (" SendTo:" & Convert.ToString(RemotePoint) + " ").Substring(0, 30) & "Data:" & Sendinf)
End If
Case "106" '接收到设备的按键信息*/
DevRecFramesStr = dataArray(1) '包序列号
DevBufferIpAddrStr = dataArray(2) '终端IP
DevBufferRemoteAddrStr = dataArray(3) '远程电脑指机IP
DevBufferMachinStr = dataArray(4) '机号
DevBufferInputKeyStr = dataArray(5) '按键信息*/
If dataArray.Length > 6 Then
DevBufferSerialNumStr = dataArray(6) '2018年以后的设备有唯一硬件序号
End If
Sendinf = "001," + DevRecFramesStr '向设备发此数据表示已收到信息,否则设备会连续发三次
SendBuf = Encoding.GetEncoding(936).GetBytes(Sendinf)
ListenerSock.SendTo(SendBuf, SendBuf.Length, SocketFlags.None, RemotePoint)
Me.Invoke(New EditTC(AddressOf EditTCNow), 2, Now() & (" SendTo:" & Convert.ToString(RemotePoint) + " ").Substring(0, 30) & "Data:" & Sendinf)
Case "108" '接收到设备在取餐模式内的的刷卡信息
DevRecFramesStr = dataArray(1) '包序列号
DevBufferIpAddrStr = dataArray(2) '终端IP
DevBufferRemoteAddrStr = dataArray(3) '远程电脑指机IP
DevBufferMachinStr = dataArray(4) '机号
DevBufferCardidStr = dataArray(5) '十位物理卡号
If dataArray.Length > 6 Then
DevBufferSerialNumStr = dataArray(6) '2018年以后的设备有唯一硬件序号
End If
Sendinf = "001," + DevRecFramesStr '向设备发此数据表示已收到信息,否则设备会连续发三次
SendBuf = Encoding.GetEncoding(936).GetBytes(Sendinf)
ListenerSock.SendTo(SendBuf, SendBuf.Length, SocketFlags.None, RemotePoint)
Me.Invoke(New EditTC(AddressOf EditTCNow), 2, Now() & (" SendTo:" & Convert.ToString(RemotePoint) + " ").Substring(0, 30) & "Data:" & Sendinf)
'此处加入业务对数据库的查、增、删、减操作
Select Case VoiceCode
Case "1" '提示消费成功并显示消费金额
Sendinf = "008," & DevBufferMachinStr & "," & DevBufferCardidStr & ",0," & TextBox5.Text.Trim() & "," & Format(NumericUpDown2.Value, "0") & "," & BeepCode & "," & VoiceCode
Case Else '其它提示
Sendinf = "006," & DevBufferMachinStr & "," & DevBufferCardidStr & "," & TextBox5.Text.Trim() & "," & Format(NumericUpDown2.Value, "0") & "," & BeepCode & "," & VoiceCode
'Sendinf = "013," & DevBufferMachinStr & ",{卡号:}" & DevBufferCardidStr & "\n" & TextBox5.Text.Trim() & "," & Format(NumericUpDown2.Value, "0") & "," & BeepCode & "," & VoiceCode
End Select
SendBuf = Encoding.GetEncoding(936).GetBytes(Sendinf)
ListenerSock.SendTo(SendBuf, SendBuf.Length, SocketFlags.None, RemotePoint)
Me.Invoke(New EditTC(AddressOf EditTCNow), 2, Now() & (" SendTo:" & Convert.ToString(RemotePoint) + " ").Substring(0, 30) & "Data:" & Sendinf)
Case "109" '设备收到电脑发送的显示声音指令 后 反发的确认指令,可根据这个返回来判断设备有没有收到电脑发出的指令,如没有收到电脑可再次发送
DevRecFramesStr = dataArray(1) '包序列号
DevBufferIpAddrStr = dataArray(2) '终端IP
DevBufferRemoteAddrStr = dataArray(3) '远程电脑指机IP
DevBufferMachinStr = dataArray(4) '机号
DevBufferCommandStr = dataArray(5) '指令号
Case "115" '传送注册卡号到顺序区
DevRecFramesStr = dataArray(1) '&&包序列号
DevBufferIpAddrStr = dataArray(2) '&&终端IP
DevBufferRemoteAddrStr = dataArray(3) '&&远程电脑指机IP
DevBufferMachinStr = dataArray(4) '&&机号
DevBufferFunctionStr1 = dataArray(5) '记录格式标识(98万张卡标识为3)
Timer2.Enabled = False
If sendcode = "015" Then '只传一个注册卡号
If DevBufferFunctionStr1 = "0" Then
Me.Invoke(New EditTC(AddressOf EditTCNow), 4, "注册卡号‘" + RegCard + "’已成功地传送到IP地址为‘" + DevBufferIpAddrStr + "’的设备的顺序区!")
ElseIf DevBufferFunctionStr1 = "1" Then
Me.Invoke(New EditTC(AddressOf EditTCNow), 4, "注册卡号‘" + RegCard + "’已成功地传送到IP地址为‘" + DevBufferIpAddrStr + "’的设备的顺序区!")
Else
Me.Invoke(New EditTC(AddressOf EditTCNow), 4, "注册卡号‘" + RegCard + "’传送失败!")
End If
Else '连续传送注册卡号
If DevBufferFunctionStr1 = "0" Or DevBufferFunctionStr1 = "1" Or DevBufferFunctionStr1 = "2" Or DevBufferFunctionStr1 = "3" Then
SendPoin = SendPoin + 1
SendAgain = 0
Me.Invoke(New EditTC(AddressOf EditTCNow), 5, "")
Else
Sleep(150)
SendAgain = SendAgain + 1 '重发计次,如果重发3次表示此次下传失败,将发送指针移到最后,结束传送
If SendAgain = 3 Then SendCount = False
End If
If SendPoin <= SendPoinMax And SendCount Then
Timer2.Enabled = True
Sendinf = SendBufStr(SendPoin)
SendBuf = Encoding.GetEncoding(936).GetBytes(Sendinf)
ListenerSock.SendTo(SendBuf, SendBuf.Length, SocketFlags.None, RemotePoint)
Me.Invoke(New EditTC(AddressOf EditTCNow), 2, Now() & (" SendTo:" & Convert.ToString(RemotePoint) + " ").Substring(0, 30) & "Data:" & Sendinf)
Else
Me.Invoke(New EditTC(AddressOf EditTCNow), 6, "将注册卡号传送到设备的顺序区")
If SendPoin >= SendPoinMax Then
Me.Invoke(New EditTC(AddressOf EditTCNow), 4, "注册卡号已成功地传送到IP地址为‘" + DevBufferIpAddrStr + "’设备的顺序区!")
Else
Me.Invoke(New EditTC(AddressOf EditTCNow), 4, "传送注册卡号到IP地址为‘" + DevBufferIpAddrStr + "’设备时中途退出!请重新传送。")
End If
End If
End If
Case "116" '传送注册卡号到随机区
DevRecFramesStr = dataArray(1) '&&包序列号
DevBufferIpAddrStr = dataArray(2) '&&终端IP
DevBufferRemoteAddrStr = dataArray(3) '&&远程电脑指机IP
DevBufferMachinStr = dataArray(4) '&&机号
DevBufferFunctionStr1 = dataArray(5) '记录格式标识(98万张卡标识为3)
Timer2.Enabled = False
If sendcode = "016" Then '只传一个注册卡号
If DevBufferFunctionStr1 = "0" Then
Me.Invoke(New EditTC(AddressOf EditTCNow), 4, "注册卡号‘" + RegCard + "’已成功地传送到IP地址为‘" + DevBufferIpAddrStr + "’的设备的随机区!")
ElseIf DevBufferFunctionStr1 = "1" Then
Me.Invoke(New EditTC(AddressOf EditTCNow), 4, "注册卡号‘" + RegCard + "’已成功地传送到IP地址为‘" + DevBufferIpAddrStr + "’的设备的随机区!")
Else
Me.Invoke(New EditTC(AddressOf EditTCNow), 4, "注册卡号‘" + RegCard + "’传送失败!")
End If
Else '连续传送注册卡号
If DevBufferFunctionStr1 = "0" Or DevBufferFunctionStr1 = "1" Or DevBufferFunctionStr1 = "2" Or DevBufferFunctionStr1 = "3" Then
SendPoin = SendPoin + 1
SendAgain = 0
Me.Invoke(New EditTC(AddressOf EditTCNow), 5, "")
Else
Sleep(150)
SendAgain = SendAgain + 1 '重发计次,如果重发3次表示此次下传失败,将发送指针移到最后,结束传送
If SendAgain = 3 Then SendCount = False
End If
If SendPoin <= SendPoinMax And SendCount Then
Timer2.Enabled = True
Sendinf = SendBufStr(SendPoin)
SendBuf = Encoding.GetEncoding(936).GetBytes(Sendinf)
ListenerSock.SendTo(SendBuf, SendBuf.Length, SocketFlags.None, RemotePoint)
Me.Invoke(New EditTC(AddressOf EditTCNow), 2, Now() & (" SendTo:" & Convert.ToString(RemotePoint) + " ").Substring(0, 30) & "Data:" & Sendinf)
Else
Me.Invoke(New EditTC(AddressOf EditTCNow), 7, "将注册卡号传送到设备的随机区")
If SendPoin >= SendPoinMax Then
Me.Invoke(New EditTC(AddressOf EditTCNow), 4, "注册卡号已成功地传送到IP地址为‘" + DevBufferIpAddrStr + "’设备的随机区!")
Else
Me.Invoke(New EditTC(AddressOf EditTCNow), 4, "传送注册卡号到IP地址为‘" + DevBufferIpAddrStr + "’设备时中途退出!请重新传送。")
End If
End If
End If
Case "117" '删除设备内指定的注册卡号
DevRecFramesStr = dataArray(1) '&&包序列号
DevBufferIpAddrStr = dataArray(2) '&&终端IP
DevBufferRemoteAddrStr = dataArray(3) '&&远程电脑指机IP
DevBufferMachinStr = dataArray(4) '&&机号
DevBufferFunctionStr1 = dataArray(5) '记录格式标识(98万张卡标识为3)
If DevBufferFunctionStr1 = "0" Then
Me.Invoke(New EditTC(AddressOf EditTCNow), 4, "IP地址为‘" + DevBufferIpAddrStr + "’的设备,注册卡号:‘" + RegCard + "’ 清除成功!")
Else
Me.Invoke(New EditTC(AddressOf EditTCNow), 4, "IP地址为‘" + DevBufferIpAddrStr + "’的设备,注册卡号:‘" + RegCard + "’ 清除失败!")
End If
Case "118" '清除顺序区注册号
DevRecFramesStr = dataArray(1) '&&包序列号
DevBufferIpAddrStr = dataArray(2) '&&终端IP
DevBufferRemoteAddrStr = dataArray(3) '&&远程电脑指机IP
DevBufferMachinStr = dataArray(4) '&&机号
DevBufferFunctionStr1 = dataArray(5) '记录格式标识(98万张卡标识为3)
If DevBufferFunctionStr1 = "0" Then
Me.Invoke(New EditTC(AddressOf EditTCNow), 4, "IP地址为’" + DevBufferIpAddrStr + "’的设备顺序区内的注册卡记录清除成功!")
Else
Me.Invoke(New EditTC(AddressOf EditTCNow), 4, "IP地址为’" + DevBufferIpAddrStr + "’的设备顺序区内的注册卡记录清除失败!")
End If
Case "119" '清除随机区注册号
DevRecFramesStr = dataArray(1) '&&包序列号
DevBufferIpAddrStr = dataArray(2) '&&终端IP
DevBufferRemoteAddrStr = dataArray(3) '&&远程电脑指机IP
DevBufferMachinStr = dataArray(4) '&&机号
DevBufferFunctionStr1 = dataArray(5) '记录格式标识(98万张卡标识为3)
If DevBufferFunctionStr1 = "0" Then
Me.Invoke(New EditTC(AddressOf EditTCNow), 4, "IP地址为’" + DevBufferIpAddrStr + "’的设备随机区内的注册卡记录清除成功!")
Else
Me.Invoke(New EditTC(AddressOf EditTCNow), 4, "IP地址为’" + DevBufferIpAddrStr + "’的设备随机区内的注册卡记录清除失败!")
End If
Case "120" '查询指定的注册卡号是否存在
DevRecFramesStr = dataArray(1) '&&包序列号
DevBufferIpAddrStr = dataArray(2) '&&终端IP
DevBufferRemoteAddrStr = dataArray(3) '&&远程电脑指机IP
DevBufferMachinStr = dataArray(4) '&&机号
DevBufferFunctionStr1 = dataArray(5) '记录格式标识(98万张卡标识为3)
If DevBufferFunctionStr1 = "0" Then
Me.Invoke(New EditTC(AddressOf EditTCNow), 4, "IP地址为’" + DevBufferIpAddrStr + "’的设备内存在注册卡号‘" + RegCard + "’")
Else
Me.Invoke(New EditTC(AddressOf EditTCNow), 4, "IP地址为’" + DevBufferIpAddrStr + "’的设备内不存在注册卡号‘" + RegCard + "’")
End If
Case "121" '读设备内注册卡号
DevRecFramesStr = dataArray(1) '&&包序列号
DevBufferIpAddrStr = dataArray(2) '&&终端IP
DevBufferRemoteAddrStr = dataArray(3) '&&远程电脑指机IP
DevBufferMachinStr = dataArray(4) '&&机号
DevBufferFunctionStr1 = dataArray(5) '记录格式标识(98万张卡标识为3)
DevBufferFunctionStr2 = dataArray(6) '&&卡号
Me.Invoke(New EditTC(AddressOf EditTCNow), 4, "IP地址为’" + DevBufferIpAddrStr + "’的设备,顺序区内的注册卡数为:" + DevBufferFunctionStr1 + ",随机区内的注册卡数为:" + DevBufferFunctionStr2)
Case "125" '接收到直接扫码信息
DevRecFramesStr = dataArray(1) '包序列号
DevBufferIpAddrStr = dataArray(2) '终端IP
DevBufferRemoteAddrStr = dataArray(3) '远程电脑指机IP
DevBufferMachinStr = dataArray(4) '机号
DevBufferCommandStr = dataArray(5) '二维码格式标识
DevBufferQrcodeInfStr = ""
If dataArray.Length > 6 Then '防止二维码信息中有分隔符,
i = 6
While i < dataArray.Length - 1
DevBufferQrcodeInfStr = DevBufferQrcodeInfStr & dataArray(i)
i = i + 1
End While
DevBufferSerialNumStr = dataArray(dataArray.Length - 1) '2018年以后的设备有唯一硬件序号
End If
Sendinf = "001," + DevRecFramesStr '向设备发此数据表示已收到信息,否则设备会连续发三次
SendBuf = Encoding.GetEncoding(936).GetBytes(Sendinf)
ListenerSock.SendTo(SendBuf, SendBuf.Length, SocketFlags.None, RemotePoint)
Me.Invoke(New EditTC(AddressOf EditTCNow), 2, Now() & (" SendTo:" & Convert.ToString(RemotePoint) + " ").Substring(0, 30) & "Data:" & Sendinf)
'此处加入业务对数据库的查、增、删、减操作
Sendinf = "009," & DevBufferMachinStr & ",扫码信息:" & DevBufferQrcodeInfStr & "\n,20,1,0"
SendBuf = Encoding.GetEncoding(936).GetBytes(Sendinf)
ListenerSock.SendTo(SendBuf, SendBuf.Length, SocketFlags.None, RemotePoint)
Me.Invoke(New EditTC(AddressOf EditTCNow), 2, Now() & (" SendTo:" & Convert.ToString(RemotePoint) + " ").Substring(0, 30) & "Data:" & Sendinf)
Case "126" '&&返回无按键实时考勤门禁机 写参数指令
DevRecFramesStr = dataArray(1) '&&包序列号
DevBufferIpAddrStr = dataArray(2) '&&终端IP
DevBufferRemoteAddrStr = dataArray(3) '&&远程电脑指机IP
DevBufferMachinStr = dataArray(4) '&&机号
DevBufferCardCode = dataArray(5) '返回值
Msg = ""
Select Case DevBufferCardCode
Case "0"
Msg = "IP地址为’" & DevBufferIpAddrStr & "’的设备,参数设置成功!如果是设置WIFI热点参数,30秒后可查询WIFI连接状态。"
Case "1"
Msg = "IP地址为’" + DevBufferIpAddrStr + "’的设备,广播式发送成功!"
Case "2"
Msg = "IP地址为’" + DevBufferIpAddrStr + "’的设备,无线通讯失败!"
Case "4"
Msg = "IP地址为’" + DevBufferIpAddrStr + "’的设备,参数设置指令的数据错误!"
Case "5"
Msg = "IP地址为’" + DevBufferIpAddrStr + "’的设备,必须按主板上的RST键3秒,将密码清空后才能再更改通讯密码!"
End Select
Me.Invoke(New EditTC(AddressOf EditTCNow), 9, Msg)
Case "127" '&&返回无按键实时考勤门禁机读参数指令
DevRecFramesStr = dataArray(1) '&&包序列号
DevBufferIpAddrStr = dataArray(2) '&&终端IP
DevBufferRemoteAddrStr = dataArray(3) '&&远程电脑指机IP
DevBufferMachinStr = dataArray(4) '&&机号
DevBufferCardCode = dataArray(5) '返回值
Select Case DevBufferCardCode
Case "0"
Msg = ""
For i = 6 To UBound(dataArray) - LBound(dataArray)
Me.Invoke(New EditTC(AddressOf EditTCNow), 11, dataArray(i))
'infparsing(dataArray(i))
Next
Case "1"
Me.Invoke(New EditTC(AddressOf EditTCNow), 8, "不能以广播式发送!")
Case "2"
Me.Invoke(New EditTC(AddressOf EditTCNow), 8, "无线通讯失败!")
Case Else
If DevBufferCardCode.Substring(0, 2) = "8=" Then
DevBufferCardCode = DevBufferCardCode.Substring(2, Len(DevBufferCardCode) - 2)
Dim wifiinf() As String
wifiinf = Split(DevBufferCardCode, "&")
For i = 0 To UBound(wifiinf) - LBound(wifiinf)
Select Case i
Case 0
Me.Invoke(New EditTC(AddressOf EditTCNow), 8, "WIFI热点名称 :" & wifiinf(i))
Case 1
Msg = "数据传送方式 :"
Select Case wifiinf(i)
Case "0"
Msg = Msg & "网线和WIFI都有效时,刷卡数据以网线发送"
Case "1"
Msg = Msg & "网线和WIFI都有效时, 刷卡数据以WIFI发送"
Case "2"
Msg = Msg & "网线和WIFI同时发送刷卡数据()"
Case "3"
Msg = Msg & "刷卡数据只以网络发送()"
Case "4"
Msg = Msg & "刷卡数据只以WIFI发送()"
End Select
Me.Invoke(New EditTC(AddressOf EditTCNow), 8, Msg)
Case 2
Msg = "WIFI的IP获取方式:"
If wifiinf(i) = "1" Then Msg = Msg & "DHCP自动获取" Else Msg = Msg & "绑定静态ip"
Me.Invoke(New EditTC(AddressOf EditTCNow), 8, Msg)
Case 3
Me.Invoke(New EditTC(AddressOf EditTCNow), 8, "WIFI的IP地址 :" & wifiinf(i))
Case 4
Me.Invoke(New EditTC(AddressOf EditTCNow), 8, "WIFI的掩码 :" & wifiinf(i))
Case 5
Me.Invoke(New EditTC(AddressOf EditTCNow), 8, "WIFI的MAC :" & wifiinf(i))
Case 6
Me.Invoke(New EditTC(AddressOf EditTCNow), 8, "WIFI的网关 :" & wifiinf(i))
Case 7
Me.Invoke(New EditTC(AddressOf EditTCNow), 8, "WIFI网关MAC :" & wifiinf(i))
Case 8
Me.Invoke(New EditTC(AddressOf EditTCNow), 8, "设备的WIFI名称 :" & wifiinf(i))
Case 9
Msg = "设备WIFI连接状态:"
If wifiinf(i) = "1" Then Msg = Msg & "连接失败" Else Msg = Msg & "连接成功"
Me.Invoke(New EditTC(AddressOf EditTCNow), 8, Msg)
End Select
Next
End If
End Select
Case "128" '接收到消费金额及扫码信息
DevRecFramesStr = dataArray(1) '包序列号
DevBufferIpAddrStr = dataArray(2) '终端IP
DevBufferRemoteAddrStr = dataArray(3) '远程电脑指机IP
DevBufferMachinStr = dataArray(4) '机号
DevBufferCommandStr = dataArray(5) '口令
DevBufferUseMoneryStr = dataArray(6) '消费金额*/
DevBufferUseTimeStr = dataArray(7) '消费时间*/
DevBufferQrcodeInfStr = ""
If dataArray.Length > 9 Then '防止二维码信息中有分隔符,
i = 9
While i < dataArray.Length - 1
DevBufferQrcodeInfStr = DevBufferQrcodeInfStr + dataArray(i)
i = i + 1
End While
DevBufferSerialNumStr = dataArray(dataArray.Length - 1) '2018年以后的设备有唯一硬件序号
End If
Sendinf = "001," + DevRecFramesStr '向设备发此数据表示已收到信息,否则设备会连续发三次
SendBuf = Encoding.GetEncoding(936).GetBytes(Sendinf)
ListenerSock.SendTo(SendBuf, SendBuf.Length, SocketFlags.None, RemotePoint)
Me.Invoke(New EditTC(AddressOf EditTCNow), 2, Now() & (" SendTo:" & Convert.ToString(RemotePoint) + " ").Substring(0, 30) & "Data:" & Sendinf)
'此处加入业务对数据库的查、增、删、减操作
Sendinf = "008," & DevBufferMachinStr & "," & DevBufferCommandStr & "," & DevBufferUseMoneryStr & ",正在进行扫码支付..{请不要按动键盘!\n},5,0,1"
SendBuf = Encoding.GetEncoding(936).GetBytes(Sendinf)
ListenerSock.SendTo(SendBuf, SendBuf.Length, SocketFlags.None, RemotePoint)
Me.Invoke(New EditTC(AddressOf EditTCNow), 2, Now() & (" SendTo:" & Convert.ToString(RemotePoint) + " ").Substring(0, 30) & "Data:" & Sendinf)
Case "150" '接收到实时考勤门禁机刷卡数据
DevRecFramesStr = dataArray(1) '包序列号
DevBufferIpAddrStr = dataArray(2) '终端IP
DevBufferRemoteAddrStr = dataArray(3) '远程电脑指机IP
DevBufferMachinStr = dataArray(4) '机号
DevBufferCardidStr = dataArray(5) '卡号
DevBufferReaderStr = dataArray(6) '消费金额*/
DevBufferDoorNoStr = dataArray(7) '门或继电器号*/
DevBufferDelayStr = dataArray(8) '门磁未关秒数,0表示已关*/
DevBufferPasswPropStr = dataArray(9) '密码属性(0密码无效,1刷卡后按密码,2补签密码,3开门密码,4防迫胁密码)*/
DevBufferPassWStr = dataArray(10) '密码(最多8位数字)*/
DevBufferUseTimeStr = dataArray(11) '消费时间*/
If dataArray.Length > 12 Then
DevBufferSerialNumStr = dataArray(12) '2018年以后的设备有唯一硬件序号
End If
Sendinf = "001," + DevRecFramesStr '向设备发此数据表示已收到信息,否则设备会连续发三次
SendBuf = Encoding.GetEncoding(936).GetBytes(Sendinf)
ListenerSock.SendTo(SendBuf, SendBuf.Length, SocketFlags.None, RemotePoint)
Me.Invoke(New EditTC(AddressOf EditTCNow), 2, Now() & (" SendTo:" & Convert.ToString(RemotePoint) + " ").Substring(0, 30) & "Data:" & Sendinf)
'此处加入业务对数据库的查、增、删、减操作
'用050指令返回开门成功,051指令返回开门失败,正式系统开发时要有重发机制
Select Case VoiceCode
Case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15" '发送禁止开门的指令"
Sendinf = "051," & DevBufferMachinStr & "," & DevBufferCardidStr & "," & TextBox5.Text.Trim() & "," & Format(NumericUpDown2.Value, "0") & "," & BeepCode & "," & VoiceCode
Case Else '发送开门指令
Sendinf = "050," & DevBufferMachinStr & "," & DevBufferCardidStr & "," & TextBox5.Text.Trim() & "," & Format(NumericUpDown2.Value, "0") & "," & BeepCode & "," & VoiceCode & "," & DevBufferReaderStr & "," & DevBufferDoorNoStr & "," & Format(NumericUpDown1.Value, "0") & "," & Format(NumericUpDown2.Value, "0")
End Select
SendBuf = Encoding.GetEncoding(936).GetBytes(Sendinf)
ListenerSock.SendTo(SendBuf, SendBuf.Length, SocketFlags.None, RemotePoint)
Me.Invoke(New EditTC(AddressOf EditTCNow), 2, Now() & (" SendTo:" & Convert.ToString(RemotePoint) + " ").Substring(0, 30) & "Data:" & Sendinf)
Case "151" '发送按钮开门申请信息
DevRecFramesStr = dataArray(1) '包序列号
DevBufferIpAddrStr = dataArray(2) '终端IP
DevBufferRemoteAddrStr = dataArray(3) '远程电脑指机IP
DevBufferMachinStr = dataArray(4) '机号
DevBufferInputKeyStr = dataArray(5) '&&按钮号
DevBufferReaderStr = dataArray(6) '&&对应的门或继电器号
DevBufferDelayStr = dataArray(7) '&&门磁未关秒数(0门已关)
DevBufferUseTimeStr = dataArray(8) '&&刷卡时间
If UBound(dataArray) >= 9 Then DevBufferSerialNumStr = dataArray(9) Else DevBufferSerialNumStr = "" '唯一硬件序号
Sendinf = "001," + DevRecFramesStr '向设备发此数据表示已收到信息,否则设备会连续发三次
SendBuf = Encoding.GetEncoding(936).GetBytes(Sendinf)
ListenerSock.SendTo(SendBuf, SendBuf.Length, SocketFlags.None, RemotePoint)
Me.Invoke(New EditTC(AddressOf EditTCNow), 2, Now() & (" SendTo:" & Convert.ToString(RemotePoint) + " ").Substring(0, 30) & "Data:" & Sendinf)
Select Case VoiceCode
Case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15" '发送禁止开门的指令"
Sendinf = "051," & DevBufferMachinStr & "," & DevBufferInputKeyStr & "," & TextBox5.Text.Trim() & "," & Format(NumericUpDown2.Value, "0") & "," & BeepCode & "," & VoiceCode
Case Else '发送开门指令
Sendinf = "050," & DevBufferMachinStr & "," & DevBufferInputKeyStr & "," & TextBox5.Text.Trim() & "," & Format(NumericUpDown2.Value, "0") & "," & BeepCode & "," & VoiceCode & "," & DevBufferInputKeyStr & "," & DevBufferReaderStr & "," & Format(NumericUpDown1.Value, "0") & "," & Format(NumericUpDown2.Value, "0")
End Select
SendBuf = Encoding.GetEncoding(936).GetBytes(Sendinf)
ListenerSock.SendTo(SendBuf, SendBuf.Length, SocketFlags.None, RemotePoint)
Me.Invoke(New EditTC(AddressOf EditTCNow), 2, Now() & (" SendTo:" & Convert.ToString(RemotePoint) + " ").Substring(0, 30) & "Data:" & Sendinf)
Case "152" '门磁报警信息
DevRecFramesStr = dataArray(1) ' &&包序列号
DevBufferIpAddrStr = dataArray(2) ' &&终端IP
DevBufferRemoteAddrStr = dataArray(3) '&&远程电脑指机IP
DevBufferMachinStr = dataArray(4) '&&机号
DevBufferInputKeyStr = dataArray(5) '&&门磁号
DevBufferReaderStr = dataArray(6) '&&对应的门或继电器号
DevBufferDelayStr = dataArray(7) '&&门磁未关秒数(0门已关)
DevBufferUseTimeStr = dataArray(8) '&&刷卡时间
If UBound(dataArray) >= 9 Then DevBufferSerialNumStr = dataArray(9) Else DevBufferSerialNumStr = "" '唯一硬件序号
Sendinf = "001," + DevRecFramesStr '向设备发此数据表示已收到信息,否则设备会连续发三次
SendBuf = Encoding.GetEncoding(936).GetBytes(Sendinf)
ListenerSock.SendTo(SendBuf, SendBuf.Length, SocketFlags.None, RemotePoint)
Me.Invoke(New EditTC(AddressOf EditTCNow), 2, Now() & (" SendTo:" & Convert.ToString(RemotePoint) + " ").Substring(0, 30) & "Data:" & Sendinf)
Case "153" '返回查询设备状态的053指令
DevRecFramesStr = dataArray(1) ' &&包序列号
DevBufferIpAddrStr = dataArray(2) ' &&终端IP
DevBufferRemoteAddrStr = dataArray(3) '&&远程电脑指机IP
DevBufferMachinStr = dataArray(4) '&&机号
DevBufferInputKeyStr = dataArray(5) '&&继电器号
DevBufferReaderStr = dataArray(6) '&&继电器状态
DevBufferDelayStr = dataArray(7) '&&门磁未关秒数(0门已关)
DevBufferStateStr = dataArray(8) '&&门磁报警状态
If UBound(dataArray) >= 9 Then DevBufferSerialNumStr = dataArray(9) Else DevBufferSerialNumStr = "" '唯一硬件序号
Sendinf = "001," + DevRecFramesStr '向设备发此数据表示已收到信息,否则设备会连续发三次
SendBuf = Encoding.GetEncoding(936).GetBytes(Sendinf)
ListenerSock.SendTo(SendBuf, SendBuf.Length, SocketFlags.None, RemotePoint)
Me.Invoke(New EditTC(AddressOf EditTCNow), 2, Now() & (" SendTo:" & Convert.ToString(RemotePoint) + " ").Substring(0, 30) & "Data:" & Sendinf)
Msg = "继电器号:" & DevBufferInputKeyStr & ",继电器状态:" & DevBufferReaderStr & ",门磁未关秒数:" & DevBufferDelayStr & ",门磁报警状态:" & DevBufferStateStr
Me.Invoke(New EditTC(AddressOf EditTCNow), 9, Msg)
Case "154" '接收到实时考勤门禁机卡离开感应区
DevRecFramesStr = dataArray(1) '包序列号
DevBufferIpAddrStr = dataArray(2) '终端IP
DevBufferRemoteAddrStr = dataArray(3) '远程电脑指机IP
DevBufferMachinStr = dataArray(4) '机号
DevBufferCardidStr = dataArray(5) '卡号
DevBufferSerialNumStr = dataArray(6)
Case "155" '&&门禁脱网记录发送----
DevRecFramesStr = dataArray(1) ' &&包序列号
DevBufferIpAddrStr = dataArray(2) ' &&终端IP
DevBufferRemoteAddrStr = dataArray(3) '&&远程电脑指机IP
DevBufferMachinStr = dataArray(4) '&&机号
DevBufferCardidStr = dataArray(5) '&&卡号
DevBufferReaderStr = dataArray(6) '&&读头
DevBufferDoorNoStr = dataArray(7) '&&门或继电器号
DevBufferPasswPropStr = dataArray(8) '&&密码属性(0密码无效,1刷卡后按密码,2补签密码,3开门密码,4防迫胁密码)
DevBufferUseTimeStr = dataArray(9) '&&刷卡时间
DevBufferStaryStr = dataArray(10) '&&状态 0扣费 1计次
DevBufferRecordAddStr = dataArray(11) '&&记录地址标识
DevBufferAllNoStr = dataArray(12) '&&总计录数
If UBound(dataArray) = 13 Then DevBufferSerialNumStr = dataArray(13) Else DevBufferSerialNumStr = "" '唯一硬件序号
Sendinf = "001," + DevRecFramesStr '向设备发此数据表示已收到信息,否则设备会连续发三次
SendBuf = Encoding.GetEncoding(936).GetBytes(Sendinf)
ListenerSock.SendTo(SendBuf, SendBuf.Length, SocketFlags.None, RemotePoint)
Me.Invoke(New EditTC(AddressOf EditTCNow), 2, Now() & (" SendTo:" & Convert.ToString(RemotePoint) + " ").Substring(0, 30) & "Data:" & Sendinf)
If Not IsDateTime(DevBufferUseTimeStr) Then '记录的刷卡时间非法,表示此记录有问题(测试时的其它数据)
DevBufferUseTimeStr = "9999-99-99 99:99:99"
End If
'这里对脱网记录进行处理
If CheckBox3.Checked Then '选择清除已上传的记录驱使用设备继续上传剩下的记录
Sendinf = "055," + DevBufferMachinStr + "," + DevBufferCardidStr + "," + DevBufferUseTimeStr + "," + DevBufferRecordAddStr '&&清除设备内当前这条记录,设备才会传下一条记录
SendBuf = Encoding.GetEncoding(936).GetBytes(Sendinf)
ListenerSock.SendTo(SendBuf, SendBuf.Length, SocketFlags.None, RemotePoint)
Me.Invoke(New EditTC(AddressOf EditTCNow), 2, Now() & (" SendTo:" & Convert.ToString(RemotePoint) + " ").Substring(0, 30) & "Data:" & Sendinf)
End If
Case "158" '响应电脑远程开门的058指令
DevRecFramesStr = dataArray(1) ' &&包序列号
DevBufferIpAddrStr = dataArray(2) ' &&终端IP
DevBufferRemoteAddrStr = dataArray(3) '&&远程电脑指机IP
DevBufferMachinStr = dataArray(4) '&&机号
DevBufferStaryStr = dataArray(5) '&&0开门成功,1开门密码认证失败,2开门密码认证失败超过6次,需等待一段时间后再能再次接收058指令(防暴力破解),3 不允许此时间段开门
DevBufferRandomCode = dataArray(6) '&&动态随机码(8位十六进制)
Me.Invoke(New EditTC(AddressOf EditTCNow), 10, DevBufferRandomCode)
Msg = ""
Select Case DevBufferStaryStr
Case "0"
Msg = "IP:" & DevBufferIpAddrStr & " 开门成功"
Case "1"
Msg = "IP:" & DevBufferIpAddrStr & " 开门密码认证失败!"
Case "2"
Msg = "IP:" & DevBufferIpAddrStr & " 开门密码认证失败超过6次,需等待一段时间后再能再次接收058指令(防暴力破解)"
Case "3"
Msg = "IP:" & DevBufferIpAddrStr & " 不允许此时间段开门"
End Select
Me.Invoke(New EditTC(AddressOf EditTCNow), 9, Msg)
Me.Invoke(New EditTC(AddressOf EditTCNow), 10, DevBufferRandomCode)
Case "159" '&&心跳信息
DevRecFramesStr = dataArray(1) ' &&包序列号
DevBufferIpAddrStr = dataArray(2) ' &&终端IP
DevBufferRemoteAddrStr = dataArray(3) '&&远程电脑指机IP
DevBufferMachinStr = dataArray(4) '&&机号
DevBufferQrcodeInfStr = dataArray(5) '&&信息类型
DevBufferSwitchStr = dataArray(6) '继电器状态(bit0为第1门bit1为第2门)
DevBufferFireStr = dataArray(7) '消防输入状态
DevBufferRandomCode = dataArray(8) '&&动态随机码(8位十六进制)
DevBufferDatetimeStr = dataArray(9) '日期时间
DevBufferSerialNumStr = dataArray(10) '设备硬件号
Me.Invoke(New EditTC(AddressOf EditTCNow), 10, DevBufferRandomCode)
Case "199" '消费金额发起指令
DevRecFramesStr = dataArray(1) ' &&包序列号
DevBufferRecordAddStr = dataArray(2) ' &&消费流水号
DevBufferMachinStr = dataArray(3) '&&机号
DevBufferUseMoneryStr = dataArray(4) '&&消费额
Sendinf = "001," + DevRecFramesStr '向设备发此数据表示已收到信息,否则设备会连续发三次
SendBuf = Encoding.GetEncoding(936).GetBytes(Sendinf)
ListenerSock.SendTo(SendBuf, SendBuf.Length, SocketFlags.None, RemotePoint)
Me.Invoke(New EditTC(AddressOf EditTCNow), 2, Now() & (" SendTo:" & Convert.ToString(RemotePoint) + " ").Substring(0, 30) & "Data:" & Sendinf)
'这里执行对消费机发送消费结果的显示及声音
'消费结果成功0,失败1 余额,卡号
Sendinf = "099," + DevRecFramesStr + "," + DevBufferRecordAddStr + ",0," + DevBufferMachinStr + "," + DevBufferUseMoneryStr + ",888.8,1234567890" '&&向消费发起终端发送消费结果
SendBuf = Encoding.GetEncoding(936).GetBytes(Sendinf)
ListenerSock.SendTo(SendBuf, SendBuf.Length, SocketFlags.None, RemotePoint)
Me.Invoke(New EditTC(AddressOf EditTCNow), 2, Now() & (" SendTo:" & Convert.ToString(RemotePoint) + " ").Substring(0, 30) & "Data:" & Sendinf)
Case "198" '消费取消指令
DevRecFramesStr = dataArray(1) ' &&包序列号
DevBufferRecordAddStr = dataArray(2) ' &&消费流水号
Sendinf = "001," + DevRecFramesStr '向设备发此数据表示已收到信息,否则设备会连续发三次
SendBuf = Encoding.GetEncoding(936).GetBytes(Sendinf)
ListenerSock.SendTo(SendBuf, SendBuf.Length, SocketFlags.None, RemotePoint)
Me.Invoke(New EditTC(AddressOf EditTCNow), 2, Now() & (" SendTo:" & Convert.ToString(RemotePoint) + " ").Substring(0, 30) & "Data:" & Sendinf)
End Select
Catch ex As Exception
Me.Invoke(New EditTC(AddressOf EditTCNow), 2, "ERROR:" & vbCrLf & ex.GetHashCode & ex.Message & vbCrLf)
End Try
End While
End Sub
Private Sub EditTCNow(ByVal con As Integer, ByVal dispinf As String) '这里要和委托定义时的参数保持一致
Select Case con
Case 1
TextBox3.Text = dispinf
Case 2
ListBox1.Items.Add(dispinf)
ListBox1.SelectedIndex = ListBox1.Items.Count - 1
Case 3
TextBox1.Text = dispinf
Case 4
Form3.TextBox2.Text = dispinf
Case 5
Form3.Pb1.Value = Form3.Pb1.Value + 1
Case 6
Form3.Button8.Text = dispinf
Form3.Button9.Enabled = True
Case 7
Form3.Button9.Text = dispinf
Form3.Button8.Enabled = True
Case 8
Form5.ListBox1.Items.Add(dispinf)
Case 9
Form6.TextBox3.Text = dispinf
Form5.ListBox1.Items.Add(dispinf)
Case 10
Form6.TextBox2.Text = dispinf
Case 11
infparsing(dispinf)
End Select
End Sub
Private Sub EditUiNow(ByVal data0 As String, ByVal data1 As String) '这里要和委托定义时的参数保持一致
ListBox1.Items.Add(data0 & data1)
ListBox1.SelectedIndex = ListBox1.Items.Count - 1
Dim dataArray() As String
Dim DevBufferIpAddrStr As String
Dim DevBufferMaskStr As String
Dim DevBufferGatewayStr As String
Dim DevBufferRemoteAddrStr As String
Dim DevBufferPort As String
Dim DevBufferNumberDecStr As String
Dim DevBufferGatewayStrMAC As String
Dim DevBufferRemoteAddrMACStr As String
Dim DevBufferMACSearchStr As String
Dim DevBufferSerialNumStr As String
Dim plist As ListViewItem
Dim i As Integer
Dim poi As Integer
Dim MACSTC As String
Dim MACCH As String
Dim iswifi, wifidhcp As String
dataArray = Split(data1, ",")
If dataArray(0) = "100" Then '发送搜索指令后,在线设备的返回信息
If UBound(dataArray) = 6 Then '旧设备不能跨网段通讯的设备返回信息
For i = 1 To UBound(dataArray) / 6
DevBufferIpAddrStr = dataArray((i - 1) * 6 + 1)
DevBufferMaskStr = dataArray((i - 1) * 6 + 2)
DevBufferGatewayStr = dataArray((i - 1) * 6 + 3)
DevBufferRemoteAddrStr = dataArray((i - 1) * 6 + 4)
DevBufferPort = dataArray((i - 1) * 6 + 5)
DevBufferNumberDecStr = dataArray((i - 1) * 6 + 6)
poi = InStr(1, machinnos, DevBufferNumberDecStr)
If poi = 0 Then
MACSTC = GetSTCMAC(DevBufferNumberDecStr)
machinnos = machinnos + DevBufferNumberDecStr
plist = ListView1.Items.Add(DevBufferIpAddrStr)
plist.SubItems.Add(DevBufferMaskStr)
plist.SubItems.Add(DevBufferGatewayStr)
plist.SubItems.Add("")
plist.SubItems.Add(DevBufferRemoteAddrStr)
plist.SubItems.Add("")
plist.SubItems.Add("")
plist.SubItems.Add(DevBufferPort)
plist.SubItems.Add(DevBufferNumberDecStr)
plist.SubItems.Add("否")
plist.SubItems.Add(MACSTC)
End If
Next
End If
If UBound(dataArray) >= 9 Then '可跨网段通讯设备的返回信息
For i = 1 To UBound(dataArray) / 9
DevBufferIpAddrStr = dataArray((i - 1) * 9 + 1)
DevBufferMaskStr = dataArray((i - 1) * 9 + 2)
DevBufferGatewayStr = dataArray((i - 1) * 9 + 3)
DevBufferGatewayStrMAC = dataArray((i - 1) * 9 + 4)
DevBufferRemoteAddrStr = dataArray((i - 1) * 9 + 5)
DevBufferRemoteAddrMACStr = dataArray((i - 1) * 9 + 6)
DevBufferMACSearchStr = dataArray((i - 1) * 9 + 7)
DevBufferPort = dataArray((i - 1) * 9 + 8)
DevBufferNumberDecStr = dataArray((i - 1) * 9 + 9)
MACSTC = GetSTCMAC(DevBufferNumberDecStr)
If (DEC_To_Bin(DevBufferMACSearchStr)).Substring(0, 1) = "1" Then iswifi = "WiFi" Else iswifi = "有线"
If (DEC_To_Bin(DevBufferMACSearchStr)).Substring(5, 1) = "1" Then wifidhcp = "DHCP" Else wifidhcp = "静态ip"
If UBound(dataArray) >= 10 Then
DevBufferSerialNumStr = dataArray(10)
MACCH = GetCHMAC(DevBufferSerialNumStr)
Else
DevBufferSerialNumStr = ""
MACCH = ""
End If
poi = InStr(1, machinnos, DevBufferNumberDecStr)
If poi = 0 Then
machinnos = machinnos + DevBufferNumberDecStr
plist = ListView1.Items.Add(DevBufferIpAddrStr)
plist.SubItems.Add(DevBufferMaskStr)
plist.SubItems.Add(DevBufferGatewayStr)
plist.SubItems.Add(DevBufferGatewayStrMAC)
plist.SubItems.Add(DevBufferRemoteAddrStr)
plist.SubItems.Add(DevBufferRemoteAddrMACStr)
plist.SubItems.Add(DevBufferMACSearchStr)
plist.SubItems.Add(DevBufferPort)
plist.SubItems.Add(DevBufferNumberDecStr)
plist.SubItems.Add("是")
plist.SubItems.Add(MACSTC)
plist.SubItems.Add(DevBufferSerialNumStr)
plist.SubItems.Add(iswifi)
plist.SubItems.Add(wifidhcp)
plist.SubItems.Add(MACCH)
End If
Next
End If
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
ListView1.Items.Clear()
machinnos = ""
Dim SendStr = "000"
CommandSendBroadcast(SendStr) '广播方式发送搜索在线设备的指令
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
ListBox1.Items.Clear()
End Sub
Function IsDateTime(ByVal datetimestr As String) As Boolean
Dim dt As Date
Try
dt = datetimestr
Return True
Catch ex As Exception
Return False
End Try
End Function
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Dim SendStr = "003," & TextBox2.Text.Trim() & "," & TextBox3.Text.Trim()
CommandSend(SendStr)
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
Dim SendStr = "002," & TextBox2.Text.Trim()
CommandSend(SendStr)
End Sub
Public Function CheckIp(Ipstr As String) As Boolean
Dim ip As IPAddress
Try
ip = IPAddress.Parse(Ipstr)
Return True
Catch
Return False
End Try
End Function
Function CheckRemoIpPort(Ipstr As String) As Boolean
Dim dataArray() As String
Try
dataArray = Split(Ipstr, ":")
RemoteIPoint = New IPEndPoint(IPAddress.Parse(dataArray(0)), Convert.ToInt32(dataArray(1)))
Return True
Catch
Return False
End Try
End Function
Private Sub ListView1_ColumnClick(sender As Object, e As ColumnClickEventArgs) Handles ListView1.ColumnClick
If _ListViewSorter = ListViewSorter.EnumSortOrder.Ascending Then
Dim Sorter As New ListViewSorter(e.Column, ListViewSorter.EnumSortOrder.Descending)
ListView1.ListViewItemSorter = Sorter
_ListViewSorter = ListViewSorter.EnumSortOrder.Descending
Else
Dim Sorter As New ListViewSorter(e.Column, ListViewSorter.EnumSortOrder.Ascending)
ListView1.ListViewItemSorter = Sorter
_ListViewSorter = ListViewSorter.EnumSortOrder.Ascending
End If
End Sub
Private Sub ListView1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListView1.SelectedIndexChanged
Try
TextBox1.Text = ListView1.SelectedItems(0).SubItems(0).Text & ":" & ListView1.SelectedItems(0).SubItems(7).Text
Catch
End Try
End Sub
Private Sub TextBox6_TextChanged(sender As Object, e As EventArgs) Handles TextBox6.TextChanged
Try
ListenerSock.Close()
ready = False
ListenerThre.Abort()
LocalIp = ComboBox1.Text.Trim()
StartListener() '开始侦听已选网卡的UDP端口
Catch
End Try
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
TextBox3.Text = Format(Now, "yyyy-MM-dd HH:mm:ss")
End Sub
Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
If CheckBox1.Checked = True Then
Timer1.Enabled = True
Else
Timer1.Enabled = False
End If
End Sub
Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
Dim SendStr = "012," & TextBox2.Text.Trim() & "," & Format(Val(TextBox4.Text), "000000")
CommandSend(SendStr)
End Sub
Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
Dim SendStr = "022," & TextBox2.Text.Trim() & ",1,请输入密码," & Format(NumericUpDown2.Value, "0") & ",1,20"
CommandSend(SendStr)
End Sub
Public Sub CommandSend(ByVal SendStr As String)
If CheckRemoIpPort(TextBox1.Text.Trim()) Then
Dim ByArr As Byte() = Encoding.GetEncoding(936).GetBytes(SendStr)
Dim SendInf As String = Now() & (" SendTo:" & Convert.ToString(RemoteIPoint) + " ").Substring(0, 30) & "Data:" & SendStr
ListenerSock.SendTo(ByArr, ByArr.Length, SocketFlags.None, RemoteIPoint)
ListBox1.Items.Add(SendInf)
ListBox1.SelectedIndex = ListBox1.Items.Count - 1
Else
MsgBox("请选择一台在线设备或者输入设备的IP地址", MsgBoxStyle.Critical, "提示")
TextBox1.Select()
End If
End Sub
Public Sub CommandSendBroadcast(ByVal SendStr As String)
Dim ByArr As Byte() = Encoding.GetEncoding(936).GetBytes(SendStr)
Dim Remote As IPEndPoint = New IPEndPoint(IPAddress.Broadcast, PortNumber)
ListenerSock.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, 1) '设为广播式发送
ListenerSock.SendTo(ByArr, ByArr.Length, SocketFlags.None, Remote)
ListBox1.Items.Add(Now() & (" SendTo:" & Convert.ToString(Remote) + " ").Substring(0, 30) & "Data:" & SendStr)
ListBox1.SelectedIndex = ListBox1.Items.Count - 1
End Sub
Public Sub CommandSendUtf8(ByVal SendStr As String)
If CheckRemoIpPort(TextBox1.Text.Trim()) Then
Dim ByArr As Byte() = Encoding.GetEncoding("utf-8").GetBytes(SendStr) '为支持中文热点名称,需使用utf8编码方式转换
Dim SendInf As String = Now() & (" SendTo:" & Convert.ToString(RemoteIPoint) + " ").Substring(0, 30) & "Data:" & SendStr
ListenerSock.SendTo(ByArr, ByArr.Length, SocketFlags.None, RemoteIPoint)
ListBox1.Items.Add(SendInf)
ListBox1.SelectedIndex = ListBox1.Items.Count - 1
Else
MsgBox("请选择一台在线设备或者输入设备的IP地址", MsgBoxStyle.Critical, "提示")
TextBox1.Select()
End If
End Sub
Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
Dim SendStr = "030," & TextBox2.Text.Trim() & ",030-030::030-030," & Format(ComboBox2.SelectedIndex, "0") & ",1," & Format(NumericUpDown1.Value, "0")
CommandSend(SendStr)
End Sub
Private Sub Button10_Click(sender As Object, e As EventArgs) Handles Button10.Click
Dim SendStr = "030," & TextBox2.Text.Trim() & ",030-030::030-030," & Format(ComboBox2.SelectedIndex, "0") & ",0," & Format(NumericUpDown1.Value, "0")
CommandSend(SendStr)
End Sub
Private Sub Button11_Click(sender As Object, e As EventArgs) Handles Button11.Click
Dim SendStr = "009," & TextBox2.Text.Trim() & "," & TextBox5.Text.Trim() & "," & Format(NumericUpDown2.Value, "0") & "," & Format(ComboBox3.SelectedIndex, "0") & "," & Format(ComboBox4.SelectedIndex, "0")
CommandSend(SendStr)
End Sub
Private Sub Button12_Click(sender As Object, e As EventArgs) Handles Button12.Click
Dim SendStr = "040," & TextBox2.Text.Trim() & ",\L(" & ComboBox5.Text.Trim() & ")"
CommandSend(SendStr)
End Sub
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
Dim SendStr = "040," & TextBox2.Text.Trim() & ",\n\n\n\n IC卡消费票据\n--------------------------------\n机号:00008 IP:192.168.2.181\n卡号:0123456789 姓名:张三丰\n本次消费:123.45 元\n"
CommandSend(SendStr)
End Sub
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
If CheckRemoIpPort(TextBox1.Text.Trim()) Then
Form2.ShowDialog()
Else
MsgBox("请选择一台在线设备或者输入设备的IP地址及通讯端口", MsgBoxStyle.Critical, "提示")
TextBox1.Select()
End If
End Sub
Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
Dim sendinf As String
Timer2.Enabled = False
Select Case sendcode
Case "015015"
Sleep(100)
SendAgain = SendAgain + 1
If SendAgain = 3 Then
SendCount = False
Form3.Button8.Text = "将注册卡号传送到设备的顺序区"
Form3.Button9.Enabled = True
Else
If SendPoin <= SendPoinMax And SendCount Then
Timer2.Enabled = True
sendinf = SendBufStr(SendPoin)
CommandSend(sendinf)
End If
End If
Case "016016"
Sleep(150)
SendAgain = SendAgain + 1
If SendAgain = 3 Then
SendCount = False
Form3.Button9.Text = "将注册卡号传送到设备的随机区"
Form3.Button8.Enabled = True
Else
If SendPoin <= SendPoinMax And SendCount Then
Timer2.Interval = 500 + SendPoin * 10 '数据包越多,等待返回的时间需越长。
Timer2.Enabled = True
sendinf = SendBufStr(SendPoin)
CommandSend(sendinf)
End If
End If
End Select
End Sub
Private Sub Button13_Click(sender As Object, e As EventArgs) Handles Button13.Click
If CheckRemoIpPort(TextBox1.Text.Trim()) Then
Form3.ShowDialog()
Else
MsgBox("请选择一台在线设备或者输入设备的IP地址及通讯端口", MsgBoxStyle.Critical, "提示")
TextBox1.Select()
End If
End Sub
Private Sub Button14_Click(sender As Object, e As EventArgs) Handles Button14.Click
Form4.ShowDialog()
End Sub
Private Sub Button15_Click(sender As Object, e As EventArgs) Handles Button15.Click
If CheckRemoIpPort(TextBox1.Text.Trim()) Then
Form5.ShowDialog()
Else
MsgBox("请选择一台在线设备或者输入设备的IP地址及通讯端口", MsgBoxStyle.Critical, "提示")
TextBox1.Select()
End If
End Sub
Public Function GetSTCMAC(ByVal inputstr As String) As String
Dim i As Integer
Dim tempmac, str1 As String
tempmac = "00000000" + Convert.ToInt64(inputstr).ToString("X2")
GetSTCMAC = "16-88"
For i = 1 To 4
str1 = tempmac.Remove(0, tempmac.Length - 2)
tempmac = tempmac.Substring(0, tempmac.Length - 2)
GetSTCMAC = GetSTCMAC + "-" + str1
Next
End Function
Public Function GetCHMAC(ByVal inputstr As String) As String
Dim i As Integer
GetCHMAC = ""
If inputstr.Length >= 16 Then
For i = 0 To 5
GetCHMAC = GetCHMAC + inputstr.Substring(4 + i * 2, 2)
If i < 5 Then GetCHMAC = GetCHMAC + "-"
Next
End If
End Function
Public Function DEC_To_Bin(ByVal indata As Byte) As String
DEC_To_Bin = "00000000" + Convert.ToString(indata, 2)
DEC_To_Bin = DEC_To_Bin.Substring(DEC_To_Bin.Length - 8)
End Function
Private Sub Button16_Click(sender As Object, e As EventArgs) Handles Button16.Click
If CheckRemoIpPort(TextBox1.Text.Trim()) Then
Form6.ShowDialog()
Else
MsgBox("请选择一台在线设备或者输入设备的IP地址及通讯端口", MsgBoxStyle.Critical, "提示")
TextBox1.Select()
End If
End Sub
Private Sub Button17_Click(sender As Object, e As EventArgs) Handles Button17.Click
Dim copstr As String
Dim I As Long
Clipboard.Clear()
copstr = ""
For I = 0 To ListBox1.Items.Count - 1
copstr = copstr & ListBox1.Items(I)
copstr = copstr & vbCrLf
Next
Clipboard.SetText(copstr)
End Sub
Private Sub ComboBox4_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox4.SelectedIndexChanged
VoiceCode = ComboBox4.SelectedIndex.ToString()
End Sub
Private Sub ComboBox3_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox3.SelectedIndexChanged
BeepCode = ComboBox3.SelectedIndex.ToString()
End Sub
Private Sub infparsing(ByVal inputstr As String) '解析读取的实时考勤门禁机参数
Dim dataArray() As String
Dim i As Integer
dataArray = Split(inputstr, "=")
If UBound(dataArray) - LBound(dataArray) = 1 Then
i = Val(dataArray(0))
If Form6.ComboBoxArray(i).DropDownStyle = 2 Then
Form6.ComboBoxArray(i).selectedindex = Val(dataArray(1))
Else
Form6.ComboBoxArray(i).text = dataArray(1)
End If
End If
End Sub
Private Sub Button18_Click(sender As Object, e As EventArgs) Handles Button18.Click
If CheckRemoIpPort(TextBox1.Text.Trim()) Then
Form7.ShowDialog()
Else
MsgBox("请选择一台在线设备或者输入设备的IP地址及通讯端口", MsgBoxStyle.Critical, "提示")
TextBox1.Select()
End If
End Sub
End Class
Public Class ListViewSorter
Implements System.Collections.IComparer
Public Enum EnumSortOrder As Integer
Ascending = 0
Descending = 1
End Enum
Public SortOrder As EnumSortOrder
Public SortColumn As Integer
Public Sub New(ByVal SortColumn As Integer, ByVal SortOrder As EnumSortOrder)
Me.SortColumn = SortColumn
Me.SortOrder = SortOrder
End Sub
Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer Implements IComparer.Compare
Dim xString As String
Dim YString As String
' Convert the two passed values to listview items
Dim l1 As ListViewItem
Dim l2 As ListViewItem
l1 = CType(x, ListViewItem)
l2 = CType(y, ListViewItem)
' Get the appropriate text values depending on whether we are being asked
' to sort on the first column (0) or subitem columns (>0)
If SortColumn = 0 Then
' SortColumn is 0, we need to compare the
' Text property of the Item itself
xString = l1.Text
YString = l2.Text
Else
' SortColumn is not 0, so we need to compare the Text
' property of the SubItem
xString = l1.SubItems(SortColumn).ToString
YString = l2.SubItems(SortColumn).ToString
End If
' Do the comparison
If xString = YString Then
' Values are equal
Return 0
ElseIf xString > YString Then
' X is greater than Y
If SortOrder = EnumSortOrder.Ascending Then
Return 1
Else
Return -1
End If
ElseIf xString < YString Then
' Y is greater than X
If SortOrder = EnumSortOrder.Ascending Then
Return -1
Else
Return 1
End If
End If
End Function
End Class