05-10-2017 10:06 AM
They are there to cast the generic .Net references into the right object class. I created them by right clicking on the refnum input of an accordingly configured property node for that class and selecting "Create Constant". And I deduced the type of them by looking at the source code of the SpecifiedDevice class in the according source file.
05-10-2017 04:48 PM
Rolf,
Thanks for your help. I made it run but with issues:
this.usb.ProductId = 68;
this.usb.VendorId = 5230;
this.usb.OnSpecifiedDeviceArrived += new System.EventHandler(this.usb_OnSpecifiedDeviceArrived);
this.usb.OnSpecifiedDeviceRemoved += new System.EventHandler(this.usb_OnSpecifiedDeviceRemoved);
this.usb.OnDeviceArrived += new System.EventHandler(this.usb_OnDeviceArrived);
this.usb.OnDeviceRemoved += new System.EventHandler(this.usb_OnDeviceRemoved);
this.usb.OnDataRecieved += new UsbLibrary.DataRecievedEventHandler(this.usb_OnDataRecieved);
this.usb.OnDataSend += new UsbLibrary.DataSendEventHandler(this.usb_OnDataSend);
//
05-10-2017 09:32 PM
I realized that I uploaded as LabVIEW 2016, it's not convenient to people. I'll upload tomorrow as LabVIEW 2013.
05-11-2017 02:14 AM
Hey, this line:
this.usb.OnDataRecieved += new UsbLibrary.DataRecievedEventHandler(this.usb_OnDataRecieved);
corresponds with this part in my example:
This means, the EventHander you are so frantically searching for IS the callback VI in LabVIEW. It's not implemented by the DLL so you could simply load it from the .Net assembly but the programmer (this means you) has to provide it, and the way you do this in LabVIEW is by creating a callback.
And to do that you take an Event Registration node, wire the object refnum which can register an event to the first parameter, select the specific event from the drop down list in that parameter, possibly wire a User Parameter datattype to the last optional parameter input of the Register for Event node and then right click on the node and select "Create Callback VI".
I could of course write the entire library for you, but I don't have the hardware to test and I would need to send you an invoice for the work for that. ![]()
05-11-2017 10:11 AM
rolfk, thanks for your help, I will study the issues.
The callback vi keeps running and I couldn't stop it except I close LabVIEW. I don't know what's wrong. Is it caused by removing the Dispose method? Because the Dispose method crashes LabVIEW, I have to remove it.
05-11-2017 11:18 AM - edited 05-11-2017 11:46 AM
@guangdew1 wrote:
rolfk, thanks for your help, I will study the issues.
The callback vi keeps running and I couldn't stop it except I close LabVIEW. I don't know what's wrong. Is it caused by removing the Dispose method? Because the Dispose method crashes LabVIEW, I have to remove it.
I'm not sure why the Dispose method crashes. The .Net code is convoluted enough that it is hard to see which routine gets called when and in what order. And I'm not a .Net Enthusiast or Profi either. What I know about .Net and C# is from trying to understand some code to translate it to other environments like Java, C and LabVIEW.
And the constructor node for the Find Specified Device method should not be necessary. This method is a static method and does not take any class input so the created object from the constructor is never used.
As to the callback VI not stopping, I'm afraid that is a by-product of how LabVIEW invokes it in order to make it available to the .Net component. LabVIEW can't really know when the external .Net component might decide to call the VI so it simply prepares it and once prepared it stays there in that special .Net callback context, ready to be invoked, until the application is completely closed. You might want to try to wire the refnum output of the Register Event node to the Unregister for Events node that is executed after the closing of the device. That should at least unreserve the callback VI. I forgot to add that in the example.
If I would be tasked to make this work, I would throw away the .Net code completely, write a shared library DLL in C, which does what the .Net assembly does, but in a simpler and more straight forward way and then interface that to LabVIEW.
Or if you only need to make this work for a specific vendor_id and product_id I would actually use VISA USB Raw to communicate to this device.