本人最近在做USB通信,在开源网上下了个libusbdotnet,能够打开设备,在通信的时候 mEpWriter.Write(wr, 100);这句总是弹出警告未将对象引用设置到对象的实例,在网上看了半天也没结果,自己在他的Test_Bulk中新建一个button A,将他Write button触发的事件代码复制到button A事件下,再注释掉Write button下的事件,编译照常通过,点击A按钮,mEpWriter.Write(wr, 100);还是弹出未将对象引用设置到对象的实例,我是真的懵了libusbdotnet出错未将对象引用设置到对象的实例usb

解决方案 »

  1.   

     mEpWriter或 wr 为null
      

  2.   

    我也想过这个问题,我试过单独给byte[]wr赋值,结果还是一样
      

  3.   

    我监视查看了下,mEpWriter果然为null,但是我引用过程序集libusbdotnet啊
    using LibUsbDotNet;
    using LibUsbDotNet.Usb;
    using LibUsbDotNet.Usb.Info;
    using LibUsbDotNet.Usb.Internal;
    using LibUsbDotNet.Usb.Main;
    using LibUsbDotNet.DeviceNotify;
    using LibUsbDotNet.DeviceNotify.Info;
    namespace UF32
    {
        public partial class Form1 : Form
        {
              private UsbDevice dev;
              private UsbDeviceList devlist;
              int dev_index = 0;
              private  UsbEndpointWriter mEpWriter ;
              private  UsbEndpointReader mEpReader;
         }
    }