📄 comtrade.bas
字号:
iLastComPos = iComPos
iComPos = InStr(iLastComPos + 1, sLineString, ",")
If iComPos >= 1 Then
' 通道名称
rComtradeSwitchInfor(iChns).sChannelName = Trim$(Mid$(sLineString, iLastComPos + 1, iComPos - iLastComPos - 1))
' If Trim$(rComtradeSwitchInfor(iChns).sChannelName) = "" Then
' sErrorMessage = "开关量通道名称不能为空;或通道定义行格式不正确。"
' GoTo lbFileContentError ' 配置文件内容错误
' End If
If Trim$(Mid$(sLineString, iComPos + 1)) <> "" Then ' 最后一项内容不能为空
' 正常状态:0 或 1
rComtradeSwitchInfor(iChns).iNormalStatus = Val(Mid$(sLineString, iComPos + 1))
' 只允许0或1
If rComtradeSwitchInfor(iChns).iNormalStatus <> 0 Then rComtradeSwitchInfor(iChns).iNormalStatus = 1
GoTo lbNextSwitchChn ' 下一条记录
End If
End If
End If
sErrorMessage = "开关量通道信息定义不全(应有3项内容)或定义行数不足;或配置文件格式不正确。"
GoTo lbFileContentError ' 配置文件错误
lbNextSwitchChn:
Next iChns
End If
' 4.LineFrequency:
' lf <CR,LF>
' lf = line frequency in Hz(50 or 60)
iLineCount = iLineCount + 1 ' 文件行数
Line Input #filehandle, sLineString
rComtradeFileHeadInfor.fFrequency = Val(sLineString) ' 电网额定频率
If rComtradeFileHeadInfor.fFrequency <> 50 And rComtradeFileHeadInfor.fFrequency <> 60 Then
sErrorMessage = "电网频率错误,应为50或60;或模拟量和开关量定义行数与通道数不对应;或配置文件格式不正确。"
GoTo lbFileContentError ' 配置文件错误
End If
' 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
'
iLineCount = iLineCount + 1 ' 文件行数
Line Input #filehandle, sLineString
rComtradeFileHeadInfor.iNumberOfAcqSeg = Val(sLineString) ' 不同采样频率的数据段
If rComtradeFileHeadInfor.iNumberOfAcqSeg < 1 Then
sErrorMessage = "最少有一个相同采样频率的数据段;或配置文件格式不正确。"
GoTo lbFileContentError ' 配置文件错误
End If
' 实际记录数由配置文件的不同采样频率的数据段决定
ReDim rComtradeAcqSegInfor(1 To rComtradeFileHeadInfor.iNumberOfAcqSeg)
Dim iSeg As Integer
' 初始化
For iSeg = 1 To rComtradeFileHeadInfor.iNumberOfAcqSeg
rComtradeAcqSegInfor(iSeg).fPointsPerSec = 1#
rComtradeAcqSegInfor(iSeg).lEndPointOffset = 0
rComtradeAcqSegInfor(iSeg).blSelected = False
Next iSeg
' 读取不同采样频率的数据段信息
For iSeg = 1 To rComtradeFileHeadInfor.iNumberOfAcqSeg
iLineCount = iLineCount + 1 ' 文件行数
Line Input #filehandle, sLineString
iComPos = InStr(sLineString, ",")
If iComPos >= 1 Then
' 采样频率
rComtradeAcqSegInfor(iSeg).fPointsPerSec = Val(Mid$(sLineString, 1, iComPos - 1))
If rComtradeAcqSegInfor(iSeg).fPointsPerSec < 0.000001 Then
sErrorMessage = "采样频率错误,必须大于0;或数据段定义行格式不正确;或配置文件格式不正确。"
GoTo lbFileContentError ' 配置文件错误
End If
If Trim$(Mid$(sLineString, iComPos + 1)) <> "" Then
' 结束采样点记录偏移(本频率段最后一个采样点对应的记录数)
rComtradeAcqSegInfor(iSeg).lEndPointOffset = Val(Mid$(sLineString, iComPos + 1))
If rComtradeAcqSegInfor(iSeg).lEndPointOffset < 1 Then
sErrorMessage = "结束采样点记录偏移必须不小于1;或数据段定义行格式不正确;或配置文件格式不正确。"
GoTo lbFileContentError ' 配置文件错误
End If
GoTo lbNextSeg ' 下一个数据段
End If
End If
sErrorMessage = "采样频率数据段信息定义不全(应有2项内容)或定义行数不足。"
GoTo lbFileContentError ' 配置文件错误
lbNextSeg:
Next iSeg
' 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)
'
Dim year1 As Integer, month1 As Integer, day1 As Integer
Dim hour1 As Integer, minute1 As Integer, second1 As Integer, usec1 As Long
iLineCount = iLineCount + 1 ' 文件行数
Line Input #filehandle, sLineString
iComPos = InStr(sLineString, "/")
If iComPos >= 1 Then
' 月
month1 = Val(Mid$(sLineString, 1, iComPos - 1))
iLastComPos = iComPos
iComPos = InStr(iLastComPos + 1, sLineString, "/")
If iComPos >= 1 Then
' 日
day1 = Val(Mid$(sLineString, iLastComPos + 1, iComPos - iLastComPos - 1))
iLastComPos = iComPos
iComPos = InStr(iLastComPos + 1, sLineString, ",")
If iComPos >= 1 Then
' 年
year1 = Val(Mid$(sLineString, iLastComPos + 1, iComPos - iLastComPos - 1))
iLastComPos = iComPos
iComPos = InStr(iLastComPos + 1, sLineString, ":")
If iComPos >= 1 Then
' 时
hour1 = Val(Mid$(sLineString, iLastComPos + 1, iComPos - iLastComPos - 1))
iLastComPos = iComPos
iComPos = InStr(iLastComPos + 1, sLineString, ":")
If iComPos >= 1 Then
' 分
minute1 = Val(Mid$(sLineString, iLastComPos + 1, iComPos - iLastComPos - 1))
iLastComPos = iComPos
iComPos = InStr(iLastComPos + 1, sLineString, ".")
If iComPos >= 1 Then
' 秒
second1 = Val(Mid$(sLineString, iLastComPos + 1, iComPos - iLastComPos - 1))
' 微秒
usec1 = Val(Mid$(sLineString, iComPos + 1)) ' 给出了us部分的时间
If usec1 < 0 Or usec1 > 999999 Then
sErrorMessage = "错误的时间格式,微秒部分必须在0~999999之间。"
GoTo lbFileContentError ' 配置文件错误
End If
Else
' 秒
second1 = Val(Mid$(sLineString, iLastComPos + 1))
' 微秒
usec1 = 0 ' 未给出us部分的时间
End If
GoTo lbCheckFirstPntTime ' 检查第一个采样点对应的绝对时刻的正确性
End If
End If
End If
End If
End If
sErrorMessage = "第一个采样点对应的绝对时刻应满足mm/dd/yy, hh:mm:ss.ssssss格式;或配置文件格式不正确。"
GoTo lbFileContentError ' 配置文件内容错误
lbCheckFirstPntTime: ' 检查第一个采样点对应的绝对时刻的正确性
If year1 < 80 Then
If IsDate(Format(year1 + 2000, "0000") + "/" + Format(month1, "00") + "/" + Format(day1, "00") + " " + Format(hour1, "00") + ":" + Format(minute1, "00") + ":" + Format(second1, "00")) = True Then
rComtradeFileHeadInfor.dFirstPntTime = CDate(Format(year1 + 2000, "0000") + "/" + Format(month1, "00") + "/" + Format(day1, "00") + " " + Format(hour1, "00") + ":" + Format(minute1, "00") + ":" + Format(second1, "00")) ' 第一个采样点对应的绝对时刻(年/月/日 时:分:秒)
rComtradeFileHeadInfor.lFirstPntUsec = usec1 ' 第一个采样点对应的绝对时刻(us)
GoTo lbAcqZeroTime ' 读取触发对应的绝对时刻
End If
Else
If IsDate(Format(year1 + 1900, "0000") + "/" + Format(month1, "00") + "/" + Format(day1, "00") + " " + Format(hour1, "00") + ":" + Format(minute1, "00") + ":" + Format(second1, "00")) = True Then
rComtradeFileHeadInfor.dFirstPntTime = CDate(Format(year1 + 1900, "0000") + "/" + Format(month1, "00") + "/" + Format(day1, "00") + " " + Format(hour1, "00") + ":" + Format(minute1, "00") + ":" + Format(second1, "00")) ' 第一个采样点对应的绝对时刻(年/月/日 时:分:秒)
rComtradeFileHeadInfor.lFirstPntUsec = usec1 ' 第一个采样点对应的绝对时刻(us)
GoTo lbAcqZeroTime ' 读取触发对应的绝对时刻
End If
End If
sErrorMessage = "第一个采样点对应的绝对时刻时间内容错误,应满足mm/dd/yy, hh:mm:ss.ssssss格式;或配置文件格式不正确。"
GoTo lbFileContentError ' 配置文件内容错误
lbAcqZeroTime: ' 读取触发对应的绝对时刻
iLineCount = iLineCount + 1 ' 文件行数
Line Input #filehandle, sLineString
iComPos = InStr(sLineString, "/")
If iComPos >= 1 Then
' 月
month1 = Val(Mid$(sLineString, 1, iComPos - 1))
iLastComPos = iComPos
iComPos = InStr(iLastComPos + 1, sLineString, "/")
If iComPos >= 1 Then
' 日
day1 = Val(Mid$(sLineString, iLastComPos + 1, iComPos - iLastComPos - 1))
iLastComPos = iComPos
iComPos = InStr(iLastComPos + 1, sLineString, ",")
If iComPos >= 1 Then
' 年
year1 = Val(Mid$(sLineString, iLastComPos + 1, iComPos - iLastComPos - 1))
iLastComPos = iComPos
iComPos = InStr(iLastComPos + 1, sLineString, ":")
If iComPos >= 1 Then
' 时
hour1 = Val(Mid$(sLineString, iLastComPos + 1, iComPos - iLastComPos - 1))
iLastComPos = iComPos
iComPos = InStr(iLastComPos + 1, sLineString, ":")
If iComPos >= 1 Then
' 分
minute1 = Val(Mid$(sLineString, iLastComPos + 1, iComPos - iLastComPos - 1))
iLastComPos = iComPos
iComPos = InStr(iLastComPos + 1, sLineString, ".")
If iComPos >= 1 Then
' 秒
second1 = Val(Mid$(sLineString, iLastComPos + 1, iComPos - iLastComPos - 1))
' 微秒
usec1 = Val(Mid$(sLineString, iComPos + 1)) ' 给出了us部分的时间
If usec1 < 0 Or usec1 > 999999 Then
sErrorMessage = "错误的时间格式,微秒部分必须在0~999999之间。"
GoTo lbFileContentError ' 配置文件错误
End If
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -