📄 低压伺服接收码转换器.frm
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form Form1
BorderStyle = 1 'Fixed Single
Caption = "低压伺服通讯接收码转换器"
ClientHeight = 2835
ClientLeft = 45
ClientTop = 435
ClientWidth = 5010
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 2835
ScaleWidth = 5010
StartUpPosition = 3 'Windows Default
Begin VB.CommandButton Command3
Caption = "退出"
Height = 495
Left = 3000
TabIndex = 9
Top = 2280
Width = 1575
End
Begin VB.CommandButton Command2
Caption = "执行"
BeginProperty Font
Name = "MS Sans Serif"
Size = 9.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 3000
TabIndex = 8
Top = 1680
Width = 1575
End
Begin MSCommLib.MSComm Servo
Left = 2160
Top = 1560
_ExtentX = 1005
_ExtentY = 1005
_Version = 393216
DTREnable = -1 'True
BaudRate = 38400
InputMode = 1
End
Begin VB.CommandButton Command1
Caption = "转换"
BeginProperty Font
Name = "MS Sans Serif"
Size = 9.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 3000
TabIndex = 4
Top = 1080
Width = 1575
End
Begin VB.TextBox Text4
BeginProperty Font
Name = "MS Sans Serif"
Size = 9.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 2280
TabIndex = 3
Text = "0"
Top = 360
Width = 2415
End
Begin VB.TextBox Text3
BeginProperty Font
Name = "MS Sans Serif"
Size = 9.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 240
TabIndex = 2
Text = "0"
Top = 2040
Width = 1575
End
Begin VB.TextBox Text2
BeginProperty Font
Name = "MS Sans Serif"
Size = 9.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 240
TabIndex = 1
Text = "0"
Top = 1200
Width = 1575
End
Begin VB.TextBox Text1
BeginProperty Font
Name = "MS Sans Serif"
Size = 9.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 240
TabIndex = 0
Text = "0"
Top = 360
Width = 1575
End
Begin VB.Label Label3
Caption = "数据"
Height = 255
Left = 240
TabIndex = 7
Top = 1800
Width = 1095
End
Begin VB.Label Label2
Caption = "功能码"
Height = 255
Left = 240
TabIndex = 6
Top = 960
Width = 855
End
Begin VB.Label Label1
Caption = "ID"
Height = 255
Left = 240
TabIndex = 5
Top = 120
Width = 855
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim b0, b1, b2, b3, b4, b5, b6, s As Integer
Dim command(0 To 6) As Byte
Private Sub Command1_Click()
Dim Lon As Byte
If Val(Text3.Text) < 63 And Val(Text3.Text) > -64 Then
Lon = 4
ElseIf Val(Text3.Text) < 8191 And Val(Text3.Text) > -8192 Then
Lon = 5
ElseIf Val(Text3.Text) < 1048575 And Val(Text3.Text) > -1048576 Then
Lon = 6
ElseIf Val(Text3.Text) < 134217727 And Val(Text3.Text) > -134217728 Then
Lon = 7
End If
Select Case Lon
Case 4
b3 = CInt(Val(Text1.Text))
b2 = &H80 + CInt(Val(Text2.Text))
b1 = &H80 + (&H7F And CInt(Val(Text3.Text)))
s = b1 + b2 + b3
b0 = &H80 + s Mod 128
Text4.Text = Hex(b3) & Hex(b2) & Hex(b1) & Hex(b0)
command(0) = b3
command(1) = b2
command(2) = b1
command(3) = b0
command(4) = 0
command(5) = 0
command(6) = 0
Case 5
b4 = CInt(Val(Text1.Text))
b3 = &H80 + &H20 + CInt(Val(Text2.Text))
b2 = &H80 + (&H3F80 And (CInt(Val(Text3.Text)))) / 128
b1 = &H80 + (&H7F And CInt(Val(Text3.Text)))
s = b1 + b2 + b3 + b4
b0 = &H80 + s Mod 128
Text4.Text = Hex(b4) & Hex(b3) & Hex(b2) & Hex(b1) & Hex(b0)
command(0) = b4
command(1) = b3
command(2) = b2
command(3) = b1
command(4) = b0
command(5) = 0
command(6) = 0
Case 6
b5 = Val(Text1.Text)
b4 = &H80 + &H40 + CInt(Val(Text2.Text))
b3 = &H80 + (&H1FC000 And (CLng(Val(Text3.Text)))) / 16384
b2 = &H80 + (&H3F80 And (CLng(Val(Text3.Text)))) / 128
b1 = &H80 + (&H7F And CLng(Val(Text3.Text)))
s = b1 + b2 + b3 + b4 + b5
b0 = &H80 + s Mod 128
Text4.Text = Hex(b5) & Hex(b4) & Hex(b3) & Hex(b2) & Hex(b1) & Hex(b0)
command(0) = b5
command(1) = b4
command(2) = b3
command(3) = b2
command(4) = b1
command(5) = b0
command(6) = 0
Case 7
b6 = Val(Text1.Text)
b5 = &H80 + &H60 + CInt(Val(Text2.Text))
b4 = &H80 + (&HFE00000 And (CLng(Val(Text3.Text)))) / 16384 / 128
b3 = &H80 + (&H1FC000 And (CLng(Val(Text3.Text)))) / 16384
b2 = &H80 + (&H3F80 And (CLng(Val(Text3.Text)))) / 128
b1 = &H80 + (&H7F And CLng(Val(Text3.Text)))
s = b1 + b2 + b3 + b4 + b5 + b6
b0 = &H80 + s Mod 128
Text4.Text = Hex(b6) & Hex(b5) & Hex(b4) & Hex(b3) & Hex(b2) & Hex(b1) & Hex(b0)
command(0) = b6
command(1) = b5
command(2) = b4
command(3) = b3
command(4) = b2
command(5) = b1
command(6) = b0
End Select
Command2.Enabled = True
End Sub
Private Sub Command2_Click()
Servo.Output = command
End Sub
Private Sub Command3_Click()
If Servo.PortOpen = True Then
Servo.PortOpen = False
End If
End
End Sub
Private Sub Form_Load()
If Servo.PortOpen = False Then
Servo.PortOpen = True
End If
Command2.Enabled = False
End Sub
Private Sub Form_Unload(Cancel As Integer)
If Servo.PortOpen = True Then
Servo.PortOpen = False
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -