Global BarIndex(8), PIndex As Integer, TrendIndex(4), HisIndex(4), PBigerIndex As Integer
Global Data(100) As Single, DTrend(100, 360) As Single, TString(360) As Date
Global TNumber As Long, TTT As Date, AlarmNumber As Integer
Global RangeInputID As String, ModelFlag As Boolean, LoginPade As Integer
Global FTAny As Boolean, RunFlag As Boolean, FTBT As Boolean, FTOne As Boolean
Global VoiceFlag(4) As Boolean, TrendOnePindex As Integer
Global PNumber As Single, CNumber  As Integer, BarTrePIndex(20) As Integer
Global AlarmPNum As Integer, IndicatorFlag As Boolean, ControlFlag As Boolean
Global PPP As PDefine, CCC As ACollect, AAA As PAlarm, VoiceFileName As String
Global RListFlag As Boolean, TListFlag As Boolean, PListFlag As Boolean, LListFlag As Boolean, FListFlag As Boolean
Global AdjustErr5(8) As Integer, AdjustErr6(8) As IntegerType PDefine
  ID(100) As Integer
  PFL(100) As String * 1
  PName(100) As String
  Data(100) As Single
  PUnit(100) As String
  MPID(100) As String
  VSet(100) As Single
  MLUp(100) As Single
  MLDown(100) As Single
  DLUp(100) As Single
  DLDown(100) As Single
  BDBH(100) As Boolean
End TypeType PAlarm
  ID(10) As Integer
  PName(10) As String
  PUnit(10) As String
  DataIndex(10) As Integer
  UpLimit(10) As Single
  DownLimit(10) As Single
  PLimit(10) As Single
  Flag(10) As Integer
  MValue(10) As Single
  StartTime(10) As Date
End TypeType ACollect
  ID(20) As Integer
  Address(20) As Integer
  StartP(20) As Integer
  PNum(20) As Integer
  PIndex(20) As Integer
  Detail(20) As String
End TypeSub AdjustErrPermit()
Dim e%, t$, a As Single, c$, i%, j%, Y1_5 As Single, Y1_6 As Single, b As Integer
Dim SV1_5 As Single, SV1_6 As Single
Call idcbnum(5, 3, 18, 1, Y1_5, b, t$, e%)
Call idcbnum(6, 3, 17, 1, Y1_6, b, t$, e%)
Call IdcbEs(5, 3, 64, 8, AdjustErr5(1), t$, e%)
For i% = 1 To 8
   If AdjustErr5(i%) <> 0 Then
      For j% = 1 To 8
          AdjustErr5(j%) = 0
      Next j%
      c$ = "RE;"
      IdcbTx 5, c$, 0, a, e
      c$ = "SET17;"
      IdcbTx 5, c$, 0, Y1_5, e
      Call AdapterInit
      Exit Sub
   End If
Next i%
Call IdcbEs(6, 3, 64, 8, AdjustErr6(1), t$, e%)
For i% = 1 To 8
   If AdjustErr6(i%) <> 0 Then
      For j% = 1 To 8
          AdjustErr6(j%) = 0
      Next j%
      c$ = "RE;"
      IdcbTx 6, c$, 0, a, e
      c$ = "SET17;"
      IdcbTx 6, c$, 0, Y1_6, e
      Call AdapterInit
      Exit Sub
   End If
Next i%
End Sub
Sub PDefineInit()
  Dim i As Integer
  With frmMain.AdodcPDefine
    .Refresh
    .Recordset.MoveFirst
    Do While Not .Recordset.EOF
      i = .Recordset("序号")
      PPP.ID(i) = i
      PPP.PFL(i) = .Recordset("参数类别")
      PPP.PName(i) = .Recordset("参数名称")
      PPP.Data(i) = .Recordset("参数实时值")
      PPP.PUnit(i) = .Recordset("单位")
      PPP.MPID(i) = .Recordset("测点编号")
      PPP.VSet(i) = .Recordset("运行值")
      PPP.MLUp(i) = .Recordset("仪表量程上限")
      PPP.MLDown(i) = .Recordset("仪表量程下限")
      PPP.DLUp(i) = .Recordset("显示上限")
      PPP.DLDown(i) = .Recordset("显示下限")
      PPP.BDBH(i) = .Recordset("标度变换标志")
      .Recordset.MoveNext
    Loop
    PNumber = i
  End With
End Sub
Sub PAlarmInit()
  Dim i As Integer
  With frmMain.AdodcPAlarm
    .Refresh
    .Recordset.MoveFirst
    Do While Not .Recordset.EOF
      i = .Recordset("序号")
      AAA.ID(i) = i
      AAA.PName(i) = .Recordset("参数名称")
      AAA.PUnit(i) = .Recordset("单位")
      AAA.DataIndex(i) = .Recordset("数组序号")
      AAA.UpLimit(i) = .Recordset("报警上限")
      AAA.DownLimit(i) = .Recordset("报警下限")
      AAA.PLimit(i) = .Recordset("报警限")
      AAA.Flag(i) = 0
      .Recordset.MoveNext
    Loop
    AlarmPNum = i
  End With
  AlarmNumber = 0
End Sub
Sub ACollectInit()
  Dim i As Integer
  With frmMain.AdodcACollect
    .Refresh
    .Recordset.MoveFirst
    Do While Not .Recordset.EOF
      i = .Recordset("序号")
      CCC.ID(i) = i
      CCC.Address(i) = .Recordset("前端地址")
      CCC.StartP(i) = .Recordset("起始通道")
      CCC.PNum(i) = .Recordset("通道数")
      CCC.PIndex(i) = .Recordset("数组起始号")
      CCC.Detail(i) = .Recordset("说明")
      .Recordset.MoveNext
    Loop
    CNumber = i
  End With
End Sub
Sub CollectData()
  Dim b(20) As Integer, t(20) As String, e As Integer, i As Integer, s As String
  s = ""
  With CCC
    For i = 1 To CNumber
      Call idcbnum(.Address(i), 0, .StartP(i), .PNum(i), Data(.PIndex(i)), b(1), t(1), e)
      If e < 0 Then s = s + str(.Address(i)) + "=" + str(e)
    Next i
  End With
  For i = 79 To 81
     Data(i) = 1.25 * Data(i) - 0.25
  Next i
  frmMain.StatusBar1.Panels(3) = s
End Sub
Sub HistoryDataSave()
  Dim k As Integer
  frmMain.StatusBar1.Panels(3).Text = "正在存储历史数据..."
  Call CollectAndPermite
  Call S10Permite
  With frmMain.AdodcHistory
    .Recordset.AddNew
    .Recordset("日期") = Format(TTT, "yyyy年mm月dd日")
    .Recordset("时间") = TimeValue(TTT)
    For k = 1 To 81
      .Recordset(k + 1) = Data(k)
    Next k
    .Recordset.Update
    '.Refresh
  End With
  frmMain.StatusBar1.Panels(3).Text = "OK!"
End Sub
Sub ControlPermite()
Dim a(1) As Single, b(1) As Integer, t(1) As String, e As Integer
'  idcbnum 6, 0, 900, 1, a(1), b(1), t(1), e%
  frmControl.IndicatorT.BarID = 1
  frmControl.IndicatorT.BarValue = Data(78) / 7 'a(1) * 100
  frmControl.TrendT.AddXY 0, TTT, Data(78) 'frmControl.TrendT.TrackYMin + (frmControl.TrendT.TrackYMax - frmControl.TrendT.TrackYMin) * a(1)
  frmControl.TrendT.Refresh
  idcbnum 6, 0, 211, 1, a(1), b(1), t(1), e%
  frmControl.IndicatorT.BarID = 0
  frmControl.IndicatorT.BarValue = a(1) * 100
  idcbnum 6, 0, 213, 1, a(1), b(1), t(1), e%
  frmControl.IndicatorT.BarID = 2
  frmControl.IndicatorT.BarValue = a(1) * 100
  
'  idcbnum 5, 0, 900, 1, a(1), b(1), t(1), e%
  frmControl.IndicatorH.BarID = 1
'  frmControl.IndicatorH.BarValue = (Data(75) + 300) / 6 'a(1) * 100
  frmControl.TrendH.AddXY 0, TTT, Data(75) 'frmControl.TrendH.TrackYMin + (frmControl.TrendH.TrackYMax - frmControl.TrendH.TrackYMin) * a(1)
  frmControl.TrendH.Refresh
  idcbnum 5, 0, 211, 1, a(1), b(1), t(1), e%
  frmControl.IndicatorH.BarID = 0
  frmControl.IndicatorH.BarValue = a(1) * 100
  idcbnum 5, 0, 214, 1, a(1), b(1), t(1), e%
  frmControl.IndicatorH.BarID = 1
  frmControl.IndicatorH.BarValue = a(1) * 100
  idcbnum 5, 0, 213, 1, a(1), b(1), t(1), e%
  frmControl.IndicatorH.BarID = 2
  frmControl.IndicatorH.BarValue = a(1) * 100End Sub