資源簡介
C#控制GPIO

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Text;
using?System.Windows.Forms;
using?System.IO;
using?System.IO.Ports;
using?System.Security;
using?System.Diagnostics;
using?System.Reflection;
using?System.Runtime.InteropServices;
using?System.Threading;
namespace?GPIO
{
????public?partial?class?Form1?:?Form
????{
????????[DllImport(“coredll.dll“?EntryPoint?=?“DeviceIoControl“?SetLastError?=?true)]
????????internal?static?extern?int?DeviceIoControl(
????????????IntPtr?hDevice
????????????int?dwIoControlCode
????????????byte[]?lpInBuffer
????????????int?nInBufferSize
????????????byte[]?lpOutBuffer
????????????int?nOutBufferSize
????????????ref?int?lpBytesReturned
????????????IntPtr?lpOverlapped);
????????[DllImport(“coredll.dll“)]
????????private?static?extern?IntPtr?CreateFile(
????????????string?lpFileName
????????????//?要打開的串口名稱???????????
????????????uint?dwDesiredAccess
????????????//?指定串口的訪問方式一般設置為可讀可寫方式???
????????????int?dwShareMode
????????????//?指定串口的共享模式串口不能共享所以設置為0???
????????????int?lpSecurityAttributes
????????????//?設置串口的安全屬性WIN9X下不支持應設為NULL???
????????????int?dwCreationDisposition
????????????//?對于串口通信創建方式只能為OPEN_EXISTING???
?????????????int?dwFlagsAndAttributes
????????????//?指定串口屬性與標志設置為FILE_FLAG_OVERLAPPED(?重疊I/O操作?)指定串口以異步方式通信???
?????????????int?hTemplateFile
????????????//?對于串口通信必須設置為NULL???
????????);
????????private?const?uint?GENERIC_READ?=?0x80000000;
????????private?const?uint?GENERIC_WRITE?=?0x40000000;
????????private?const?int?OPEN_EXISTING?=?3;
????????public?Form1()
????????{
????????????InitializeComponent();
????????}
????????IntPtr?gpiodriver;
????????private?void?button1_Click(object?sender?EventArgs?e)
????????{
????????????gpiodriver?=?CreateFile(“GIO1:“?GENERIC_READ?|?GENERIC_WRITE?0?0?OPEN_EXISTING?0?0);
????????????if?(gpiodriver?==?(IntPtr)(-1))
????????????{
????????????????MessageBox.Show(“打開GPIO設備失敗!“);
????????????}
????????????else
????????????{
????????????????int?bytesReturned?=?0;
????????????????DeviceIoControl(gpiodriver?0x01?null?0?null?0?ref?bytesReturned?IntPtr.Zero);
????????????????Thread.Sleep(5000);
????????????????DeviceIoControl(gpiodriver?0x02?null?0?null?0?ref?bytesReturned?IntPtr.Zero);
????????????????Thread.Sleep(5000);
????????????????DeviceIoControl(gpiodriver?0x03?null?0?null?0?ref?bytesReturned?IntPtr.Zero);
????????????????Thread.Sleep(5000);
????????????????DeviceIoControl(gpiodriver?0x04?null?0?null?0?ref?bytesReturned?IntPtr.Zero);
????????????????Thread.Sleep(5000);
????????????????DeviceIoControl(gpiodriver?0x06?null?0?null?0?ref?bytesReturned?IntPtr.Zero);
????????????????Thread.Sleep(5000);
????????????????DeviceIoControl(gpiodriver?0x07?null?0?null?0?ref?bytesReturned?IntPtr.Zero);
????????????????Thread.Sleep(5000);
??????????????
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????7680??2012-09-04?15:43??GPIO\GPIO\bin\Debug\GPIO.exe
?????文件??????19968??2012-09-04?15:43??GPIO\GPIO\bin\Debug\GPIO.pdb
?????文件???????3525??2012-09-04?16:06??GPIO\GPIO\Form1.cs
?????文件???????2163??2012-09-04?14:56??GPIO\GPIO\Form1.Designer.cs
?????文件???????6298??2012-09-04?14:56??GPIO\GPIO\Form1.resx
?????文件???????4057??2012-09-04?15:14??GPIO\GPIO\GPIO.csproj
?????文件????????198??2012-09-04?15:22??GPIO\GPIO\GPIO.csproj.user
?????文件????????842??2012-09-04?15:14??GPIO\GPIO\obj\Debug\GPIO.csproj.GenerateResource.Cache
?????文件???????7680??2012-09-04?15:43??GPIO\GPIO\obj\Debug\GPIO.exe
?????文件????????180??2012-09-04?15:14??GPIO\GPIO\obj\Debug\GPIO.Form1.resources
?????文件??????19968??2012-09-04?15:43??GPIO\GPIO\obj\Debug\GPIO.pdb
?????文件????????180??2012-09-04?15:14??GPIO\GPIO\obj\Debug\GPIO.Properties.Resources.resources
?????文件????????527??2012-09-04?15:43??GPIO\GPIO\obj\GPIO.csproj.FileListAbsolute.txt
?????文件????????349??2012-09-04?14:26??GPIO\GPIO\Program.cs
?????文件???????1123??2012-09-04?14:26??GPIO\GPIO\Properties\AssemblyInfo.cs
?????文件???????2345??2012-09-04?14:26??GPIO\GPIO\Properties\Resources.Designer.cs
?????文件???????5618??2012-09-04?14:26??GPIO\GPIO\Properties\Resources.resx
?????文件???????1067??2012-09-04?14:26??GPIO\GPIO.sln
????..A..H.?????14336??2012-09-04?16:26??GPIO\GPIO.suo
?????目錄??????????0??2012-09-04?14:26??GPIO\GPIO\obj\Debug\TempPE
?????目錄??????????0??2012-09-04?15:19??GPIO\GPIO\bin\Debug
?????目錄??????????0??2012-09-04?15:43??GPIO\GPIO\obj\Debug
?????目錄??????????0??2012-09-04?14:26??GPIO\GPIO\bin
?????目錄??????????0??2012-09-04?15:14??GPIO\GPIO\obj
?????目錄??????????0??2012-09-04?14:26??GPIO\GPIO\Properties
?????目錄??????????0??2012-09-04?16:06??GPIO\GPIO
?????目錄??????????0??2012-09-04?14:26??GPIO
-----------?---------??----------?-----??----
????????????????98104????????????????????27
............此處省略0個文件信息
- 上一篇:C# 三角形網格等值線繪制案例源碼
- 下一篇:C# 自定義帶搜索下拉框
評論
共有 條評論