| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 529 人关注过本帖
标题:VB中数字量采集问题
只看楼主 加入收藏
小巴88888888
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2013-3-30
结帖率:100%
收藏
 问题点数:0 回复次数:0 
VB中数字量采集问题
我想问一下各位大虾,我用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
请给大神帮我看看到底问题出在什么地方了?
搜索更多相关主题的帖子: 指示灯 
2013-03-30 09:34
快速回复:VB中数字量采集问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.030785 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved