资源简介
结合实际项目通过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
相关资源
- CCS中如何生成LIB文件-并在另外CCS项目
- LzmaLib
- Adobe Illustrator CS5原版amtlib.dll文件
- IpHlpApi.h&IpHlpApi.lib
- 开源的nmealib
- zlib 最新 1.2.8 win32 win64 编译好的dll
- CJLibrary Version 6.09
- Element_Components_v2.1.0.rplib
- libaio-0.3.107-10.el6.x86_64.rpm
- Library图书馆图书管理系统
- librdkafka win7 64位 vs2015编译Release版本
- VS2012OpenGL配置所需要的全部libdllh文件
- LibXL for Windows 3.8.3 最新版Excel操作库带
- Experimental investigation of the phase equili
- Libevent官方原版高清帮助文档
- 远程桌面协议 (RDP)控件库
- EhLib v6.0 Full Source.rar
- duilib webkit内核浏览器控件
- IBM 4U Universal Tape Library产品手册
- fastlib——十分好用的画图工具
- 编译好的json_lib.lib 包含64位,32位,头
- windows 32位64位 x264库,包含libdll和头文
- libx264静态库,windows x86版本
- libconfig-1.4.9.tar.gz
- Experimental investigation and thermodynamic c
- glibc-headers-2.5-42.x86_64.rpm
- STMicroelectronics 所有封装集成库intlib格
- libgit-platinum.so
- shape_predictor_68_face_landmarks.dat.bz2 68个标
- 基于libsvm的图像分割代码
评论
共有 条评论