📄 picwinusb.cs
字号:
////////////////////////////////////////////////////////////////////////////
//// PicWinUSB by J1M - www.hobbypic.com ////
//// ////
//// This aplication shows how to use Microsoft WinUSB driver with ////
//// a PIC 18F2550. Information has been extracted from MSDN: ////
//// ////
//// - How to Use WinUSB to Communicate with a USB Device: ////
//// http://www.microsoft.com/whdc/device/connect/WinUsb_HowTo.mspx ////
//// - WinUSB: ////
//// http://msdn2.microsoft.com/en-us/library/aa476426.aspx ////
//// - WinUSB User-Mode Client Support Routines: ////
//// http://msdn2.microsoft.com/en-us/library/aa476437.aspx ////
//// ////
//// PicWinUSB is offered AS-IS and without warranty of any kind. ////
//// You cannot copy, distribute or sell this code. ////
//// ////
////////////////////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
namespace PicWinUSB
{
public partial class PicWinUSB : Form
{
IntPtr iHandle; // global device handle definition
PicWinUSBAPI picwinusbapi = new PicWinUSBAPI();
public PicWinUSB()
{
Guid InterfaceGuid = new Guid("31415926-5358-9793-2384-626433832795"); // .Inf defined Guid
InitializeComponent();
iHandle = picwinusbapi.Init_PicWinUSB(InterfaceGuid);
}
private void led_Click(object sender, EventArgs e)
{
bool bres;
byte[] sdBuffer = new byte[2]; // Define send DataBuffer size
sdBuffer[0] = 0x00; //Mode
sdBuffer[1] = 0x01; //Led
bres = picwinusbapi.Write_PicWinUSB(iHandle, sdBuffer);
}
private void adc_Click(object sender, EventArgs e)
{
bool bres;
byte[] sdBuffer = new byte[1]; // Define send DataBuffer size
byte[] rdBuffer = new byte[2]; // Define recieve DataBuffer size
sdBuffer[0] = 0x01; //Mode
bres = picwinusbapi.Write_PicWinUSB(iHandle, sdBuffer);
bres = picwinusbapi.Read_PicWinUSB(iHandle, rdBuffer);
if (rdBuffer[0] == 1)
{
adcBar.Value = (int)(rdBuffer[1] * 100 / 254);
}
}
private void pictureBox1_Click(object sender, EventArgs e)
{
Process.Start("http://www.hobbypic.com");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -