查看: 7008|回復: 0
打印 上一主題 下一主題

VB.NET下采用索引對WinIO的封裝類(lèi)(WinIO.vb)

[復制鏈接]
跳轉到指定樓層
樓主
發(fā)表于 2009-4-3 00:15:09 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
關(guān)鍵詞: 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"
    Private Shared Function InitializeWinIo() As Boolean
    End Function
    Private Shared Function ShutdownWinIo() As Boolean
    End Function
    Private Shared Function GetPortVal( _
        ByVal PortAddr As UInt16, ByRef PortVal As UInt32, ByVal bSize As Byte) As Boolean
    End Function
    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() '//構造函數(自動(dòng)運行)
        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() '析構函數(自動(dòng)運行)
        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
您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

關(guān)于我們  -  服務(wù)條款  -  使用指南  -  站點(diǎn)地圖  -  友情鏈接  -  聯(lián)系我們
電子工程網(wǎng) © 版權所有   京ICP備16069177號 | 京公網(wǎng)安備11010502021702
快速回復 返回頂部 返回列表
午夜高清国产拍精品福利|亚洲色精品88色婷婷七月丁香|91久久精品无码一区|99久久国语露脸精品|动漫卡通亚洲综合专区48页