'送指令
Private Sub SendStringToDevice(LineText As String)
Dim Temp1 As String, L As Integer, i As Integer, K As Integer, A As String
L = Len(LineText)
For i = 1 To L
A = Mid(LineText, i, 1)
Call SendSigleKey(Asc(A))
Next i
End Sub
Private Sub SendSigleKey(KeyAscii As Integer)
On Error GoTo 1
If KeyAscii = 13 Then
'Text2.Text = ""
Winsock1.SendData Chr(13)
KeyAscii = 0
Else
Winsock1.SendData Chr(KeyAscii)
'DoEvents 注释不注释没有区别
End If
Exit Sub
1 KeyAscii = 0
End Sub
'获得和显示数据
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim strbuf As String
Winsock1.GetData strbuf, vbString
Text1.Text = Text1.Text & strbuf
End Sub
'*****************************************************************************
' 为解决HLR41、42的问题,增加的代码
'*****************************************************************************
Function Inkey() As Byte
Dim b As Byte
'循环等待服务器端的数据
While Winsock1.BytesReceived = 0
Nop
Wend
'获得服务器端数据,每次获得一个字节
Winsock1.GetData b
'返回获得的字节
Inkey = b
End Function
'控操作过程,以等待服务器端的数据
Sub Nop()
DoEvents: DoEvents: DoEvents: DoEvents: DoEvents: DoEvents: DoEvents:
DoEvents: DoEvents
End Sub
Function VVV(D$)
'将字符串转换成数值
VVV = Val(D$)
'然后去除被转换成数值的字符串
D$ = Mid$(D$, InStr(D$ + ";", ";") + 1)
End Function
Sub SendChars(D$)
Dim b As Byte
While D$ <> ""
b = VVV(D$)
'然后发送该字节
Winsock1.SendData b
Wend
End Sub
Sub ttt()
Dim b As Byte, LL
Dim C, D, V, xx, yy As Byte
Dim X, Y, L, F, T As Integer
Dim s$, dat$, p&
While Winsock1.BytesReceived > 0
'DoEvents
b = Inkey
'分析得到的字节数据
Select Case b
Case 255
'255表示的是命令的先导字符,即后面的数据是命令
'接着获得后面两个字节的数据,分别放在变量c和d中
C = Inkey
D = Inkey
'如果c为253,表示发出do命令,服务器提出要求协商
If C = 253 Then 'And (D = 1 Or D = 24)
SendChars "255;251;" & D
GoTo L2
End If
'如果c为254,表示拒绝接收
If C = 254 And D = 1 Then
SendChars "255;252;1"
GoTo L2
End If
'如果为251 ,表示愿意激活某个选项
If C = 251 And D = 1 Then
SendChars "255;254;1"
GoTo L2
End If
'如果是250,表示的是子协商选项
If C = 250 Then
'循环等到d等于240,表示子协商结束
While D <> 240
D = Inkey
Wend
SendChars "255;250;24;0;118;116;49;48;48;255;240"
GoTo L2
End If
'如果是253,发出do命令
' If C = 253 Then
' SendChars "255;252;" & D
' GoTo L2
' End If
End Select
L2: Wend
'Connectdd = True
End Sub 作者:
Nothing 时间: 2006-12-30 19:38