📄 form5.frm
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form Form5
Caption = "Form5"
ClientHeight = 3195
ClientLeft = 60
ClientTop = 345
ClientWidth = 4680
LinkTopic = "Form5"
ScaleHeight = 3195
ScaleWidth = 4680
StartUpPosition = 3 '窗口缺省
Begin MSCommLib.MSComm MSComm1
Left = 3840
Top = 2280
_ExtentX = 1005
_ExtentY = 1005
_Version = 393216
DTREnable = -1 'True
End
Begin VB.CommandButton Command2
Caption = "返回"
Height = 375
Left = 2280
TabIndex = 7
Top = 2280
Width = 1215
End
Begin VB.CommandButton Command1
Caption = "写入"
Height = 375
Left = 600
TabIndex = 6
Top = 2280
Width = 975
End
Begin VB.TextBox Text4
Height = 495
Left = 120
TabIndex = 5
Top = 0
Width = 4455
End
Begin VB.Frame Frame1
Caption = "数据类型 地址 要写入的数据"
Height = 975
Left = 360
TabIndex = 0
Top = 840
Width = 3495
Begin VB.TextBox Text3
Height = 375
Left = 1920
TabIndex = 3
Top = 480
Width = 1215
End
Begin VB.TextBox Text2
Height = 375
Left = 960
TabIndex = 2
Top = 480
Width = 495
End
Begin VB.TextBox Text1
Height = 375
Left = 360
TabIndex = 1
Top = 480
Width = 375
End
Begin VB.Label Label1
Caption = "="
Height = 255
Left = 1680
TabIndex = 4
Top = 600
Width = 375
End
End
End
Attribute VB_Name = "Form5"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Declare Sub Sleep Lib "kernel32" (ByVal dwseconds As Long)
Private Sub Command1_Click()
Dim str_write(0 To 37) As Byte
Dim str_val(0 To 5) As Byte
Dim Temp_FCS As Variant
Dim dz As Integer
Dim lx As String
Dim llxx As String
Dim haaa As String
Dim shuju As String
dz = Text2.Text
lx = Text1.Text
shuju = ("&H" & Hex(Text3.Text))
If lx = "s" Or lx = "sm" Or lx = "i" Or lx = "q" Or lx = "v" Or lx = "vb" Or lx = "vw" Or lx = "vd" Then
If lx = "s" Then
lxx = &H4
haa = &H1
End If
If lx = "sm" Then
lxx = &H5
haa = &H1
End If
If lx = "i" Then
lxx = &H81
haa = &H1
End If
If lx = "q" Then
lxx = &H82
haa = &H1
End If
If lx = "m" Then
lxx = &H83
haa = &H1
End If
If lx = "v" Then
lxx = &H84
haa = &H1
End If
If lx = "vb" Then
lxx = &H84
haa = &H1
End If
If lx = "vw" Then
lxx = &H84
haa = &H2
End If
If lx = "vd" Then
lxx = &H84
haa = &H4
End If
str_write(0) = &H68
str_write(1) = &H20
str_write(2) = &H20
str_write(3) = &H68
str_write(4) = &H2
str_write(5) = &H0
str_write(6) = &H7C
str_write(7) = &H32
str_write(8) = &H1
str_write(9) = &H0
str_write(10) = &H0
str_write(11) = &H0
str_write(12) = &H0
str_write(13) = &H0
str_write(14) = &HE
str_write(15) = &H0
str_write(16) = &H5
str_write(17) = &H5
str_write(18) = &H1
str_write(19) = &H12
str_write(20) = &HA
str_write(21) = &H10
str_write(22) = &H2
str_write(23) = &H0
str_write(24) = haa
str_write(25) = &H0
str_write(26) = &H1
str_write(27) = lxx
str_write(28) = &H0
str_write(29) = (Str(dz) * 8) \ 256
str_write(30) = (Str(dz) * 8) Mod 256
str_write(31) = &H0
str_write(32) = &H4
str_write(33) = &H0
str_write(34) = &H8
str_write(35) = shuju
For i = 4 To 35
Temp_FCS = Temp_FCS + str_write(i)
Next
str_write(36) = Temp_FCS Mod 256
str_write(37) = &H16
MSComm1.Output = str_write
Sleep (100)
str_val(0) = &H10
str_val(1) = &H2
str_val(2) = &H0
str_val(3) = &H5C
str_val(4) = &H5E
str_val(5) = &H16
MSComm1.Output = str_val
Else:
If MsgBox("数据类型输入错误,正确类型为 S SM I Q M V VB VW VD", 1 + 32 + 0, "关闭") = 1 Then
End If
End If
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Private Sub Form_Load()
MSComm1.CommPort = 1
MSComm1.Settings = "9600,e,8,1"
MSComm1.InputLen = 0
MSComm1.RThreshold = 1
MSComm1.InputMode = comInputModeBinary
MSComm1.PortOpen = True
End Sub
Private Sub MSComm1_OnComm()
Dim rcv_1() As Byte
Dim dis_1 As String
Dim rcv_2 As Long
rcv_1 = MSComm1.Input
rcv_2 = UBound(rcv_1)
ReDim temP(0 To UBound(rcv_1))
For i = 0 To rcv_2
dis_1 = dis_1 & Hex(rcv_1(i)) & ""
Next i
Text4.Text = dis_1
End Sub
Private Sub Text1_Chaange()
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -