using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace LED_CSharp
{
public partial class Form1 : Form
{
const UInt32 OPEN_EXISTING = 3;
const UInt32 GENERIC_READ = 0x80000000;
const UInt32 GENERIC_WRITE = 0x40000000;
const Int32 INVALID_HANDLE_VALUE = -1;
const UInt32 LED_ON = 0x01;
const UInt32 LED_OFF = 0x06;
private IntPtr hPort;
[DllImport("coredll.dll")]
public static extern IntPtr CreateFile(String lpFileName, UInt32 dwDesiredAccess, UInt32 dwShareMode, IntPtr lpSecurityAttributes, UInt32 dwCreationDisposition, UInt32 dwFlagsAndAttributes, IntPtr hTemplateFile);
[DllImport("coredll.dll")]
public static extern bool DeviceIoControl(IntPtr hDevice, UInt32 dwIoControlCode, Byte[] lpInBuffer, UInt32 nInBufferSize, Byte[] lpOutBuffer, UInt32 nOutBufferSize, UInt32 lpBytesReturned, IntPtr lpOverlapped);
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
hPort = CreateFile("LED1:", GENERIC_READ | GENERIC_WRITE, 0, IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero);
if (hPort == (IntPtr)INVALID_HANDLE_VALUE)
{
MessageBox.Show("Open Led Driver Fail");
}
}
private void button3_Click(object sender, EventArgs e)
{
DeviceIoControl(hPort, LED_ON, null, 0, null,0,0,IntPtr.Zero);
}
private void button4_Click(object sender, EventArgs e)
{
DeviceIoControl(hPort, LED_OFF, null, 0, null,0,0,IntPtr.Zero);
}
}
}PS.#define IO_CTL_LED_1_ON 0x01
#define IO_CTL_LED_2_ON 0x02
#define IO_CTL_LED_3_ON 0x03
#define IO_CTL_LED_4_ON 0x04
#define IO_CTL_LED_ALL_ON 0x05
#define IO_CTL_LED_1_OFF 0x06
#define IO_CTL_LED_2_OFF 0x07
#define IO_CTL_LED_3_OFF 0x08
#define IO_CTL_LED_4_OFF 0x09
#define IO_CTL_LED_ALL_OFF 0x0a
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace LED_CSharp
{
public partial class Form1 : Form
{
const UInt32 OPEN_EXISTING = 3;
const UInt32 GENERIC_READ = 0x80000000;
const UInt32 GENERIC_WRITE = 0x40000000;
const Int32 INVALID_HANDLE_VALUE = -1;
const UInt32 LED_ON = 0x01;
const UInt32 LED_OFF = 0x06;
private IntPtr hPort;
[DllImport("coredll.dll")]
public static extern IntPtr CreateFile(String lpFileName, UInt32 dwDesiredAccess, UInt32 dwShareMode, IntPtr lpSecurityAttributes, UInt32 dwCreationDisposition, UInt32 dwFlagsAndAttributes, IntPtr hTemplateFile);
[DllImport("coredll.dll")]
public static extern bool DeviceIoControl(IntPtr hDevice, UInt32 dwIoControlCode, Byte[] lpInBuffer, UInt32 nInBufferSize, Byte[] lpOutBuffer, UInt32 nOutBufferSize, UInt32 lpBytesReturned, IntPtr lpOverlapped);
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
hPort = CreateFile("LED1:", GENERIC_READ | GENERIC_WRITE, 0, IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero);
if (hPort == (IntPtr)INVALID_HANDLE_VALUE)
{
MessageBox.Show("Open Led Driver Fail");
}
}
private void button3_Click(object sender, EventArgs e)
{
DeviceIoControl(hPort, LED_ON, null, 0, null,0,0,IntPtr.Zero);
}
private void button4_Click(object sender, EventArgs e)
{
DeviceIoControl(hPort, LED_OFF, null, 0, null,0,0,IntPtr.Zero);
}
}
}PS.#define IO_CTL_LED_1_ON 0x01
#define IO_CTL_LED_2_ON 0x02
#define IO_CTL_LED_3_ON 0x03
#define IO_CTL_LED_4_ON 0x04
#define IO_CTL_LED_ALL_ON 0x05
#define IO_CTL_LED_1_OFF 0x06
#define IO_CTL_LED_2_OFF 0x07
#define IO_CTL_LED_3_OFF 0x08
#define IO_CTL_LED_4_OFF 0x09
#define IO_CTL_LED_ALL_OFF 0x0a
PS.不知道這樣的Source Code是值多少錢 找都找不到, 連原廠都不願意給 搞不懂! 還是搞得不太懂 不過反正Work了
Comments