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

查看: 8276|回復(fù): 0
打印 上一主題 下一主題

C#下采用索引對(duì)WinIO的封裝類(WinIO.cs)

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
發(fā)表于 2009-4-3 00:10:04 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
關(guān)鍵詞: WinIO , 封裝 , 索引
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;//MessageBox需要
using System.Runtime.InteropServices;//加動(dòng)態(tài)鏈接庫(kù)需要
//菜農(nóng)HotPower@126.com  2008.11.12 于雁塔村
namespace WindowsFormsApplication2
{
    #region C#下采用索引對(duì)WinIO的封裝類(WinIO.cs)
    /*
       應(yīng)用時(shí)應(yīng)該在Form1.cs中加入:
       private WinIO WinIOPort = new WinIO();
            例: WinIOPort[0x378] = 0x55;
                 x = WinIOPort[0x379, 2];
    */
    public class WinIO
    {
        //動(dòng)態(tài)鏈接庫(kù)的引用
        [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與并口無(wú)關(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;//讀寫出錯(cuò)字段
        public WinIO()
        {//構(gòu)造函數(shù)(自動(dòng)運(yùn)行)
            try
            {
                enable = InitializeWinIo();//加載WinIO
            }
            catch (System.Exception error)
            {//WinIO加載失敗異常處理
                MessageBox.Show(error.Message, "系統(tǒng)提示", MessageBoxButtons.OK,
MessageBoxIcon.Error);
            }
        }
        ~WinIO()
        {//析構(gòu)函數(shù)(自動(dòng)運(yùn)行)
            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
}

本版積分規(guī)則

關(guān)于我們  -  服務(wù)條款  -  使用指南  -  站點(diǎn)地圖  -  友情鏈接  -  聯(lián)系我們
電子工程網(wǎng) © 版權(quán)所有   京ICP備16069177號(hào) | 京公網(wǎng)安備11010502021702
快速回復(fù) 返回頂部 返回列表
主站蜘蛛池模板: 在线日韩欧美一区二区三区 | 国产一久久香蕉国产线看观看 | 青青青草国产线观 | 国内精品一区二区在线观看 | 黄色片免费在线看 | 免费的三级毛片 | 欧美日韩精品一区二区三区 | 免费久久精品视频 | 伊人六月| 日本无遮挡吸乳视频看看 | 富二代精产国品在线播放 | 人人做人人干 | 碰操| 国产午夜人做人视频羞羞 | 精品理论片 | 国产性夜夜春夜夜爽 | 男人的天堂在线免费视频 | 国产精品18久久久久久小说 | 免费自拍偷拍视频 | 九九热在线精品视频 | 免费h福利动漫网站在线 | 久久精品国产福利国产秒 | 亚洲天堂第一页 | 四虎论坛| 毛片视频免费 | 免费看的 | 色四虎| 国产精品日韩在线观看 | 亚洲视频欧美视频 | 国产高清一区二区三区 | 免费99 | 日韩视频 中文字幕 视频一区 | 国产wwwww | 天堂最新版免费观看 | 国产成人久久综合二区 | 大伊香蕉精品一线视频 | 日韩成人精品 | 国产精品影视 | 69成年网 | 91高清视频 | 国产免费一级视频 |