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
文章评论(0条评论)
登录后参与讨论