资源简介
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# 自定义带搜索下拉框
相关资源
- C# TIP文件生成和拆解
- C#解析HL7消息的库135797
- C# OCR数字识别实例,采用TessnetOcr,对
- 考试管理系统 - C#源码
- asp.net C#购物车源代码
- C#实时网络流量监听源码
- C#百度地图源码
- Visual C#.2010从入门到精通配套源程序
- C# 软件版本更新
- C#屏幕软键盘源码,可以自己定制界面
- 智慧城市 智能家居 C# 源代码
- c#获取mobile手机的IMEI和IMSI
- C#实现简单QQ聊天程序
- 操作系统 模拟的 欢迎下载 C#版
- C#写的计算机性能监控程序
- 用C#实现邮件发送,有点类似于outlo
- MVC model层代码生成器 C#
- c#小型图书销售系统
- C# Socket Server Client 通讯应用 完整的服
- c# winform 自动登录 百度账户 源代码
- C#编写的16进制计算器
- C#TCP通信协议
- C# 数据表(Dataset)操作 合并 查询一
- C#语音识别系统speechsdk51,SpeechSDK51L
- 数据库备份还原工具1.0 C# 源码
-
[免费]xm
lDocument 节点遍历C# - EQ2008LEDc#开发实例
- DirectX.Capturec# winform 操作摄像头录像附
- c# 实现的最大最小距离方法对鸢尾花
- C#版保龄球记分代码
评论
共有 条评论