查看: 2868|回复: 0

VB.NET下采用索引对WinIO的封装类(WinIO.vb) [复制链接]

hotpower (离线)
积分
82854
帖子
313
发表于 2009-4-3 00:15:09 |显示全部楼层
关键词: NET , WinIO , 封装 , 索引
Imports System.Runtime.InteropServices
Imports System.Text
Imports System.Threading
Imports System.Windows.Forms 'MessageBox需要
'菜农HotPower@126.com 2008.11.13 于雁塔菜地
Public Class WinIO
#Region "WinIO API"
    <DllImport("WinIo.dll")> Private Shared Function InitializeWinIo() As Boolean
    End Function
    <DllImport("WinIo.dll")> Private Shared Function ShutdownWinIo() As Boolean
    End Function
    <DllImport("WinIo.dll")> Private Shared Function GetPortVal( _
        ByVal PortAddr As UInt16, ByRef PortVal As UInt32, ByVal bSize As Byte) As Boolean
    End Function
    <DllImport("WinIo.dll")> Private Shared Function SetPortVal( _
        ByVal PortAddr As UInt16, ByVal PortVal As UInt32, ByVal bSize As Byte) As Boolean
    End Function
#End Region
    '在Form1.cs内加Private WinIoPort As New WinIO()
    Private blEnable As Boolean
    Private blError As Boolean
    Sub New() '//构造函数(自动运行)
        blEnable = False
        blError = False
        Try
            blEnable = InitializeWinIo() '加载WinIO
        Catch ex As System.Exception
            MessageBox.Show(ex.Message, "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub
    Protected Overrides Sub Finalize() '析构函数(自动运行)
        If blEnable = True Then
            ShutdownWinIo() '卸载WinIO
        End If
    End Sub
    Public ReadOnly Property Err() As Boolean
        Get
            Return blError
        End Get
    End Property
    Public ReadOnly Property Enable() As Boolean
        Get
            Return blEnable
        End Get
    End Property
    Default Public Property My(ByVal Index As UInt16) As Byte
        'x = WinIoPort(&H378)
        Get
            Dim val As UInt32
            blError = GetPortVal(Index, val, 1)
            Return (val And &HFF)
        End Get
        'WinIoPort(&H378) = &H55
        Set(ByVal value As Byte)
            blError = SetPortVal(Index, value, 1)
        End Set
    End Property
    Default Public Property My(ByVal Index As UInt16, ByVal size As Byte) As UInt32
        'x = WinIoPort(&H378, 1) x = WinIoPort(&H378, 2) x = WinIoPort(&H378, 4)
        Get
            Dim val As UInt32
            blError = GetPortVal(Index, val, size)
            Return val
        End Get
        'WinIoPort(&H378, 1) = &H55 WinIoPort(&H378, 2) = &H5555
        'WinIoPort(&H378, 4) = &H12345678
        Set(ByVal value As UInt32)
            blError = SetPortVal(Index, value, size)
        End Set
    End Property
End Class
●█〓██▄▄▄▄▄▄ ●●●●●●→ ''''╭WWWW╮
▄▅██████▅▄▃▂ 传播非典灌水四方 ( ●_●)
███天█马█行█空████ '''',,,;,;,;'''/▇\''
◥⊙▲⊙▲⊙▲⊙▲⊙▲⊙▲◤ 群魔乱舞见阳光/MMMM\
您需要登录后才可以发表评论 登录 | 立即注册

关于我们  -  服务条款  -  使用指南  -  站点地图  -  友情链接  -  联系我们
电子工程网 © 版权所有   京ICP备11013910号 | 京公网安备11010502021702
回顶部