📄 comtrade.bas
字号:
Attribute VB_Name = "comtrade"
Option Explicit
Global lMaskArray(0 To 31) As Long ' 位掩码
Global Const csProgramTitle = "COMTRADE数据处理工具 V1.0" ' 窗口标题
Global Const cnTxtFileType = 0 ' 文本格式
Global Const cnExcelFileType = 1 ' EXCEL格式
Global Const cnWordFileType = 2 ' WORD格式
Global Const cnPdfFileType = 3 ' PDF格式
' --------------------------
' COMTRADE配置文件格式定义
' --------------------------
' 1. Station Name and Identification:
' station_name, id <CR,LF>
' station_name = the unique name of the recorder
' id = the unique number of the recorder
'
' 2. Numbfer and Type of Channels:
' TT, nnt, nnt <CR,LF>
' TT = total number of channels
' nn = number of channels of
' t = types of input (A=analog/D=status)
'
' 3. Channel Information:
' nn, id, p, cccccc, uu, a, b, skew, min, max <CR,LF>
' nn = channle number
' id = channel name
' p = channel phase identification (e.g., A,B,C,N,R,Y,B)
' cccccc = circuit/component being monitored
' uu = channle units (KV, KA, etc)
' a = real number (see below)
' b = real number. Channel conversion factor is a * x + b (i.e., a recorded value
' of x corresponse to (a * x + b) in units uu specified above)
' skew = real number. Channel time skew (in us) from start of sample peiod
' min = an integer equal to the minimum value (lower limit of sample range) for samples
' of this channel
' max = an integer equal to the maximum value (upper limit of sample range) for samples
' of this channel
' m = (0 or 1) the normal state of this channle (applies to digital channles only)
'
' 4.LineFrequency:
' lf <CR,LF>
' lf = line frequency in Hz(50 or 60)
'
' 5. Sample Rate Information:
' nrates <CR,LF>
' sssss1, endsamp1 <CR,LF>
' sssss1, endsamp1 <CR,LF>
' ....
' sssss1, endsampn <CR,LF>
' nrates = number of different sample rates in the data file
' sssss1 ~ ssssn = the sample rate in Hz
' endsamp1 ~ endsampn = last sample number at this rate
'
' 6. Date / Time Stamps:
' mm/dd/yy, hh:mm:ss.ssssss <CR,LF> => for the first data value in the date file
' mm/dd/yy, hh:mm:ss.ssssss <CR,LF> => for the trigger point.
' mm = month (01-12)
' dd = day of month (01-31)
' yy = last two digits of year
' hh = hours (00-23)
' mm = minutes (00-59)
' ss.ssssss = seconds (from 0 sec to 59.999999 sec)
'
' 7. File Type:
' ft <CR,LF>
' ft = ASCII for ascii file format, and BINARY for binary file format
'
' 8. Example Configuration File
' Great Oaks Substation, 25 <CR,LF>
' 6, 4A, 2D <CR,LF>
' 1, Line 1 Phase A Voltage, A, kV, 200., 0., 0., 0, 4096 <CR,LF>
' 2, Line 2 Phase B Voltage, B, kV, 200., 0., 0., 0, 4096 <CR,LF>
' 3, Bus Current, A, kA, 100., 0., 0., 0, 4096 <CR,LF>
' 4, Line 2 Phase A Voltage, A, kV, 200., 0., 0., 0. 4096 <CR,LF>
' 1, Breaker #XX Open, 0 <CR,LF>
' 2, Breaker #YY Closed, 0 <CR,LF>
' 60 <CR,LF>
' 2 <CR,LF>
' 5184, 1298 <CR,LF>
' 2592, 1400 <CR,LF>
' 06/25/88, 23:12:14.089045 <CR,LF>
'
' 9. Example Ascii Date File
' 0000000001, 0000000000, 002090, 001827, 002090, 002044, 0, 0
' ---------- ---------- ------------------------------- --------
' Sample Time in us Analog Data Values for Channels Status
' Number from begi- 1-4 Infor
' nning or Channels
' record 5 and 6
'
' 10. BINARY format Data File:
' n tt A1A2......AkD1D2....Dm
' n = sample number , in four bytes
' tt = sample time in us, in four bytes
' A1..Ak = analog sample values in two bytes for each channel
' D1..Dm = status values of 16 digital inputs in each 16 bit word
'
' Notes:
' (1) The least significant bit of a word is assigned to the smallest input
' channel number belonging to that group of 16 channels. Thus, bit 0 of
' D1 is the status of digital input number 1, while bit 1 of D2 is the
' status of digital input number 18.
' (2) In storing a word, the low byte of the word is stored first, then the
' high byte.
' (3) Missing data in a binary file is represented by FFFF.
'
' COMTRADE文件头信息定义
Type tComtradeFileHeadInfor
blFileValid As Boolean ' 当前数据文件是否有效
sDatFileName As String ' 当前数据文件名称
sCfgFileName As String ' 当前配置文件名称
sEquipName As String ' 采集数据的设备唯一名称
lEquipId As Long ' 采集数据的设备唯一ID
lTotalChannels As Long ' 通道总数
lTotalAnalogChs As Long ' 模拟量通道总数
lTotalSwitchChs As Long ' 开关量通道总数
fFrequency As Single ' 电网额定频率: 50 或 60
iNumberOfAcqSeg As Integer ' 不同采样频率的数据段数
dFirstPntTime As Date ' 第一个采样点对应的绝对时刻(年/月/日 时:分:秒)
lFirstPntUsec As Long ' 第一个采样点对应的绝对时刻(us)
dAcqZeroTime As Date ' 触发记录对应的绝对时刻(年/月/日 时:分:秒)
lAcqZeroUsec As Long ' 触发记录对应的绝对时刻(us)
sFileFormat As String * 10 ' 文件格式:BINARY-二进制,ASCII-文本
End Type
Global rComtradeFileHeadInfor As tComtradeFileHeadInfor
' COMTRADE不同采样频率的数据段信息
Type tComtradeAcqSegInfor
fPointsPerSec As Single ' 采样频率
lEndPointOffset As Long ' 结束采样点记录偏移(本频率段最后一个采样点对应的记录数)
blSelected As Boolean ' 是否被选择输出:True-是
End Type
' 实际记录数由配置文件的不同采样频率的数据段决定
Global rComtradeAcqSegInfor() As tComtradeAcqSegInfor
' COMTRADE模拟量通道信息
Type tComtradeAnalogInfor
iChannelID As Integer ' 通道号
sChannelName As String * 50 ' 通道名称
sPhaseName As String * 3 ' 相序
sCirCompName As String * 20 ' 被监测的电路或元件名称
sUnitName As String * 10 ' 单位
fCoefficient As Single ' 系数
fOffset As Single ' 偏移量
fSkewTime As Single ' 本通道相对于采样周期的时间偏移
lMinValue As Long ' 最小整数值
lMaxValue As Long ' 最大整数值
blSelected As Boolean ' 是否被选择输出:True-是
End Type
' 实际记录数由配置文件的模拟量通道总数决定
Global rComtradeAnalogInfor() As tComtradeAnalogInfor
' COMTRADE开关量通道信息
Type tComtradeSwitchInfor
iChannelID As Integer ' 通道号
sChannelName As String * 50 ' 通道名称
iNormalStatus As Integer ' 正常状态:0 或 1
blSelected As Boolean ' 是否被选择输出:True-是
End Type
' 实际记录数由配置文件的开关量通道总数决定
Global rComtradeSwitchInfor() As tComtradeSwitchInfor
Sub Main()
'检查程序是否已在运行
Call VariInstanceControl(csProgramTitle, cnEndNewInstance, SW_SHOWMAXIMIZED)
Dim i As Integer
For i = 0 To 15
lMaskArray(i) = 2 ^ i ' 位掩码
Next i
If Dir$(Trim(App.Path) + "\DATA", vbDirectory) = "" Then
MkDir Trim(App.Path) + "\DATA" ' 建立数据文件默认路径
End If
If Dir$(Trim(App.Path) + "\OUT", vbDirectory) = "" Then
MkDir Trim(App.Path) + "\OUT" ' 建立输出文件默认路径
End If
rComtradeFileHeadInfor.blFileValid = False ' 当前数据文件是否有效
rComtradeFileHeadInfor.sCfgFileName = "" ' 当前配置文件名称
rComtradeFileHeadInfor.sDatFileName = "" ' 当前数据文件名称
mdiMain.Show vbNormal ' 启动主窗口
End Sub
' 检查是否为正长整数
Function blIsPositiveLongValue(sMessage As String, sTitle As String, lValue As Long, iLineCount As Integer)
If lValue < 0 Then
MsgBox "第" + Trim$(Str$(iLineCount)) + "行:" + sMessage, vbCritical + vbOKOnly, sTitle
blIsPositiveLongValue = False
Else
blIsPositiveLongValue = True
End If
End Function
' 检查是否为正整数
Function blIsPositiveIntValue(sMessage As String, sTitle As String, iValue As Integer, iLineCount As Integer)
If iValue < 0 Then
MsgBox "第" + Trim$(Str$(iLineCount)) + "行:" + sMessage, vbCritical + vbOKOnly, sTitle
blIsPositiveIntValue = False
Else
blIsPositiveIntValue = True
End If
End Function
' 检查是否为正浮点数
Function blIsPositiveSingleValue(sMessage As String, sTitle As String, fValue As Single, iLineCount As Integer)
If fValue < 0 Then
MsgBox "第" + Trim$(Str$(iLineCount)) + "行:" + sMessage, vbCritical + vbOKOnly, sTitle
blIsPositiveSingleValue = False
Else
blIsPositiveSingleValue = True
End If
End Function
' 得到数据文件信息
Public Sub subGetFileInfor()
' 当前数据文件是否有效
If rComtradeFileHeadInfor.blFileValid = False Then Exit Sub
' 初始化rComtradeFileHeadInfor结构
rComtradeFileHeadInfor.sEquipName = "" ' 采集数据的设备名称
rComtradeFileHeadInfor.sEquipName = 0 ' 采集数据的设备ID
rComtradeFileHeadInfor.lTotalChannels = 0 ' 通道总数
rComtradeFileHeadInfor.lTotalAnalogChs = 0 ' 模拟量通道总数
rComtradeFileHeadInfor.lTotalSwitchChs = 0 ' 开关量通道总数
rComtradeFileHeadInfor.fFrequency = 50 ' 电网额定频率
rComtradeFileHeadInfor.iNumberOfAcqSeg = 1 ' 不同采样频率的数据段
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -