mainbas.bas

来自「电梯检测系统是对电梯性能进行检测的系统。是一个用来学习的程序。」· BAS 代码 · 共 1,098 行 · 第 1/3 页

BAS
1,098
字号
Attribute VB_Name = "MainBas"
Option Explicit

Public IniPath As String
Public SysUserGh As String
Public UserPass As String
Public SysPass As String
Public PubFile As String

Public ParaExe As String

Public SendComp As Boolean      '  sendcomp marks signal-sending complished
Public SendSucc As Boolean      '  sendcomp marks signal-sending-complished success or fail
Public tempBool As Boolean      '  a temp variant means signal operate OK

Public InputStr As Variant      '  FrmInputBox

Public FuncTstAry As Variant    '  the trip set of selected project
Public FuncTstKeyAry As Variant '  the key set of selected project
Public CurTripNum As Integer    '  the number current trip in test project
Public MaxFuncTstNum As Integer '  the trips' number of current test project
Public ExitAllow As Boolean
Public T2On As Boolean

Public JRHTstSta As Boolean 'mark JHR signal in test mode
Public JRECTstSta As Boolean 'mark JREC signal in test mode

Public DREC_Dcomp As Boolean     'DREC-D signal send complete
Public DREC_Ucomp As Boolean     'DREC-U signal send complete
Public JRHcomp As Boolean        'JRH signal send complete
Public JRECcomp As Boolean       'JREC signal send complete
Public DRH_Ucomp As Boolean
Public DRH_Dcomp As Boolean

Public ErrorOn  As Boolean       'when in one floor but the lamp is on, ErronOn=true

Public NowMoveFx As String      'current move direction
Public CountNum As Long     'impulsion counter number
Public CurFloor As Integer  'Now in which floor

Public FillComp As Boolean   'whether test table fill complete,
Public FillSucc As Boolean   'whether test table fill successfully
Public PFillComp As Boolean   'whether test table fill complete,
Public PFillSucc As Boolean   'whether test table fill successfu
Public InsFillComp As Boolean   'whether test table fill complete,
Public InsFillSucc As Boolean   'whether test table fill successfu

Public LockOn As Boolean

Public YesCmdClick As Boolean  'in functest test form ,YES or No command button click or not
Public FuncTestPass As Boolean 'when YES command button click ,means test thick current trip test pass

Public DefMsgComp As Boolean  'define-msgbox pressed

Public TempFileName As Variant  '存放当前测试报表文件名

Public LngVRetAryB As Variant   'return number of register reading
Public vRetAryB As Variant      'return value

Public commport As Long    'MOXA 1 th port for U1 communication
 
Public portsetting  As String

Global Const cTimeOut = 0.5
Public CommInterv As Long

Public iDeviceID As Long '单片机设备号

'以下定义信号地址
Public JHMAddr As Long       '''
Public JRHAddr As Long       '''
Public JRECAddr As Long
Public JHCAddr As Long
Public DREC_UAddr As Long
Public DREC_DAddr As Long
Public DRH_UAddr As Long      '''
Public DRH_DAddr As Long      '''
Public T2Addr As Long
Public T2_On As Long
Public T3Addr As Long
Public DT_O As Long
Public DT_S As Long
Public KL_XAddr As Long
Public KL_VAddr As Long
Public KL_MAddr As Long
Public KTSAddr As Long
Public KTCAddr  As Long
Public DC_1Addr As Long
Public DC_2Addr As Long
Public DC_3Addr As Long
Public DE_U1Addr As Long
Public DE_D2Addr As Long
Public DE_D3Addr As Long
Public KET_OAddr As Long
Public KET_SAddr As Long
Public KSAddr As Long
Public KSEAddr As Long
Public KSKBAddr As Long
Public KSKB2Addr As Long
Public JBFAddr As Long
Public JABAddr As Long
Public JVECAddr As Long
Public JHCTAddr As Long  '''
Public KVT As Long  '''
Public KVT2 As Long  '''
Public IT2 As Boolean
Public RVEC As Long
Public MGBAddr As Long
Public RLCA As Long
Public VST_OAddr As Long
Public VST_SAddr As Long
Public VST_O2Addr As Long
Public VST_S2Addr As Long
Public ICS0Addr As Long
Public ICS1Addr As Long
Public XLVETAddr As Long
Public LC_1 As Long
Public LC_2 As Long
Public LC_3 As Long
Public LE_U1 As Long
Public LE_D2 As Long
Public LE_D3 As Long
Public LW_U As Long
Public LW_D As Long
Public MVEC As Long
Public AlarmAddr As Long

Public CountAddr As Long

Public SAddr As Long   '''
Public PAddr As Long   '''


Public FanAddr As Long   '''
Public LightAddr As Long   '''
Public RPHT1Addr As Long   '''
Public RPHT2Addr As Long   '''
Public KL_HAddr As Long   '''
Public KTS2Addr As Long   '''
Public KTC2Addr  As Long  '''
Public KET_O2Addr As Long  '''
Public KET_S2Addr As Long  '''
Public KNEAddr As Long     '''
Public KSL_UAddr As Long   '''
Public KSL_DAddr As Long   '''
Public LE_U2 As Long       '''
Public DE_U2Addr As Long

'wire test
Public XPOWER1 As Long
Public iXPOWER1 As Long
Public XPOWER2 As Long
Public iXPOWER2 As Long
Public XLight1 As Long
Public iXLight1 As Long
Public XLight2 As Long
Public iXLight2 As Long

Public TESTED_BEGIN As Long


Public MaxCount As Long        'maximum impulsion counter value
Public Floor2ndCount As Long   'the impulsion counter when come to 2nd floor
Public sCountNum As Long      'cCountNum-lCountNum
Public VisPass As Boolean
 
Public Function DefInputBox(ByVal Prompt, Optional ByVal title = "InputBox", Optional ByVal default = "", Optional ByVal xpos = 100, Optional ByVal ypos = 100) As Variant
  FrmInputBox.Caption = title
  FrmInputBox.Prompt.Caption = Prompt
  FrmInputBox.left = xpos
  FrmInputBox.top = ypos
  FillComp = False
  FillSucc = False
  FrmInputBox.Show 1
  Do Until FillComp
    DoEvents
  Loop
  If FillSucc Then
    DefInputBox = InputStr
  Else
    DefInputBox = default
  End If
End Function


Public Sub itemtest()
  
End Sub

Public Function bolReadPlcB(ByVal iCommIndex As Integer, ByVal iDeviceID As Integer, ByVal iAddr As Integer, ByVal iLen As Integer, vRetAryB As Variant) As Boolean
'作者:Henry
'目的:
'     读取Plc中选定区段的数据
'传入:
'     Comm:对应Plc之通迅对象
'     iPlc:欲读取之Plc Id
'     iAddr:欲读取数据的起始地址
'     iLen:欲读取的长度(iLen=1代表读取2Bytes)
'     vRetAryB:传回区段数据的Byte数组
'传回:
'     True:成功
'     False:失败
'注:读取之区段数据将存入vRetAryB中
'   已修改成以二进位方式传送
'   有应答正确性检核
 
Dim sTime, cTime As Single
Dim Dummy As Integer
Dim bSndAry(7) As Byte
Dim vCrc As Variant
Dim vRetStr As Variant
Dim SndStr, CrcStr As String
Dim iHByte, iLByte As Integer
Dim iLenB As Integer    '以Byte为单位的取得长度
 
        iHByte = iAddr \ 256 '取商数
        iLByte = iAddr Mod 256 '取余数
        
        '将整数变量内容置入Byte变数组中
        bSndAry(0) = iDeviceID
        bSndAry(1) = 3
        bSndAry(2) = iHByte
        bSndAry(3) = iLByte
        bSndAry(4) = 0
        bSndAry(5) = iLen
        
        vCrc = CrcB(bSndAry(), 6)
        bSndAry(6) = vCrc(0)
        bSndAry(7) = vCrc(1)
 
        '清除input/output buffer
        FrmFuncTest.ReadCom.InBufferCount = 0
        FrmFuncTest.ReadCom.OutBufferCount = 0
 
        '写入output buffer
        FrmFuncTest.ReadCom.Output = bSndAry
 
        '读取input buffer全部数据
        iLenB = iLen * 2
        sTime = Timer
        bolReadPlcB = True
        Do While bolReadPlcB
           If FrmFuncTest.ReadCom.InBufferCount >= iLenB + 5 Then
              bolReadPlcB = True
              Exit Do
           End If
           cTime = Timer
           If (cTime - sTime) > cTimeOut Then
              bolReadPlcB = False
           Else
              If (Timer - sTime) < 0 Then sTime = Timer
           End If
           Dummy = DoEvents()
        Loop
 
        If bolReadPlcB Then
           vRetAryB = FrmFuncTest.ReadCom.Input
           vCrc = CrcB(vRetAryB, iLenB + 3)
           If vRetAryB(0) <> bSndAry(0) Or vRetAryB(1) <> bSndAry(1) Or _
              vCrc(0) <> vRetAryB(iLenB + 3) Or vCrc(1) <> vRetAryB(iLenB + 4) Then
              
              bolReadPlcB = False
              Exit Function
           End If
        End If
        Exit Function
readplcerr:
        bolReadPlcB = False
End Function

Public Function bolReadPlcB_01(ByVal iDeviceID As Integer, ByVal iAddr As Integer, ByVal iLen As Integer, vRetAryB As Variant) As Boolean
'作者:Henry
'目的:
'     读取Plc中选定区段的数据
'传入:
'     iFuncIndex:功能号
'     iPlc:欲读取之Plc Id
'     iAddr:欲读取数据的起始地址
'     iLen:欲读取线圈或寄存器的个数(iLen=1代表读取1Bytes)
'     vRetAryB:传回区段数据的Byte数组
'传回:
'     True:成功
'     False:失败
'注:读取之区段数据将存入vRetAryB中
'   已修改成以二进位方式传送
'   有应答正确性检核
 
Dim sTime, cTime As Single
Dim Dummy As Integer
Dim bSndAry(7) As Byte
Dim vCrc As Variant
Dim vRetStr As Variant
Dim SndStr, CrcStr As String
Dim iHByte, iLByte As Integer
Dim iLenB As Integer    '以Byte为单位的取得长度
 
 
        iHByte = iAddr \ 256 '取商数
        iLByte = iAddr Mod 256 '取余数
        
        '将整数变量内容置入Byte变数组中
        bSndAry(0) = iDeviceID
        bSndAry(1) = 1
        bSndAry(2) = iHByte
        bSndAry(3) = iLByte
        bSndAry(4) = iLen \ 256
        bSndAry(5) = iLen Mod 256
        
        vCrc = CrcB(bSndAry(), 6)
        bSndAry(6) = vCrc(0)
        bSndAry(7) = vCrc(1)
        If FrmFuncTest.ReadCom.PortOpen = False Then
           FrmFuncTest.ReadCom.PortOpen = True
        End If

        '清除input/output buffer
        FrmFuncTest.ReadCom.InBufferCount = 0
        FrmFuncTest.ReadCom.OutBufferCount = 0
        
      
        '写入output buffer
        FrmFuncTest.ReadCom.Output = bSndAry
 
        '读取input buffer全部数据
        iLenB = iLen \ 8
        sTime = Timer
        bolReadPlcB_01 = True
        Do While bolReadPlcB_01
           If FrmFuncTest.ReadCom.InBufferCount >= iLenB + 5 Then
              bolReadPlcB_01 = True
              Exit Do
           End If
           cTime = Timer
           If (cTime - sTime) > cTimeOut Then
              bolReadPlcB_01 = False
           Else
              If (Timer - sTime) < 0 Then sTime = Timer
           End If
           Dummy = DoEvents()
        Loop
 
        If bolReadPlcB_01 Then
           vRetAryB = FrmFuncTest.ReadCom.Input
           vCrc = CrcB(vRetAryB, iLenB + 3)
           If vRetAryB(0) <> bSndAry(0) Or vRetAryB(1) <> bSndAry(1) Or _
              vCrc(0) <> vRetAryB(iLenB + 3) Or vCrc(1) <> vRetAryB(iLenB + 4) Then
              
              bolReadPlcB_01 = False
              Exit Function
           End If
        End If
        
        Exit Function
       
        
readplcerr:
        bolReadPlcB_01 = False
End Function
Public Function bolWritePlcB_10(ByVal iDeviceID As Integer, ByVal iAddr As Integer, ByVal iLenB As Integer, vDataAryB As Variant) As Boolean
'作者:Henry
'目的:
'     写入传入字符串至Plc,可选定地址
'传入:
'     Comm:对应Plc之通迅对象
'     iPlc:欲写入之Plc Id
'     iAddr:欲写入数据的起始地址

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?