예제 #1
0
        private UInt32 GetPortValue(UInt16 portAddress)
        {
            UInt32 portValue = 0;

            if (hMod != IntPtr.Zero)
            {
                if (this.GetPortVal == null)
                {
                    IntPtr pFunc = GetProcAddress(hMod, "GetPortVal");
                    if (pFunc != IntPtr.Zero)
                    {
                        this.GetPortVal = (GetPortValType)Marshal.GetDelegateForFunctionPointer(pFunc, typeof(GetPortValType));
                    }
                    else
                    {
                        string msg = "GetPortValue(): Unable to lcoate procedure address.";
                        Console.WriteLine(msg);
                        // throw new Exception(msg);
                    }
                }

                if (!this.GetPortVal(portAddress, &portValue, 1))
                {
                    string msg = "GetPortValue(): Error returned from GetPortVal()";
                    Console.WriteLine(msg);
                    // throw new Exception(msg);
                }
            }

            return(portValue);
        }
예제 #2
0
파일: Form1.cs 프로젝트: waertf/DumpPort
        private void btnGetValue_Click(object sender, EventArgs e)
        {
            IntPtr pFunc = GetProcAddress(hMod, "GetPortVal");

            if (pFunc != IntPtr.Zero)
            {
                UInt16 PortAddr;
                UInt32 PortVal;

                PortAddr = UInt16.Parse(txtPortAddr.Text, System.Globalization.NumberStyles.HexNumber);

                GetPortValType GetPortVal = (GetPortValType)Marshal.GetDelegateForFunctionPointer(pFunc, typeof(GetPortValType));

                // Call WinIo to get value
                //bool Result = GetPortVal(PortAddr, &PortVal, 1);
                bool Result = GetPortVal(PortAddr, &PortVal, 4);
                if (Result)
                {
                    //txtValue.Text = PortVal.ToString("X");
                    txtValue.Text = PortVal.ToString("X8");
                }
                else
                {
                    MessageBox.Show("Error returned from GetPortVal", "DumpPort", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
        //等待鍵盤緩衝區為空
        private static void KBCWait4IBE()
        {
            IntPtr pFunc = GetProcAddress(hMod, "GetPortVal");

            if (pFunc != IntPtr.Zero)
            {
                GetPortValType GetPortVal = (GetPortValType)Marshal.GetDelegateForFunctionPointer(pFunc, typeof(GetPortValType));
                UInt32         PortVal;
                do
                {
                    bool flag = GetPortVal(0x64, &PortVal, 1);
                }while ((PortVal & 0x2) > 0);
            }
        }
예제 #4
0
        public void Close()
        {
            if (hMod != IntPtr.Zero)
            {
                IntPtr pFunc = GetProcAddress(hMod, "ShutdownWinIo");
                if (pFunc != IntPtr.Zero)
                {
                    this.GetPortVal = null;
                    this.SetPortVal = null;

                    ShutdownWinIoType ShutdownWinIo = (ShutdownWinIoType)Marshal.GetDelegateForFunctionPointer(pFunc, typeof(ShutdownWinIoType));
                    ShutdownWinIo();

                    FreeLibrary(hMod);
                    hMod = IntPtr.Zero;
                }
            }
        }
예제 #5
0
        public bool Open(Form1 form)
        {
            form1 = form;

            if (IntPtr.Size == 4)
            {
                hMod = LoadLibrary("GPIO32.dll");
            }
            else
            {
                hMod = LoadLibrary("GPIO64.dll");
            }

            if (hMod != IntPtr.Zero)
            {
                IntPtr pFunc = GetProcAddress(hMod, "InitializeGPIO");

                if (pFunc != IntPtr.Zero)
                {
                    InitializeGPIOType InitializeGPIO = (InitializeGPIOType)Marshal.GetDelegateForFunctionPointer(pFunc, typeof(InitializeGPIOType));

                    if (InitializeGPIO())
                    {
                        IntPtr pFuncSet = GetProcAddress(hMod, "SetPortVal");
                        SetPortVal = (SetPortValType)Marshal.GetDelegateForFunctionPointer(pFuncSet, typeof(SetPortValType));
                        IntPtr pFuncGet = GetProcAddress(hMod, "GetPortVal");
                        GetPortVal = (GetPortValType)Marshal.GetDelegateForFunctionPointer(pFuncGet, typeof(GetPortValType));

                        GPIOThread.DoWork += new DoWorkEventHandler(GPIOLoop);
                        GPIOThread.WorkerSupportsCancellation = true;

                        return(true);
                    }
                }
            }

            FreeLibrary(hMod);
            return(false);
        }
예제 #6
0
        public void Close()
        {
            if (hMod != IntPtr.Zero)
            {
                IntPtr pFunc = GetProcAddress(hMod, "ShutdownWinIo");
                if (pFunc != IntPtr.Zero)
                {
                    this.GetPortVal = null;
                    this.SetPortVal = null;

                    ShutdownWinIoType ShutdownWinIo = (ShutdownWinIoType)Marshal.GetDelegateForFunctionPointer(pFunc, typeof(ShutdownWinIoType));
                    ShutdownWinIo();

                    FreeLibrary(hMod);
                    hMod = IntPtr.Zero;
                }
            }
        }
예제 #7
0
        private UInt32 GetPortValue(UInt16 portAddress)
        {
            UInt32 portValue = 0;

            if (hMod != IntPtr.Zero)
            {
                if (this.GetPortVal == null)
                {
                    IntPtr pFunc = GetProcAddress(hMod, "GetPortVal");
                    if (pFunc != IntPtr.Zero)
                    {
                        this.GetPortVal = (GetPortValType)Marshal.GetDelegateForFunctionPointer(pFunc, typeof(GetPortValType));
                    }
                    else
                    {
                        string msg = "GetPortValue(): Unable to lcoate procedure address.";
                        Console.WriteLine(msg);
                        // throw new Exception(msg);
                    }
                }

                if (!this.GetPortVal(portAddress, &portValue, 1))
                {
                    string msg = "GetPortValue(): Error returned from GetPortVal()";
                    Console.WriteLine(msg);
                    // throw new Exception(msg);
                }
            }

            return portValue;
        }