📄 rs485.frm
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form Form3
BackColor = &H00C0C000&
Caption = "RS-485----R & D Labs"
ClientHeight = 8310
ClientLeft = 165
ClientTop = 450
ClientWidth = 11880
ForeColor = &H00000000&
LinkTopic = "Form2"
ScaleHeight = 8310
ScaleWidth = 11880
StartUpPosition = 3 '窗口缺省
Begin MSCommLib.MSComm MSComm2
Left = 600
Top = 6480
_ExtentX = 1005
_ExtentY = 1005
_Version = 393216
DTREnable = -1 'True
End
Begin VB.CommandButton Command1
Caption = "计算"
Height = 375
Left = 7200
TabIndex = 13
Top = 1320
Width = 855
End
Begin VB.CommandButton Command2
Caption = "发送"
Height = 375
Left = 5640
TabIndex = 12
Top = 3600
Width = 855
End
Begin VB.CommandButton Command4
Caption = "采集"
Height = 375
Left = 2520
TabIndex = 11
Top = 1800
Width = 1575
End
Begin VB.Timer Timer1
Enabled = 0 'False
Interval = 1000
Left = 720
Top = 0
End
Begin MSCommLib.MSComm MSComm1
Left = 0
Top = 0
_ExtentX = 1005
_ExtentY = 1005
_Version = 393216
DTREnable = -1 'True
RTSEnable = -1 'True
End
Begin VB.Label T1
Alignment = 2 'Center
Appearance = 0 'Flat
BackColor = &H8000000A&
Caption = "AD1 "
ForeColor = &H80000008&
Height = 495
Left = 720
TabIndex = 10
Top = 2400
Width = 1575
End
Begin VB.Label P1
Alignment = 2 'Center
Appearance = 0 'Flat
BackColor = &H80000005&
Caption = "AD2 "
ForeColor = &H80000008&
Height = 495
Left = 720
TabIndex = 9
Top = 3120
Width = 1575
End
Begin VB.Label flow1
Alignment = 2 'Center
Appearance = 0 'Flat
BackColor = &H80000005&
Caption = "AD3 "
ForeColor = &H80000008&
Height = 495
Left = 720
TabIndex = 8
Top = 3840
Width = 1575
End
Begin VB.Label heat
Alignment = 2 'Center
Appearance = 0 'Flat
BackColor = &H80000005&
BorderStyle = 1 'Fixed Single
Caption = "AD4 "
ForeColor = &H80000008&
Height = 495
Left = 720
TabIndex = 7
Top = 4560
Width = 1575
End
Begin VB.Label aflow1
BorderStyle = 1 'Fixed Single
Caption = " "
Height = 495
Left = 6960
TabIndex = 6
Top = 1800
Width = 1575
End
Begin VB.Label Label3
Alignment = 2 'Center
BorderStyle = 1 'Fixed Single
Caption = " "
Height = 495
Left = 2520
TabIndex = 5
Top = 3840
Width = 1575
End
Begin VB.Label Label1
Alignment = 2 'Center
BorderStyle = 1 'Fixed Single
Caption = " "
Height = 495
Left = 2520
TabIndex = 4
Top = 2400
Width = 1575
End
Begin VB.Label Label2
Alignment = 2 'Center
BorderStyle = 1 'Fixed Single
Caption = " "
Height = 495
Left = 2520
TabIndex = 3
Top = 3120
Width = 1575
End
Begin VB.Label Label4
Alignment = 2 'Center
BorderStyle = 1 'Fixed Single
Caption = " "
Height = 495
Left = 2520
TabIndex = 2
Top = 4560
Width = 1575
End
Begin VB.Label Label5
BorderStyle = 1 'Fixed Single
Caption = " "
Height = 495
Left = 4440
TabIndex = 1
Top = 4560
Width = 5055
End
Begin VB.Label date1
Alignment = 2 'Center
BackColor = &H00800000&
BorderStyle = 1 'Fixed Single
Caption = " "
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00FFFFFF&
Height = 375
Left = 9120
TabIndex = 0
Top = 0
Width = 2655
End
End
Attribute VB_Name = "Form3"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub communication1() 'RS-485串口通讯
Dim Dummy As Integer
Dim i As Integer
MSComm1.CommPort = 1 ' Use COM1.
' 9600 baud, no parity, 8 data, and 1 stop bit.
MSComm1.Settings = "9600,n,8,1"
' Tell the control to read entire buffer when Input is used.
MSComm1.InputLen = 0
MSComm1.PortOpen = True ' Open the port.
MSComm1.InBufferCount = 0
MSComm1.Output = Chr$(&H23) '#
Delay10
MSComm1.Output = Chr$(&H30) '0
Delay10
MSComm1.Output = Chr$(&H31) '1
Delay10
MSComm1.Output = Chr$(&H30) '0
Delay10
' Wait for data to come back to the serial port.
i = 0
Do
Dummy = DoEvents()
i = i + 1
Loop Until MSComm1.InBufferCount >= 39 Or i > 30000
' Read the "OK" response data in the serial port.
inst = MSComm1.Input
MSComm1.PortOpen = False ' Close the serial port.
Label1.Caption = Mid(inst, 7, 5) '显示通道1电压
Label2.Caption = Mid(inst, 16, 5) '显示通道2电压
Label3.Caption = Mid(inst, 25, 5) '显示通道3电压
Label4.Caption = Mid(inst, 34, 5) '显示通道4电压
Label5.Caption = inst
End Sub
Private Sub Delay10()
Dim i As Integer
For i = 0 To 30000
Next i
End Sub
Private Sub Command2_Click()
MSComm2.CommPort = 2 ' Use COM2.
' 9600 baud, no parity, 8 data, and 1 stop bit.
MSComm2.Settings = "9600,n,8,1"
' Tell the control to read entire buffer when Input is used.
MSComm2.InputLen = 0
MSComm2.PortOpen = True ' Open the port.
MSComm2.InBufferCount = 0
MSComm2.Output = Chr$(&H30) '0 发0123
MSComm2.Output = Chr$(&H31) '1
MSComm2.Output = Chr$(&H32) '2
MSComm2.Output = Chr$(&H33) '3
MSComm2.PortOpen = False ' Close the serial port.
End Sub
Private Sub Command4_Click()
Timer1.Enabled = True
End Sub
Private Sub fheat_Click()
End Sub
Private Sub Timer1_Timer()
Dim cminute As String
date1.Caption = Now '显示当前日期时间
NowTime = Time$ '取当前时间
sec = Mid$(NowTime, 7, 2) '取当前秒
cminute = Minute(NowTime) '取当前分
communication1 '通讯
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -