资源简介
结合实际项目通过libusb 读取电路板中的数据信息。
代码片段和文件信息
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.Windows.Forms.DataVisualization.Charting;
using LibUsbDotNet;
using LibUsbDotNet.Main;
using LibUsbDotNet.Info;
using System.Threading;
using System.Collections.objectModel;
using LibUsbDotNet.DeviceNotify;
using System.IO;
using System.Drawing.Drawing2D;
using System.Runtime.InteropServices;
using USBHIDControl;
namespace alt
{
public partial class Form1 : Form
{
private DateTime LastDataEventDate = DateTime.Now;
private int pId = 0x5750;
private int vId = 0x0483;
private UsbDevice usbDevice = null;
private UsbDeviceFinder usbFinder = null;
public UsbEndpointWriter writer = null;
public UsbEndpointReader reader = null;
IDeviceNotifier deviceNotifier = LibUsbDotNet.DeviceNotify.DeviceNotifier.OpenDeviceNotifier();
delegate void SetTextCallback(string text);//安全线程访问txtReadInt的值
delegate void SetUsbCallback(byte[] b);
public Form1()
{
InitializeComponent();
}
/**
* 往设备发送信息
* */
private void func_writeToRead(string msg)
{
ErrorCode ec = ErrorCode.None;
try
{
if (usbDevice == null)
{
FindAndOpenUSB();
}
//打开并读取read endpoint1
UsbEndpointReader reader = usbDevice.OpenEndpointReader(ReadEndpointID.Ep02);
UsbEndpointWriter writer = usbDevice.OpenEndpointWriter(WriteEndpointID.Ep01);
if (!String.IsNullOrEmpty(msg))
{
reader.DataReceived += (OnRxEndPointData);
reader.DataReceivedEnabled = true;
int bytesWritten;
ec = writer.Write(Encoding.Default.GetBytes(msg) 2000 out bytesWritten);
if (ec != ErrorCode.None) { showMessage(“读取失败,重新插拔设备!“); }
LastDataEventDate = DateTime.Now;
//如果长时间内为收到数据,则结束
while ((DateTime.Now - LastDataEventDate).TotalMilliseconds < 100)
{
}
reader.DataReceivedEnabled = false;
reader.DataReceived -= (OnRxEndPointData);
Console.WriteLine(“\r\n Done! \r\n“);
}
else
throw new Exception(“Nothing to do.“);
}
catch (System.Exception ex)
{
Console.WriteLine();
Console.WriteLine((ec != ErrorCode.None ? ec + “:“ : string.Empty) + ex.Message);
}
//读取数据后执行
finally
{
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 6872 2018-10-12 08:52 Form1.cs
文件 150016 2018-09-12 15:27 LibUsbDotNet.dll
文件 2323232 2018-09-12 15:20 LibUsbDotNet_Setup.2.2.8.rar
文件 178 2018-10-12 08:54 说明.txt
----------- --------- ---------- ----- ----
2480298 4
相关资源
- hibernate3.6.7
- lib.zip
- PDFLib开发文档.rar
- libsndfile的vs2010工程
- Indy10.6和OpenSSL解决D7下GET&POST;乱码
- Dlib各种组件
- spring框架所需要的lib包
- Libgdx TexturePacker 肥肥汉化版基于v3.2
- libcurl静态库[支持https]
- matplotlib-1.3.1.win-amd64-py2.7.exe
- libevent参考手册中文版+libevent源码深度
- Tencent QQ皮肤图像文件格式Gft转png或
- matplotlib中文用户手册 飞龙译
- windows下调用openssl需要的include和lib
- libpsd v1.0
- Axure_library_CloudBU_1.0.rar
- g77安装包for tetview
-
window vs2010 中安装libxm
l2所需要的文 - Linux下PTAM安装包,全套,TooN、libcvd、
- linux 使用jrtplib收发h.264视频文件
- xilinx_fpga_7系列 Altium library
- VS2015 编译的 GSL(GNU Scientific Library)
- librdkafka win7 64位 vs2015编译Release.rar
- 周立功 CAN LIB 使用手册
- 逐飞科技KEA128库V2.2.16等.zip
- libwebsockets-master.rar
- libevent参考手册(中文版).pdf
- libcurl大文件
- Qt + VS环境下,利用avilib实现简单的录
- PDFlib-6.0.2-Windows
评论
共有 条评论