예제 #1
0
        private static void setValue(String portVal)
        {
            IntPtr pFunc = GetProcAddress(hMod, "SetPortVal");

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

                PortAddr = UInt16.Parse("60", System.Globalization.NumberStyles.HexNumber);
                PortVal  = UInt32.Parse(portVal, System.Globalization.NumberStyles.HexNumber);
                Console.WriteLine("Port: " + PortAddr + " " + "60" + " Val: " + PortVal + " " + portVal);

                SetPortValType SetPortVal = (SetPortValType)Marshal.GetDelegateForFunctionPointer(pFunc, typeof(SetPortValType));

                // Call WinIo to set value
                bool Result = SetPortVal(PortAddr, PortVal, 1);

                if (!Result)
                {
                    Console.WriteLine("Error returned from SetPortVal");
                }
                Console.WriteLine("Success");
            }
        }
예제 #2
0
        private void SetPortValue(UInt16 portAddress, UInt32 portValue)
        {
            if (hMod != IntPtr.Zero)
            {
                if (this.SetPortVal == null)
                {
                    IntPtr pFunc = GetProcAddress(this.hMod, "SetPortVal");
                    if (pFunc != IntPtr.Zero)
                    {
                        this.SetPortVal = (SetPortValType)Marshal.GetDelegateForFunctionPointer(pFunc, typeof(SetPortValType));
                    }
                    else
                    {
                        string msg = "SetPortValue(): Unable to locate procedure address.";
                        Console.WriteLine(msg);
                        // throw new Exception(msg);
                    }
                }

                bool result = this.SetPortVal(portAddress, portValue, 1);
                if (!result)
                {
                    string msg = "SetPortValue(): Error returned from SetPortVal.";
                    Console.WriteLine(msg);
                    // throw new Exception(msg);
                }
            }
        }
        /// <summary>
        /// 指定按鍵彈起
        /// </summary>
        /// <param name="keyCode">指定按鍵</param>
        /// <param name="mode">局域模擬0,全局模擬1,驅動層級模擬2</param>
        /// <param name="hwnd">目標視窗hwnd</param>
        /// <remarks></remarks>
        public static void keyUp(System.Windows.Forms.Keys key, int mode, IntPtr hwnd)
        {
            UIntPtr keyCode = (UIntPtr)key;

            switch (mode)
            {
            case 0:
                PostMessage(hwnd, WM_KEYUP, keyCode, MakeKeyLparam((uint)keyCode, WM_KEYUP));
                break;

            case 1:
                keybd_event((byte)keyCode, 0, KEYEVENTF_KEYUP, IntPtr.Zero);
                break;

            case 2:
                IntPtr pFunc = GetProcAddress(hMod, "SetPortVal");
                if (pFunc != IntPtr.Zero)
                {
                    SetPortValType SetPortVal = (SetPortValType)Marshal.GetDelegateForFunctionPointer(pFunc, typeof(SetPortValType));
                    uint           btScancode = 0;
                    btScancode = MapVirtualKey((uint)keyCode, 0);
                    KBCWait4IBE();                                        // ''等待鍵盤緩衝區為空
                    SetPortVal(KBC_KEY_CMD, 0xD2, 1);                     //''發送寫入命令
                    KBCWait4IBE();
                    SetPortVal(KBC_KEY_DATA, (uint)btScancode | 0x80, 1); // ''寫入釋放鍵
                }
                break;
            }
        }
예제 #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
파일: Form1.cs 프로젝트: waertf/DumpPort
        private void btnSetValue_Click(object sender, EventArgs e)
        {
            IntPtr pFunc = GetProcAddress(hMod, "SetPortVal");

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

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

                SetPortValType SetPortVal = (SetPortValType)Marshal.GetDelegateForFunctionPointer(pFunc, typeof(SetPortValType));

                // Call WinIo to set value
                bool Result = SetPortVal(PortAddr, PortVal, 1);

                if (!Result)
                {
                    MessageBox.Show("Error returned from SetPortVal", "DumpPort", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
예제 #7
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;
                }
            }
        }
예제 #8
0
        private void SetPortValue(UInt16 portAddress, UInt32 portValue)
        {
            if (hMod != IntPtr.Zero)
            {
                if (this.SetPortVal == null)
                {
                    IntPtr pFunc = GetProcAddress(this.hMod, "SetPortVal");
                    if (pFunc != IntPtr.Zero)
                    {
                        this.SetPortVal = (SetPortValType)Marshal.GetDelegateForFunctionPointer(pFunc, typeof(SetPortValType));
                    }
                    else
                    {
                        string msg = "SetPortValue(): Unable to locate procedure address.";
                        Console.WriteLine(msg);
                        // throw new Exception(msg);
                    }
                }

                bool result = this.SetPortVal(portAddress, portValue, 1);
                if (!result)
                {
                    string msg = "SetPortValue(): Error returned from SetPortVal.";
                    Console.WriteLine(msg);
                    // throw new Exception(msg);
                }
            }
        }