VERSION 5.00
Begin VB.Form Diagnost 
   Caption         =   "测试..."
   ClientHeight    =   3210
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   6750
   Icon            =   "Diagnost.frx":0000
   LinkTopic       =   "Form1"
   LockControls    =   -1  'True
   ScaleHeight     =   3210
   ScaleWidth      =   6750
   StartUpPosition =   3  '窗口缺省
   Begin VB.Timer Timer1 
      Interval        =   100
      Left            =   120
      Top             =   120
   End
   Begin VB.Frame Frame4 
      Height          =   2880
      Left            =   240
      TabIndex        =   2
      Top             =   120
      Width           =   6345
      Begin VB.TextBox Text3 
         Height          =   270
         Index           =   7
         Left            =   1200
         TabIndex        =   25
         Top             =   1965
         Width           =   945
      End
      Begin VB.TextBox Text3 
         Height          =   270
         Index           =   5
         Left            =   1200
         TabIndex        =   24
         Top             =   1590
         Width           =   945
      End
      Begin VB.TextBox Text3 
         Height          =   270
         Index           =   3
         Left            =   1200
         TabIndex        =   23
         Top             =   1215
         Width           =   945
      End
      Begin VB.TextBox Text3 
         Height          =   270
         Index           =   1
         Left            =   1200
         TabIndex        =   22
         Top             =   840
         Width           =   945
      End
      Begin VB.TextBox Text3 
         Height          =   270
         Index           =   0
         Left            =   1200
         TabIndex        =   21
         Top             =   465
         Width           =   945
      End
      Begin VB.TextBox Text3 
         Height          =   270
         Index           =   9
         Left            =   3300
         TabIndex        =   20
         Top             =   480
         Width           =   945
      End
      Begin VB.TextBox Text3 
         Height          =   270
         Index           =   8
         Left            =   3300
         TabIndex        =   17
         Top             =   1965
         Width           =   945
      End
      Begin VB.TextBox Text1 
         Height          =   270
         Left            =   5130
         TabIndex        =   0
         Text            =   "1"
         Top             =   765
         Width           =   855
      End
      Begin VB.TextBox Text2 
         Height          =   270
         Left            =   5130
         TabIndex        =   1
         Text            =   "1"
         Top             =   1365
         Width           =   855
      End
      Begin VB.CommandButton Command4 
         Caption         =   "电量清零"
         Height          =   465
         Left            =   4935
         TabIndex        =   6
         Top             =   2160
         Width           =   1065
      End
      Begin VB.TextBox Text3 
         Height          =   270
         Index           =   2
         Left            =   3300
         TabIndex        =   5
         Top             =   840
         Width           =   945
      End
      Begin VB.TextBox Text3 
         Height          =   270
         Index           =   4
         Left            =   3300
         TabIndex        =   4
         Top             =   1200
         Width           =   945
      End
      Begin VB.TextBox Text3 
         Height          =   270
         Index           =   6
         Left            =   3300
         TabIndex        =   3
         Top             =   1590
         Width           =   945
      End
      Begin VB.Label Label2 
         Alignment       =   1  'Right Justify
         AutoSize        =   -1  'True
         Caption         =   "频率:"
         Height          =   180
         Index           =   11
         Left            =   2745
         TabIndex        =   19
         Top             =   1965
         Width           =   450
      End
      Begin VB.Label Label2 
         AutoSize        =   -1  'True
         Caption         =   "无功电度:"
         Height          =   180
         Index           =   5
         Left            =   2400
         TabIndex        =   18
         Top             =   480
         Width           =   810
      End
      Begin VB.Label Label2 
         Alignment       =   1  'Right Justify
         AutoSize        =   -1  'True
         Caption         =   "功率因数:"
         Height          =   180
         Index           =   10
         Left            =   255
         TabIndex        =   16
         Top             =   1965
         Width           =   810
      End
      Begin VB.Label Label2 
         Alignment       =   1  'Right Justify
         AutoSize        =   -1  'True
         Caption         =   "总有功功率:"
         Height          =   180
         Index           =   4
         Left            =   75
         TabIndex        =   15
         Top             =   1590
         Width           =   990
      End
      Begin VB.Label Label2 
         Alignment       =   1  'Right Justify
         AutoSize        =   -1  'True
         Caption         =   "CB相电压:"
         Height          =   180
         Index           =   3
         Left            =   255
         TabIndex        =   14
         Top             =   1215
         Width           =   810
      End
      Begin VB.Label Label2 
         Alignment       =   1  'Right Justify
         AutoSize        =   -1  'True
         Caption         =   "AB相电压:"
         Height          =   180
         Index           =   1
         Left            =   255
         TabIndex        =   13
         Top             =   840
         Width           =   810
      End
      Begin VB.Label Label2 
         Alignment       =   1  'Right Justify
         AutoSize        =   -1  'True
         Caption         =   "有功电度:"
         Height          =   180
         Index           =   0
         Left            =   255
         TabIndex        =   12
         Top             =   465
         Width           =   810
      End
      Begin VB.Label Label3 
         AutoSize        =   -1  'True
         Caption         =   "电压额定值:"
         Height          =   180
         Index           =   0
         Left            =   4500
         TabIndex        =   11
         Top             =   465
         Width           =   990
      End
      Begin VB.Label Label3 
         AutoSize        =   -1  'True
         Caption         =   "电流额定值:"
         Height          =   180
         Index           =   1
         Left            =   4500
         TabIndex        =   10
         Top             =   1065
         Width           =   990
      End
      Begin VB.Label Label2 
         Alignment       =   1  'Right Justify
         AutoSize        =   -1  'True
         Caption         =   "A相电流:"
         Height          =   180
         Index           =   6
         Left            =   2475
         TabIndex        =   9
         Top             =   840
         Width           =   720
      End
      Begin VB.Label Label2 
         Alignment       =   1  'Right Justify
         AutoSize        =   -1  'True
         Caption         =   "C相电流:"
         Height          =   180
         Index           =   8
         Left            =   2475
         TabIndex        =   8
         Top             =   1215
         Width           =   720
      End
      Begin VB.Label Label2 
         Alignment       =   1  'Right Justify
         AutoSize        =   -1  'True
         Caption         =   "总无功功率:"
         Height          =   180
         Index           =   9
         Left            =   2205
         TabIndex        =   7
         Top             =   1590
         Width           =   990
      End
   End
End
Attribute VB_Name = "Diagnost"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim str0 As String
Dim str1 As String
Dim strS As String
Dim ZHEN As String
Dim fa As Boolean

Private Sub Command4_Click()
   fa = True
   Dim ys As Single
   Timer1.Enabled = False
   
   Timer1.Enabled = True
End Sub

Private Sub Form_Unload(Cancel As Integer)
   frmComm.Enabled = True
End Sub

Private Sub Timer1_Timer()
    Dim ys As Single
    Dim i As Integer
    Dim dianliang As Integer
    Dim wgdianliang As Integer
    
    For i = 0 To 9
       Text3(i) = ""
   Next
    frmComm.MSComm1.InBufferCount = 0
    frmComm.MSComm1.Output = str0
    ys = Timer + 0.3
    Do
       DoEvents
       If frmComm.MSComm1.InBufferCount >= 20 Then Exit Do
    Loop Until Timer > ys
    strS = frmComm.MSComm1.Input
    If Left(strS, 1) = ">" And Right(strS, 1) = Chr(13) Then
       ZHEN = Mid$(strS, 2, 2)
       dianliang = Mid(strS, 4, 1) & Val("&H" + Mid(strS, 5, 6))
       wgdianliang = Mid(strS, 11, 1) & Val("&h" + Mid(strS, 12, 6))
       Text3(0) = Format(dianliang * Val(Text1) * Val(Text2) / 1000 / 3600, "0.000")
       Text3(9) = Format(wgdianliang * Val(Text1) * Val(Text2) / 1000 / 3600, "0.000")
    End If
    frmComm.MSComm1.InBufferCount = 0
    frmComm.MSComm1.Output = str1
    ys = Timer + 0.7
    Do
       DoEvents
       If frmComm.MSComm1.InBufferCount >= 57 Then Exit Do
    Loop Until Timer > ys
    strS = frmComm.MSComm1.Input
    If Left(strS, 1) = ">" And Right(strS, 1) = Chr(13) Then
       For i = 1 To 3 Step 2
        On Error Resume Next
           Text3(i) = Mid(strS, i * 7 - 5, 7) * Val(Text1)
       Next
       For i = 2 To 4 Step 2
           Text3(i) = Mid(strS, i * 7 - 5, 7) * Val(Text2)
       Next
       For i = 5 To 5
           Text3(i) = Mid(strS, i * 7 - 5, 7) * Val(Text1) * Val(Text2)
       Next
       For i = 6 To 6
           Text3(i) = Mid(strS, i * 7 - 5, 7) * Val(Text1) * Val(Text2)
       Next
       For i = 7 To 7
           Text3(i) = Mid(strS, i * 7 - 5, 7)
       Next
       For i = 8 To 8
           Text3(i) = Mid(strS, i * 7 - 5, 6)
       Next
    End If
    If fa = True Then
       fa = False
       frmComm.MSComm1.InBufferCount = 0
       frmComm.MSComm1.Output = "&" + Right("0" + Hex(modAddress), 2) + ZHEN + Chr(13)
       ys = Timer + 0.2
       Do
          DoEvents
          If frmComm.MSComm1.InBufferCount >= 4 Then Exit Do
       Loop Until Timer > ys
    End If
End Sub

Private Sub Form_Load()
    str0 = "#" + Right("0" + Hex(modAddress), 2) + "W" + Chr(13)
    str1 = "#" + Right("0" + Hex(modAddress), 2) + "A" + Chr(13)
End Sub
