📄 comtrade.bas
字号:
rComtradeFileHeadInfor.dFirstPntTime = CDate("1980/01/01 0:0:0") ' 第一个采样点对应的绝对时刻(年/月/日 时:分:秒)
rComtradeFileHeadInfor.lFirstPntUsec = 0 ' 第一个采样点对应的绝对时刻(us)
rComtradeFileHeadInfor.dAcqZeroTime = CDate("1980/01/01 0:0:0") ' 触发记录对应的绝对时刻(年/月/日 时:分:秒)
rComtradeFileHeadInfor.lAcqZeroUsec = 0 ' 触发记录对应的绝对时刻(us)
rComtradeFileHeadInfor.sFileFormat = "ASCII" ' 文件格式:BINARY-二进制,ASCII-文本
On Error GoTo lbFileAccessError ' 设置错误陷阱
Dim filehandle As Integer, sErrorMessage As String, iLineCount As Integer
Dim sLineString As String, iComPos As Integer, iLastComPos As Integer
iLineCount = 0 ' 文件行数
'-----------------------
' COMTRADE文件头信息定义
'-----------------------
filehandle = FreeFile ' 打开配置文件
Open rComtradeFileHeadInfor.sCfgFileName For Input Access Read As #filehandle
' 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
iLineCount = iLineCount + 1 ' 文件行数
Line Input #filehandle, sLineString
iComPos = InStr(sLineString, ",")
If iComPos >= 1 Then
rComtradeFileHeadInfor.sEquipName = Trim$(Mid$(sLineString, 1, iComPos - 1)) ' 采集数据的设备名称
rComtradeFileHeadInfor.lEquipId = Val(Mid$(sLineString, iComPos + 1)) ' 采集数据的设备ID
End If
If rComtradeFileHeadInfor.sEquipName = "" Then
MsgBox "第" + Trim$(Str$(iLineCount)) + "行:采集设备名称不能为空;或配置文件格式不正确。", vbCritical + vbOKOnly, "配置文件错误"
GoTo lbFileContentError ' 配置文件内容错误
End If
If blIsPositiveLongValue("采集设备ID号必须为非负数;或配置文件格式不正确。", "配置文件错误", rComtradeFileHeadInfor.lEquipId, iLineCount) = False Then GoTo lbFileContentError ' 配置文件内容错误
' 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)
iLineCount = iLineCount + 1 ' 文件行数
Line Input #filehandle, sLineString
iComPos = InStr(sLineString, ",")
If iComPos >= 1 Then
rComtradeFileHeadInfor.lTotalChannels = Val(Mid$(sLineString, 1, iComPos - 1)) ' 通道总数
End If
iLastComPos = iComPos
iComPos = InStr(iLastComPos + 1, sLineString, ",")
If iComPos >= 1 Then
If InStr(UCase$(Mid$(sLineString, iLastComPos + 1, iComPos - iLastComPos - 1)), "A") Then ' 是否模拟量
rComtradeFileHeadInfor.lTotalAnalogChs = Val(Mid$(sLineString, iLastComPos + 1, iComPos - iLastComPos - 1)) ' 模拟量通道总数
iLastComPos = iComPos
If iComPos >= 1 Then
rComtradeFileHeadInfor.lTotalSwitchChs = Val(Mid$(sLineString, iLastComPos + 1)) ' 开关量通道总数
End If
Else ' 开关量
rComtradeFileHeadInfor.lTotalSwitchChs = Val(Mid$(sLineString, iLastComPos + 1, iComPos - iLastComPos - 1)) ' 开关量通道总数
iLastComPos = iComPos
If iComPos >= 1 Then
rComtradeFileHeadInfor.lTotalAnalogChs = Val(Mid$(sLineString, iLastComPos + 1)) ' 模拟量通道总数
End If
End If
End If
If blIsPositiveLongValue("通道总数必须为非负数;或配置文件格式不正确。", "配置文件错误", rComtradeFileHeadInfor.lTotalChannels, iLineCount) = False Then GoTo lbFileContentError ' 配置文件内容错误
If blIsPositiveLongValue("模拟量通道数必须为非负数;或配置文件格式不正确。", "配置文件错误", rComtradeFileHeadInfor.lTotalAnalogChs, iLineCount) = False Then GoTo lbFileContentError ' 配置文件内容错误
If blIsPositiveLongValue("开关量通道数必须为非负数;或配置文件格式不正确。", "配置文件错误", rComtradeFileHeadInfor.lTotalSwitchChs, iLineCount) = False Then GoTo lbFileContentError ' 配置文件内容错误
If rComtradeFileHeadInfor.lTotalChannels <> rComtradeFileHeadInfor.lTotalAnalogChs + rComtradeFileHeadInfor.lTotalSwitchChs Then
sErrorMessage = "通道总数应等于模拟量通道数与开关量通道数之和;或配置文件格式不正确。"
GoTo lbFileContentError ' 配置文件内容错误
End If
If rComtradeFileHeadInfor.lTotalChannels < 1 Then
sErrorMessage = "要求有至少1个以上的模拟量或开关量通道;或配置文件格式不正确。"
GoTo lbFileContentError ' 配置文件内容错误
End If
Dim iChns As Integer
' 读取模拟量信息
If rComtradeFileHeadInfor.lTotalAnalogChs > 0 Then
' 实际记录数由配置文件的模拟量通道总数决定
ReDim rComtradeAnalogInfor(1 To rComtradeFileHeadInfor.lTotalAnalogChs)
' 初始化记录
For iChns = 1 To rComtradeFileHeadInfor.lTotalAnalogChs
rComtradeAnalogInfor(iChns).iChannelID = 0 ' 通道号
rComtradeAnalogInfor(iChns).sChannelName = "" ' 通道名称
rComtradeAnalogInfor(iChns).sPhaseName = "" ' 相序
rComtradeAnalogInfor(iChns).sCirCompName = "" ' 被监测的电路或元件名称
rComtradeAnalogInfor(iChns).sUnitName = "" ' 单位
rComtradeAnalogInfor(iChns).fCoefficient = 1# ' 系数
rComtradeAnalogInfor(iChns).fOffset = 0# ' 偏移量
rComtradeAnalogInfor(iChns).fSkewTime = 0# ' 本通道相对于采样周期的时间偏移
rComtradeAnalogInfor(iChns).lMinValue = 0 ' 最小整数值
rComtradeAnalogInfor(iChns).lMaxValue = 0 ' 最大整数值
rComtradeAnalogInfor(iChns).blSelected = False ' 是否被选择输出:True-是
Next iChns
' 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)
' 读取模拟量信息
For iChns = 1 To rComtradeFileHeadInfor.lTotalAnalogChs
iLineCount = iLineCount + 1 ' 文件行数
Line Input #filehandle, sLineString
iComPos = InStr(sLineString, ",")
If iComPos >= 1 Then
' 通道号
rComtradeAnalogInfor(iChns).iChannelID = Val(Mid$(sLineString, 1, iComPos - 1))
If blIsPositiveIntValue("模拟量通道号必须为非负数;或通道定义行格式不正确。", "配置文件错误", rComtradeAnalogInfor(iChns).iChannelID, iLineCount) = False Then GoTo lbFileContentError ' 配置文件内容错误
iLastComPos = iComPos
iComPos = InStr(iLastComPos + 1, sLineString, ",")
If iComPos >= 1 Then
' 通道名称
rComtradeAnalogInfor(iChns).sChannelName = Trim$(Mid$(sLineString, iLastComPos + 1, iComPos - iLastComPos - 1))
' If Trim$(rComtradeAnalogInfor(iChns).sChannelName) = "" Then
' sErrorMessage = "模拟量通道名称不能为空;或通道定义行格式不正确。"
' GoTo lbFileContentError ' 配置文件内容错误
' End If
iLastComPos = iComPos
iComPos = InStr(iLastComPos + 1, sLineString, ",")
If iComPos >= 1 Then
' 相序
rComtradeAnalogInfor(iChns).sPhaseName = UCase$(Trim$(Mid$(sLineString, iLastComPos + 1, iComPos - iLastComPos - 1)))
iLastComPos = iComPos
iComPos = InStr(iLastComPos + 1, sLineString, ",")
If iComPos >= 1 Then
' 被监测的电路或元件名称
rComtradeAnalogInfor(iChns).sCirCompName = Trim$(Mid$(sLineString, iLastComPos + 1, iComPos - iLastComPos - 1))
iLastComPos = iComPos
iComPos = InStr(iLastComPos + 1, sLineString, ",")
If iComPos >= 1 Then
' 单位
rComtradeAnalogInfor(iChns).sUnitName = UCase$(Trim$(Mid$(sLineString, iLastComPos + 1, iComPos - iLastComPos - 1)))
iLastComPos = iComPos
iComPos = InStr(iLastComPos + 1, sLineString, ",")
If iComPos >= 1 Then
' 系数
rComtradeAnalogInfor(iChns).fCoefficient = Val(Mid$(sLineString, iLastComPos + 1, iComPos - iLastComPos - 1))
If Abs(rComtradeAnalogInfor(iChns).fCoefficient) < 0.000001 Then
sErrorMessage = "模拟量系数不能为零;或通道定义行格式不正确。"
GoTo lbFileContentError ' 配置文件内容错误
End If
iLastComPos = iComPos
iComPos = InStr(iLastComPos + 1, sLineString, ",")
If iComPos >= 1 Then
' 偏移量
rComtradeAnalogInfor(iChns).fOffset = Val(Mid$(sLineString, iLastComPos + 1, iComPos - iLastComPos - 1))
iLastComPos = iComPos
iComPos = InStr(iLastComPos + 1, sLineString, ",")
If iComPos >= 1 Then
' 本通道相对于采样周期的时间偏移
rComtradeAnalogInfor(iChns).fSkewTime = Val(Mid$(sLineString, iLastComPos + 1, iComPos - iLastComPos - 1))
iLastComPos = iComPos
iComPos = InStr(iLastComPos + 1, sLineString, ",")
If iComPos >= 1 Then
' 最小整数值
rComtradeAnalogInfor(iChns).lMinValue = Val(Mid$(sLineString, iLastComPos + 1, iComPos - iLastComPos - 1))
If Trim$(Mid$(sLineString, iComPos + 1)) <> "" Then ' 最后一项内容不能为空
' 最大整数值
rComtradeAnalogInfor(iChns).lMaxValue = Val(Mid$(sLineString, iComPos + 1))
If Abs(rComtradeAnalogInfor(iChns).lMaxValue) < 1 Then
sErrorMessage = "模拟量最大整数值不能为零;或通道定义行格式不正确。"
GoTo lbFileContentError ' 配置文件内容错误
End If
If rComtradeAnalogInfor(iChns).lMaxValue <= rComtradeAnalogInfor(iChns).lMinValue Then
sErrorMessage = "模拟量最大整数值应大于最小整数值;或通道定义行格式不正确。"
GoTo lbFileContentError ' 配置文件内容错误
End If
GoTo lbNextAnalogChn ' 下一条记录
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
sErrorMessage = "模拟量通道信息定义不全(应有10项内容)或定义行数不足;或配置文件格式不正确。"
GoTo lbFileContentError ' 配置文件错误
lbNextAnalogChn:
Next iChns
End If
' 读取开关量信息
If rComtradeFileHeadInfor.lTotalSwitchChs > 0 Then
' 实际记录数由配置文件的开关量通道总数决定
ReDim rComtradeSwitchInfor(1 To rComtradeFileHeadInfor.lTotalSwitchChs)
' 初始化记录
For iChns = 1 To rComtradeFileHeadInfor.lTotalSwitchChs
rComtradeSwitchInfor(iChns).iChannelID = 0 ' 通道号
rComtradeSwitchInfor(iChns).sChannelName = "" ' 通道名称
rComtradeSwitchInfor(iChns).iNormalStatus = 0 ' 正常状态:0 或 1
rComtradeSwitchInfor(iChns).blSelected = False ' 是否被选择输出:True-是
Next iChns
' 读取开关量信息
For iChns = 1 To rComtradeFileHeadInfor.lTotalSwitchChs
iLineCount = iLineCount + 1 ' 文件行数
Line Input #filehandle, sLineString
iComPos = InStr(sLineString, ",")
If iComPos >= 1 Then
' 通道号
rComtradeSwitchInfor(iChns).iChannelID = Val(Mid$(sLineString, 1, iComPos - 1))
If blIsPositiveIntValue("开关量通道号必须为非负数;或通道定义行格式不正确。", "配置文件错误", rComtradeSwitchInfor(iChns).iChannelID, iLineCount) = False Then GoTo lbFileContentError ' 配置文件内容错误
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -