国产毛片a精品毛-国产毛片黄片-国产毛片久久国产-国产毛片久久精品-青娱乐极品在线-青娱乐精品

電子工程網(wǎng)

標題: C#下采用索引對WinIO的封裝類(WinIO.cs) [打印本頁]

作者: hotpower    時間: 2009-4-3 00:10
標題: C#下采用索引對WinIO的封裝類(WinIO.cs)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;//MessageBox需要
using System.Runtime.InteropServices;//加動態(tài)鏈接庫需要
//菜農(nóng)HotPower@126.com  2008.11.12 于雁塔村
namespace WindowsFormsApplication2
{
    #region C#下采用索引對WinIO的封裝類(WinIO.cs)
    /*
       應(yīng)用時應(yīng)該在Form1.cs中加入:
       private WinIO WinIOPort = new WinIO();
            例: WinIOPort[0x378] = 0x55;
                 x = WinIOPort[0x379, 2];
    */
    public class WinIO
    {
        //動態(tài)鏈接庫的引用
        [DllImport("winio.dll")]
        public static extern bool InitializeWinIo();
        [DllImport("winio.dll")]
        public static extern void ShutdownWinIo();
        [DllImport("winio.dll")]
        public static extern bool GetPortVal(IntPtr wPortAddr, out uint pdwPortVal, byte
bSize);
        [DllImport("winio.dll")]
        public static extern bool SetPortVal(IntPtr wPortAddr, IntPtr dwPortVal, byte
bSize);
        /*
        //以下是WinIO與并口無關(guān)的函數(shù)
                    [DllImport("winio.dll")]
                    public static extern byte MapPhysToLin(byte pbPhysAddr, uint dwPhysSize,
IntPtr PhysicalMemoryHandle);
                    [DllImport("winio.dll")]
                    public static extern bool UnmapPhysicalMemory(IntPtr
PhysicalMemoryHandle, byte pbLinAddr);
                    [DllImport("winio.dll")]
                    public static extern bool GetPhysLong(IntPtr pbPhysAddr, byte
pdwPhysVal);
                    [DllImport("winio.dll")]
                    public static extern bool SetPhysLong(IntPtr pbPhysAddr, byte
dwPhysVal);
                    [DllImport("user32.dll")]
                    public static extern int MapVirtualKey(uint Ucode, uint uMapType);
        */
        //屬性字段
        private bool enable = false;//WinIO不可用
        private bool error = false;//讀寫出錯字段
        public WinIO()
        {//構(gòu)造函數(shù)(自動運行)
            try
            {
                enable = InitializeWinIo();//加載WinIO
            }
            catch (System.Exception error)
            {//WinIO加載失敗異常處理
                MessageBox.Show(error.Message, "系統(tǒng)提示", MessageBoxButtons.OK,
MessageBoxIcon.Error);
            }
        }
        ~WinIO()
        {//析構(gòu)函數(shù)(自動運行)
            if (enable)
            {//成功加載WinIO
                ShutdownWinIo();//卸載WinIO
            }
        }
        public bool Enable
        {//Enable只讀屬性
            get
            {
                return enable;
            }
        }
        public bool Error
        {//Error只讀屬性
            get
            {
                return error;
            }
        }
        public byte this[uint index]//byte讀寫端口
        {//數(shù)組索引:
            get
            {//例如 x = WioIOPort[0x378];  等效:x = WioIOPort[0x378, sizeof(byte)];
                uint val;//WinIo要求dword
                error = GetPortVal((IntPtr)index, out val, sizeof(byte));
                return (byte)val;
            }
            set
            {//例如 WioIOPort[0x378] = 0xff; 等效:WioIOPort[0x378, sizeof(byte)] = 0xff;
                error = SetPortVal((IntPtr)index, (IntPtr)value, sizeof(byte));
            }
        }
        public uint this[uint index, byte size]//可用byte,word,dword讀寫端口
        {//數(shù)組索引,size=1/2/4=sizeof(byte/UInt16/UInt32)
            get
            {//例如 x = WioIOPort[0x378, sizeof(UInt16)];
                uint val;//WinIo要求dword
                error = GetPortVal((IntPtr)index, out val, size);
                return val;
            }
            set
            {//例如 WioIOPort[0x378, sizeof(UInt32)] = 0x12345678;
                error = SetPortVal((IntPtr)index, (IntPtr)value, size);
            }
        }
    }
    #endregion
}




歡迎光臨 電子工程網(wǎng) (http://m.qingdxww.cn/) Powered by Discuz! X3.4
主站蜘蛛池模板: 精品中文字幕一区二区三区四区 | 在线性视频 | 永久网站色视频在线观看免费 | www.91麻豆.com| 欧美另类videos高清精品 | 和日本免费不卡在线v | 厚颜无耻有字幕在线观看 | 国产精品盗摄一区二区在线 | 国产欧美日韩精品第一区 | 大蕉久久伊人中文字幕 | 高清一区二区三区免费 | 91色网站| 三级国产 | 久久久精品日本一区二区三区 | 四虎国产精品高清在线观看 | 国产成人免费 | 国产精品午夜寂寞视频 | 国产精品入口免费麻豆 | 国产一级黄色大片 | 九九激情视频 | 黄页网址大全免费观看22 | 狠狠插综合 | 韩剧网最新的韩国电视剧免费观看 | 色avav| 老人free性hd老 | 日产精品卡2卡三卡乱码网址 | 自拍偷拍第 | 欧美成人精品一区二区 | 最新亚洲| 色综合久久一区二区三区 | 国产精品久久久久久久免费大片 | 青青青国产免费线在 | 国产精品免费看久久久久 | 亚洲mv大片欧洲mv大片 | 欧美黑人性大免费高清视频 | 国产一区二区三区夜色 | 日韩精品视频免费在线观看 | 欧美理论大片清免费观看 | 欧美黑人玩白人巨大极品 | 欧美日韩中文一区二区三区 | 天堂影 |