📄 frmsignaladjust.frm
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form FrmSimularAdjust
BorderStyle = 3 'Fixed Dialog
Caption = "模拟量校准"
ClientHeight = 2835
ClientLeft = 45
ClientTop = 405
ClientWidth = 8820
Icon = "FrmSignalAdjust.frx":0000
LinkTopic = "Form2"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 2835
ScaleWidth = 8820
ShowInTaskbar = 0 'False
StartUpPosition = 2 'CenterScreen
Begin VB.CommandButton Command2
Caption = "下传"
Height = 375
Index = 5
Left = 7920
TabIndex = 18
Top = 1560
Width = 615
End
Begin VB.CommandButton Command2
Caption = "下传"
Height = 375
Index = 4
Left = 3600
TabIndex = 17
Top = 1560
Width = 615
End
Begin VB.CommandButton Command2
Caption = "下传"
Height = 375
Index = 3
Left = 7920
TabIndex = 16
Top = 960
Width = 615
End
Begin VB.CommandButton Command2
Caption = "下传"
Height = 375
Index = 2
Left = 3600
TabIndex = 15
Top = 960
Width = 615
End
Begin VB.CommandButton Command2
Caption = "下传"
Height = 375
Index = 1
Left = 7920
TabIndex = 14
Top = 360
Width = 615
End
Begin VB.CommandButton Command2
Caption = "下传"
Height = 375
Index = 0
Left = 3600
TabIndex = 13
Top = 360
Width = 615
End
Begin MSCommLib.MSComm MSComm
Left = 360
Top = 2400
_ExtentX = 1005
_ExtentY = 1005
_Version = 393216
DTREnable = -1 'True
End
Begin VB.TextBox Text1
Enabled = 0 'False
Height = 375
Index = 5
Left = 6120
TabIndex = 12
Top = 1560
Width = 1575
End
Begin VB.TextBox Text1
Enabled = 0 'False
Height = 375
Index = 4
Left = 1800
TabIndex = 11
Top = 1560
Width = 1575
End
Begin VB.TextBox Text1
Enabled = 0 'False
Height = 375
Index = 3
Left = 6120
TabIndex = 10
Top = 960
Width = 1575
End
Begin VB.TextBox Text1
Enabled = 0 'False
Height = 375
Index = 2
Left = 1800
TabIndex = 9
Top = 960
Width = 1575
End
Begin VB.TextBox Text1
Enabled = 0 'False
Height = 375
Index = 1
Left = 6120
TabIndex = 8
Top = 360
Width = 1575
End
Begin VB.CommandButton Command1
Caption = "完成"
Height = 375
Left = 7560
TabIndex = 4
Top = 2280
Width = 975
End
Begin VB.TextBox Text1
Enabled = 0 'False
Height = 375
Index = 0
Left = 1800
TabIndex = 3
Top = 350
Width = 1575
End
Begin VB.Label Label6
Caption = "模拟量3校满值:"
Height = 375
Left = 4560
TabIndex = 7
Top = 1575
Width = 1455
End
Begin VB.Label Label5
Caption = "模拟量2校满值:"
Height = 375
Left = 4560
TabIndex = 6
Top = 975
Width = 1455
End
Begin VB.Label Label4
Caption = "模拟量1校满值:"
Height = 375
Left = 4560
TabIndex = 5
Top = 375
Width = 1455
End
Begin VB.Label Label3
Caption = "模拟量3校0值:"
Height = 375
Left = 360
TabIndex = 2
Top = 1560
Width = 1335
End
Begin VB.Label Label2
Caption = "模拟量2校0值:"
Height = 375
Left = 360
TabIndex = 1
Top = 960
Width = 1335
End
Begin VB.Label Label1
Caption = "模拟量1校0值:"
Height = 375
Left = 360
TabIndex = 0
Top = 360
Width = 1335
End
End
Attribute VB_Name = "FrmSimularAdjust"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim flag As Boolean
Private Sub Command1_Click()
If HardwareType < 8 Or HardwareType = 10 Or HardwareType = 11 Then
M1_0 = Val(Text1(0).Text)
M1_Full = Val(Text1(1).Text)
FrmSysReg.Text1(8).Text = FrmSimularAdjust.Text1(0).Text
FrmSysReg.Text1(9).Text = FrmSimularAdjust.Text1(1).Text
ElseIf HardwareType < 10 Then
M1_0 = Val(Text1(0).Text)
M1_Full = Val(Text1(1).Text)
M2_0 = Val(Text1(2).Text)
M2_Full = Val(Text1(3).Text)
M3_0 = Val(Text1(4).Text)
M3_Full = Val(Text1(5).Text)
FrmSysReg.Text1(8).Text = FrmSimularAdjust.Text1(0).Text
FrmSysReg.Text1(9).Text = FrmSimularAdjust.Text1(1).Text
FrmSysReg.Text1(10).Text = FrmSimularAdjust.Text1(2).Text
FrmSysReg.Text1(11).Text = FrmSimularAdjust.Text1(3).Text
FrmSysReg.Text1(12).Text = FrmSimularAdjust.Text1(4).Text
FrmSysReg.Text1(13).Text = FrmSimularAdjust.Text1(5).Text
ElseIf HardwareType = 12 Then
M1_0 = Val(Text1(0).Text)
M1_Full = Val(Text1(1).Text)
M2_0 = Val(Text1(2).Text)
M2_Full = Val(Text1(3).Text)
FrmSysReg.Text1(8).Text = FrmSimularAdjust.Text1(0).Text
FrmSysReg.Text1(9).Text = FrmSimularAdjust.Text1(1).Text
FrmSysReg.Text1(10).Text = FrmSimularAdjust.Text1(2).Text
FrmSysReg.Text1(11).Text = FrmSimularAdjust.Text1(3).Text
End If
FrmSysReg.Command1(0).Enabled = True
Unload Me
End Sub
Private Sub Command2_Click(Index As Integer)
Dim i As Byte
Dim temp As Long
If Text1(Index).Text = "" Then
MsgBox "校准值不能为空", , "提示"
Exit Sub
End If
Select Case Index
Case 0, 1
DataArr(0) = MTID
DataArr(1) = &H66
DataArr(2) = &H3
DataArr(3) = &H7
DataArr(4) = Val(Text1(Index).Text) \ 256
DataArr(5) = Val(Text1(Index).Text) Mod 256
MSComm.RThreshold = 8
For i = 0 To 5
SendBuf(i) = DataArr(i)
Next i
Case 2, 3
DataArr(0) = MTID
DataArr(1) = &H66
DataArr(2) = &H3
DataArr(3) = &H8
DataArr(4) = Val(Text1(Index).Text) \ 256
DataArr(5) = Val(Text1(Index).Text) Mod 256
MSComm.RThreshold = 8
For i = 0 To 5
SendBuf(i) = DataArr(i)
Next i
Case 4, 5
DataArr(0) = MTID
DataArr(1) = &H66
DataArr(2) = &H3
DataArr(3) = &H9
DataArr(4) = Val(Text1(Index).Text) \ 256
DataArr(5) = Val(Text1(Index).Text) Mod 256
MSComm.RThreshold = 8
For i = 0 To 5
SendBuf(i) = DataArr(i)
Next i
End Select
temp = CRC16(6)
SendBuf(6) = CrcDataHI
SendBuf(7) = CrcDataLO
SendLen = 8
ModbusTrans
End Sub
Private Sub Form_Load()
If HardwareType < 8 Or HardwareType = 10 Or HardwareType = 11 Then
Text1(0).Enabled = True
Text1(1).Enabled = True
ElseIf HardwareType < 10 Then
Text1(0).Enabled = True
Text1(1).Enabled = True
Text1(2).Enabled = True
Text1(3).Enabled = True
Text1(4).Enabled = True
Text1(5).Enabled = True
ElseIf HardwareType = 12 Then
Text1(0).Enabled = True
Text1(1).Enabled = True
Text1(2).Enabled = True
Text1(3).Enabled = True
End If
flag = False
InitMscomm
End Sub
Private Sub Form_Unload(Cancel As Integer)
SendDataReady
FrmSimularAdjust.MSComm.PortOpen = False
FrmSysReg.MSComm.PortOpen = True
End Sub
Private Sub ModbusTrans()
Dim i As Byte
Dim Buf As String
On Error GoTo sendfailed
Buf = String(SendLen, Chr(0))
outbyte = StrConv(Buf, vbFromUnicode)
For i = 0 To SendLen - 1
outbyte(i) = SendBuf(i)
Next i
MSComm.Output = outbyte
Exit Sub
sendfailed:
Err.Clear
End Sub
Private Sub InitMscomm()
On Error GoTo ErrorHandler
With MSComm
.CommPort = COMport
If .PortOpen = True Then
.PortOpen = False
End If
.Settings = COMbaud + ",n,8,1"
.InputMode = comInputModeBinary '设置或返回 Input 属性取回的数据的类型,文本形式或二进制形式
.NullDiscard = False '确定 null 字符是否从端口传送到接收缓冲区
.InBufferSize = 1000 '设置并返回接收缓冲区的字节数。
.OutBufferSize = 1000 '设置并返回发送缓冲区的字节数。
.InBufferCount = 0 '返回接收缓冲区中等待的字符数。属性设置为 0 来清除接收缓冲区。
.OutBufferCount = 0 '返回在传输缓冲区中等待的字符数。 设置 OutBufferCount 属性为 0 可以清除传输缓冲区。
.InputLen = 0 '设置并返回 Input 属性从接收缓冲区读取的字符数
'设置 InputLen 为 0 时,使用 Input 将使 MSComm 控件读取接收缓冲区中全部的内容。
.SThreshold = 0
.RThreshold = 0 '设置并返回的要接收的字符数。 并将产生 OnComm的omEvReceive事件
.PortOpen = True
End With
Exit Sub
ErrorHandler:
MsgBox "串口" + Str(COMport) + " 打开失败", vbCritical '+ vbCrLf + "无此串口或串口已打开"
End Sub
Private Sub SendDataReady()
Dim i As Byte
Dim temp As Long
DataArr(0) = MTID
DataArr(1) = &H66
DataArr(2) = &H3
DataArr(3) = &H0
DataArr(4) = &H0
DataArr(5) = &H1
MSComm.RThreshold = 8
For i = 0 To 5
SendBuf(i) = DataArr(i)
Next i
temp = CRC16(6)
SendBuf(6) = CrcDataHI
SendBuf(7) = CrcDataLO
SendLen = 8
ModbusTrans
End Sub
Private Sub MSComm_OnComm()
Dim i As Byte
On Error GoTo ErrHandler1
With MSComm
Select Case .CommEvent
Case comEvReceive
.RThreshold = 0
inputbyte = .Input
Reclen = 0
For i = LBound(inputbyte) To UBound(inputbyte)
RecBuf(Reclen) = inputbyte(i)
DataArr(Reclen) = RecBuf(Reclen)
Reclen = Reclen + 1
Next i
CRC16 (Reclen - 2)
If flag = True Then
If (RecBuf(Reclen - 2) = CrcDataHI) And (RecBuf(Reclen - 1) = CrcDataLO) Then
If RecBuf(0) = MTID And Reclen = 8 Then
MsgBox "成功退出工厂校准模式", , "提示"
Unload Me
Else
MsgBox "退出工厂校准模式失败", , "提示"
End If
Else
MsgBox "退出工厂校准模式失败", , "提示"
End If
End If
End Select
End With
Exit Sub
ErrHandler1:
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -