⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test_dy11.frm

📁 This is a test ModBus comm s pragam in "STB-311".
💻 FRM
📖 第 1 页 / 共 4 页
字号:
End Sub

Private Sub Command6_Click()
On Error Resume Next
MSComm1.Settings = Combo4.Text
MSComm1.PortOpen = False
MSComm1.CommPort = Combo1.ListIndex + 1
MSComm1.PortOpen = True

End Sub

Private Sub Command7_Click()
Dim S() As Byte
Dim S2 As String
Dim A As String
Dim S3 As String
Dim address  As Integer
address = Val(Text3.Text)
S = ZhiliuInit(address) '合闸
A = S
For i = 1 To LenB(A)
          If AscB(MidB(A, i, 1)) > 15 Then SSS1 = SSS1 + Hex(AscB(MidB(A, i, 1))) + " "
          If AscB(MidB(A, i, 1)) < 16 Then SSS1 = SSS1 + "0" + Hex(AscB(MidB(A, i, 1))) + " "
Next i
   If Check1.Value = 0 Then List1.Clear
   List1.AddItem SSS1
   List1.ListIndex = List1.ListCount - 1
 MSComm1.Output = S

End Sub


Private Sub Command8_Click()
Dim S() As Byte
Dim S2 As String
Dim A As String
Dim S3 As String
Dim address  As Integer
Dim Point As Integer
address = Val(Text3.Text)
Point = Val(Text6.Text)
 Main_In_String(1) = ""

S = TEST_ModBus2
A = S
For i = 1 To LenB(A)
          If AscB(MidB(A, i, 1)) > 15 Then SSS1 = SSS1 + Hex(AscB(MidB(A, i, 1))) + " "
          If AscB(MidB(A, i, 1)) < 16 Then SSS1 = SSS1 + "0" + Hex(AscB(MidB(A, i, 1))) + " "
Next i
   If Check1.Value = 0 Then List1.Clear
   List1.AddItem SSS1
   List1.ListIndex = List1.ListCount - 1
 
End Sub

Private Sub Command9_Click()
Dim S() As Byte
Dim S2 As String
Dim A As String
Dim S3 As String
Dim address  As Integer
Dim Point As Integer
address = Val(Text3.Text)
Point = Val(Text6.Text)
 Main_In_String(1) = ""

S = AEC_HZ(address, Point, 0)  '合闸
A = S
For i = 1 To LenB(A)
          If AscB(MidB(A, i, 1)) > 15 Then SSS1 = SSS1 + Hex(AscB(MidB(A, i, 1))) + " "
          If AscB(MidB(A, i, 1)) < 16 Then SSS1 = SSS1 + "0" + Hex(AscB(MidB(A, i, 1))) + " "
Next i
   If Check1.Value = 0 Then List1.Clear
   List1.AddItem SSS1
   List1.ListIndex = List1.ListCount - 1
 MSComm1.Output = S
 

End Sub

Private Sub Form_Load()
' Read_leixing
' Read_Unit
 MSFlexGrid3.ColWidth(0) = 1500
' For i = 1 To 32
'    Read_Dz_Num (i)
'    Read_CL_Num (i)
'    Read_bj_name (i)
'  Next i
'MSComm1.PortOpen = True
Combo1.ListIndex = 0
Combo2.ListIndex = 0
With MSFlexGrid2
.Row = 0
 .Col = 0
 .Text = "序号"
 .Col = 1
 .Text = "名称"
 .Col = 2
 .Text = "定值"
End With
With MSFlexGrid1(3)
.Col = 0
For i = 1 To 4
.Row = i
.Text = "积分电度"
Next i
For i = 5 To 6
.Row = i
.Text = "脉冲电度"
Next i
.Col = 1
For i = 1 To 2
.Row = i
.Text = "正"
.Row = i + 2
.Text = "负"
Next i
.Row = 5
.Text = "正"
.Row = 6
.Text = "负"

.Col = 2
For i = 1 To 3
.Row = i * 2 - 1
.Text = "有功"
.Row = i * 2
.Text = "无功"
Next i
For i = 0 To 2
.Row = 0
.Col = i
.Text = "          电度名称"
Next i
.Col = 3
.Text = "单元读数"
.Col = 4
.Text = "整定值"
.MergeCells = flexMergeFree
.MergeRow(0) = True
.MergeCol(0) = True
.MergeCol(1) = True
End With
With MSFlexGrid1(1)
.ColWidth(0) = 700
.ColWidth(1) = 2500
.ColWidth(2) = 2500
.Row = 0
.Col = 1
.Text = "时间"
.Col = 2
.Text = "名称"
.Col = 3
.Text = "状态"
.Col = 0
.Text = "序号"

For i = 1 To 8
.Row = i
.Text = Str(i)
Next i
End With

End Sub

Private Sub Label3_Change()
Timer1.Interval = Val(Label3.Caption)
End Sub


Private Sub MSFlexGrid1_Click(Index As Integer)
If MSFlexGrid1(3).Col = 4 Then
Text1.Text = "  " + Trim(MSFlexGrid1(3).Text)
    Text1.SelStart = 1
    Text1.Move MSFlexGrid1(3).CellLeft + MSFlexGrid1(3).Left, MSFlexGrid1(3).CellTop + MSFlexGrid1(3).Top, MSFlexGrid1(3).CellWidth, MSFlexGrid1(3).CellHeight + 40
    Text1.Visible = True
    Text1.SetFocus
    Set_Focus Text1
End If
End Sub

Private Sub MSFlexGrid2_Click()
Dim i As Integer
Dim Temp_Page As Integer
Dim Temp_Weizhi As Integer

Dim Addr As Integer
Dim Dy_type As Integer
Dim b As Integer

Addr = Val(Text3.Text)
If Addr = 0 Then Exit Sub
Dy_type = Danyuan(Val(Text3.Text)).Dy_type
SSS = Dingzhi_String(Addr)

 Label4.Caption = Danyuan(Val(Text3.Text)).Dy_Name
XC_Page = Dingzhi(Dy_type, MSFlexGrid2.Row).Dz_Page
XC_Weizhi = Dingzhi(Dy_type, MSFlexGrid2.Row).Dz_St
Label8.Caption = XC_Page
Label9.Caption = XC_Weizhi
With MSFlexGrid2
.Col = 1
Label6.Caption = Trim(.Text)
.Col = 2
Label11.Caption = .Text
Text5.Text = .Text
End With
XC_XS = Dingzhi(Dy_type, MSFlexGrid2.Row).Dz_Xishu
Text4.Text = XC_XS

End Sub

Private Sub Text1_Change()
MSFlexGrid1(3).Text = Text1.Text
End Sub

Private Sub Text1_LostFocus()
Text1.Visible = False
End Sub



Private Sub Text2_Change()

End Sub

Private Sub Text5_Click()
If Text5.Text = "OFF" Then
  Text5.Text = "ON"
Else
  If Text5.Text = "ON" Then Text5.Text = "OFF"
End If
End Sub

Private Sub Timer1_Timer()
Dim A() As Byte
Dim S As String
Dim SSS1 As String
Dim SSS As String
Dim temp_string As String
Dim Com_B As Integer
Dim address As Integer
If MSComm1.InBufferCount < 1 Then Exit Sub
If Check1.Value = 0 Then Text2.Text = ""
A = MSComm1.Input
S = A
  For i = 1 To LenB(S)
          If AscB(MidB(S, i, 1)) > 15 Then SSS1 = SSS1 + Hex(AscB(MidB(S, i, 1))) + " "
          If AscB(MidB(S, i, 1)) < 16 Then SSS1 = SSS1 + "0" + Hex(AscB(MidB(S, i, 1))) + " "
   Next i
    Text2 = Text2 + SSS1
Label13.Caption = LenB(S)

Main_In_String(1) = Main_In_String(1) + S
 
 
 
If LenB(Main_In_String(1)) > 1 Then

 For i = 2 To LenB(Main_In_String(1))
  If (AscB(MidB(Main_In_String(1), i, 1)) = &H90) And (AscB(MidB(Main_In_String(1), i - 1, 1)) = &HEB) Then
     S_long = AscB(MidB(Main_In_String(1), i + 1, 1))
      If S_long <= AscB(MidB(Main_In_String(1), i + 1)) Then
       Com_B = AscB(MidB(Main_In_String(1), i + 4, 1))
       address = AscB(MidB(Main_In_String(1), i + 2, 1))
       temp_string = MidB(Main_In_String(1), i - 1, S_long + 2)
       
'       Main_In_String(1) = ""
       Main_In_String(1) = MidB(Main_In_String(1), i + S_long + 1)

       S = temp_string
      Call Read_In_String(temp_string)
       Select Case Com_B
       Case 0
   Case 1
       With MSFlexGrid2
       Dy_type = Danyuan(address).Dy_type
       
       b = Dingzhi_Num(Dy_type)
       .Rows = b + 1
        For M = 1 To b
           .Row = M
           .Col = 0
           .Text = Str(M)
           .Col = 1
 .Text = Dingzhi(Dy_type, M).dz_name
 .Col = 2
 If Dingzhi(Dy_type, M).Dz_Datatype = 1 Then
  SSS = Dingzhi_String(address)
  If SSS <> "" Then
  
     If AscB(MidB(SSS, Dingzhi(Dy_type, M).Dz_Seg, 1)) > 15 Then temp_dz = Val("&h" + Hex$(AscB(MidB(SSS, Dingzhi(Dy_type, M).Dz_Seg + 1, 1))) + Hex$(AscB(MidB(SSS, Dingzhi(Dy_type, M).Dz_Seg, 1))))
   If AscB(MidB(SSS, Dingzhi(Dy_type, M).Dz_Seg, 1)) < 16 Then temp_dz = Val("&h" + Hex$(AscB(MidB(SSS, Dingzhi(Dy_type, M).Dz_Seg + 1, 1))) + "0" + Hex$(AscB(MidB(SSS, Dingzhi(Dy_type, M).Dz_Seg, 1))))
   Else
   Exit Sub
  End If
  
  Select Case Dingzhi(Dy_type, M).Dz_Xishu
  Case 0.1
   .Text = Format(temp_dz * Dingzhi(Dy_type, M).Dz_Xishu, "0.0")
  Case 0.01
   .Text = Format(temp_dz * Dingzhi(Dy_type, M).Dz_Xishu, "0.00")
   Case Else
   .Text = temp_dz * Dingzhi(Dy_type, M).Dz_Xishu
  End Select
  
 Else
  If SSS <> "" Then temp_dz = Val(AscB(MidB(SSS, Dingzhi(Dy_type, M).Dz_Seg, 1)))
      If temp_dz = 1 Then
       .Text = "ON"
       Else
       .Text = "OFF"
       End If
 End If
 Next M
End With
SSTab1.Tab = 0
Case &HEA
SSTab1.Tab = 1
With MSFlexGrid1(1)
For T = 1 To 8
 .Row = T
 .Col = 1
 .Text = Format(Danyuan_SOE(address, T).shi, "00") + "时" + Format(Danyuan_SOE(address, T).Fen, "00") + "分" + Format(Danyuan_SOE(address, T).miao, "00") + "秒" + Format(Danyuan_SOE(address, T).haomiao * 5, "00") + "毫秒"
 If Danyuan_SOE(address, T).Yaoxin <> 0 Then
 .Col = 2
  .Text = "遥信" + Format(Danyuan_SOE(address, T).Yaoxin, "0")
  .Col = 3
  If Danyuan_SOE(address, T).Yaoxin_bianwei = 255 Then .Text = "分"
  If Danyuan_SOE(address, T).Yaoxin_bianwei = 0 Then .Text = "合"
 Else
 .Col = 2
 MMM = qiumi(Danyuan_SOE(address, T).baojing)
 If address < Danyuanshu Then .Text = Unit_bj(Danyuan(address).Dy_type).Bj_Name(MMM)
 '.Col = 3
 '.Text = Unit_bj(Danyuan(Address).Dy_type).Bj_Name(MMM)
 '.MergeCells = flexMergeFree
 '.MergeRow(T) = True
 End If
   
Next T
  
End With

  Case &H19
       SSTab1.Tab = 3
       For Z = 1 To 2
           With MSFlexGrid1(3)
           .Row = Z + 4
           .Col = 3
           .Text = Maichong_diandu(address).Diandu(Z)
           .Col = 4
           .Text = Maichong_diandu(address).Diandu(Z)
           End With
       Next Z
       Case &H1A
        SSTab1.Tab = 3
         For Z = 1 To 4
           With MSFlexGrid1(3)
           
           .Row = Z
           .Col = 3
           .Text = Jifen_diandu(address).Diandu(Z)
           .Col = 4
           .Text = Jifen_diandu(address).Diandu(Z)
           End With
       Next Z
     End Select
     End If
     Exit For
  End If
  Next i
 End If
End Sub

Private Sub Timer2_Timer()
Dim A() As Byte
Dim S As String
Dim SSS1 As String
Dim SSS As String
Dim temp_string As String
Dim Com_B As Integer
Dim address As Integer
Dim Temp_Integer As Integer
Dim Temp_single As Single
Dim temp_Bool As Boolean
If MSComm1.InBufferCount < 1 Then Exit Sub
If Check1.Value = 0 Then Text2.Text = ""
A = MSComm1.Input
S = A
  For i = 1 To LenB(S)
          If AscB(MidB(S, i, 1)) > 15 Then SSS1 = SSS1 + Hex(AscB(MidB(S, i, 1))) + " "
          If AscB(MidB(S, i, 1)) < 16 Then SSS1 = SSS1 + "0" + Hex(AscB(MidB(S, i, 1))) + " "
   Next i
    Text2 = Text2 + SSS1
Label13.Caption = LenB(S)

Main_In_String(1) = Main_In_String(1) + S
If SC_flag = 0 Then
 With MSFlexGrid3
 For i = 1 To LenB(Main_In_String(1)) / 2 - 4
 Temp_Integer = Val("&h" + Hex$(AscB(MidB(Main_In_String(1), 3 + 2 * i, 1))) + Hex$(AscB(MidB(Main_In_String(1), 4 + 2 * i, 1))))
 If i = 19 Then
 Temp_single = Temp_Integer * 0.1
 Else
  Temp_single = Temp_Integer * 0.01
 End If
 If i > 80 Then Exit Sub
   .TextMatrix(i, 1) = Str(Temp_single)
   Next i
 End With
 Else
 
With MSFlexGrid3
 For i = 1 To LenB(Main_In_String(1)) - 6
 Temp_Integer = AscB(MidB(Main_In_String(1), i + 4, 1))
If i > LenB(Main_In_String(1)) - 8 Then

 If Temp_Integer = &H55 Then
  temp_Bool = True
  .TextMatrix(i, 1) = "跳闸"
 Else
  temp_Bool = False
  .TextMatrix(i, 1) = "信号"
 End If
Else
 
 
 If Temp_Integer = &H55 Then
  temp_Bool = True
  .TextMatrix(i, 1) = "投"
  
 Else
  temp_Bool = False
  .TextMatrix(i, 1) = "退"
 End If
  End If
   Next i
 End With
 
 
 End If
End Sub

Private Sub Timer3_Timer()
Dim A() As Byte
Dim S As String
Dim SSS1 As String
Dim SSS As String

Dim temp_string As String
Dim Com_B As Integer
Dim address As Integer
Dim Temp_Integer As Integer
Dim Temp_single As Single
Dim temp_Bool As Boolean

If MSComm1.InBufferCount < 1 Then Exit Sub
If Check1.Value = 0 Then Text2.Text = ""
A = MSComm1.Input

S = A
   For i = 1 To LenB(S)
          If AscB(MidB(S, i, 1)) > 15 Then SSS1 = SSS1 + Hex(AscB(MidB(S, i, 1))) + " "
          If AscB(MidB(S, i, 1)) < 16 Then SSS1 = SSS1 + "0" + Hex(AscB(MidB(S, i, 1))) + " "
   Next i
    Text7 = Text7 + SSS1
    
 In_str = In_str + S
   A = In_str
   T = JiaoYanCRC16(A)
   If T = 0 Then
      Label19.Caption = "校验错误"
      Exit Sub
   End If
   Label19.Caption = "校验正确"
   S = A
   SSS1 = ""
   For i = 1 To LenB(S)
          If AscB(MidB(S, i, 1)) > 15 Then SSS1 = SSS1 + Hex(AscB(MidB(S, i, 1))) + " "
          If AscB(MidB(S, i, 1)) < 16 Then SSS1 = SSS1 + "0" + Hex(AscB(MidB(S, i, 1))) + " "
   Next i
    Text2 = Text2 + SSS1

End Sub

Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)
Select Case Button.Key
Case Is = "DYdy"
  dy_dy.Show
End Select

End Sub

Private Sub UpDown3_DownClick()
Dim S As String
If XC_XS = 0.1 Then S = ".0"
If XC_XS = 0.01 Then S = ".00"
If XC_XS = 1 Then S = "0"
If Val(Text5.Text) > 0 Then Text5.Text = Format(Val(Text5.Text) - 1 * XC_XS, S)
End Sub

Private Sub UpDown3_UpClick()
Dim S As String
If XC_XS = 0.1 Then S = ".0"
If XC_XS = 0.01 Then S = ".00"
If XC_XS = 1 Then S = "0"
If Val(Text5.Text) / XC_XS < 30000 Then Text5.Text = Format(Val(Text5.Text) + 1 * XC_XS, S)
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -