注册 登录
编程论坛 VB6论坛

VB中数字量采集问题

小巴88888888 发布于 2013-03-30 09:34, 529 次点击
我想问一下各位大虾,我用PCL-724板卡采集数字量,采集到的数字量用shape控件来显示作为指示灯,问什么shape控件的颜色不稳定,总是变化呢?我把程序放到timer控件中了。程序如下 Dim ErrCde As Long
    Dim DriverHandle As Long
    Dim szErrMsg As String * 80
    Dim DioReadBit As PT_DioReadBit
    Dim Response As Integer
    Dim state As Integer

    '#########################     启动724板卡
    ErrCde = DRV_DeviceOpen(0, DriverHandle)
    If (ErrCde <> 0) Then
        DRV_GetErrorMessage ErrCde, szErrMsg
        Response = MsgBox(szErrMsg, vbOKOnly, "Error!!")
        Exit Sub
    End If

    '数字量输入通道0                       打开端口0
    DioReadBit.Port = 0
    DioReadBit.bit = 0
    DioReadBit.state = DRV_GetAddress(state)
    ErrCde = DRV_DioReadBit(DriverHandle, DioReadBit)
    If (ErrCde <> 0) Then
        DRV_GetErrorMessage ErrCde, szErrMsg
        Response = MsgBox(szErrMsg, vbOKOnly, "error!!")
        Exit Sub
    End If
    If state = 1 Then                     '总控断红
       Shape1.BackStyle = 1
       Shape1.FillColor = QBColor(8)
    Else
       Shape1.BackStyle = 1
       Shape1.FillColor = QBColor(12)
    End If
If Shape1.FillColor = QBColor(12) Then
Shape2.FillColor = QBColor(8)
Shape3.FillColor = QBColor(8)
Shape4.FillColor = QBColor(8)
Exit Sub
Else
    '数字量输入通道1                       打开端口0
    DioReadBit.Port = 0
    DioReadBit.bit = 1
    DioReadBit.state = DRV_GetAddress(state)
    ErrCde = DRV_DioReadBit(DriverHandle, DioReadBit)
    If (ErrCde <> 0) Then
        DRV_GetErrorMessage ErrCde, szErrMsg
        Response = MsgBox(szErrMsg, vbOKOnly, "error!!")
        Exit Sub
    End If
    If state = 1 Then                      '总控合绿
       Shape2.BackStyle = 1
       Shape2.FillColor = QBColor(8)
    Else
       Shape2.BackStyle = 1
       Shape2.FillColor = QBColor(10)
    End If

    '数字量输入2通道                       打开端口0
    DioReadBit.Port = 0
    DioReadBit.bit = 2
    DioReadBit.state = DRV_GetAddress(state)
    ErrCde = DRV_DioReadBit(DriverHandle, DioReadBit)
    If (ErrCde <> 0) Then
        DRV_GetErrorMessage ErrCde, szErrMsg
        Response = MsgBox(szErrMsg, vbOKOnly, "error!!")
        Exit Sub
    End If
    If state = 1 Then                      '主电源红
       Shape3.BackStyle = 1
       Shape3.FillColor = QBColor(12)
    Else
       Shape3.BackStyle = 1
       Shape3.FillColor = QBColor(8)
    End If

    '数字量输入3通道                       打开端口0
    DioReadBit.Port = 0
    DioReadBit.bit = 3
    DioReadBit.state = DRV_GetAddress(state)
    ErrCde = DRV_DioReadBit(DriverHandle, DioReadBit)
    If (ErrCde <> 0) Then
        DRV_GetErrorMessage ErrCde, szErrMsg
        Response = MsgBox(szErrMsg, vbOKOnly, "error!!")
        Exit Sub
    End If
    If state = 1 Then                      '负载绿
       Shape4.BackStyle = 1
       Shape4.FillColor = QBColor(10)
    Else
       Shape4.BackStyle = 1
       Shape4.FillColor = QBColor(8)
    End If    '#########################     关闭程序
    ErrCde = DRV_DeviceClose(DriverHandle)
    If (ErrCde <> 0) Then
    DRV_GetErrorMessage ErrCde, szErrMsg
    Response = MsgBox(szErrMsg, vbOKOnly, "Error!!")
    End If
End If
End Sub
请给大神帮我看看到底问题出在什么地方了?
0 回复
1