LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

.net constructor doesn't see all the objects

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.

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
Message 11 of 16
(1,619 Views)

Rolf,

 

Thanks for your help. I made it run but with issues:

  1. The SpecifiedDevice Dispose method crashes LabVIEW every time it goes through it. This happens for both LabVIEW 2016 and 2013, with whatever the VID or PID. I will report this to NI.
  2. I tried to use the System.EventHandler, which is inside the diagram disabled structure, but I don't know how to implement it, can you give some suggestions?
  3. The callback should be the way to get information from the board if anything happens there, such as a button press. But neither sending nor receiving is working yet. I was told that the board needs to be initialized, but I don't know how to do it in LabVIEW, below is the code:

            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);

            //

 

 

send_data.png

 

callback.png

0 Kudos
Message 12 of 16
(1,597 Views)

I realized that I uploaded as LabVIEW 2016, it's not convenient to people. I'll upload tomorrow as LabVIEW 2013.

0 Kudos
Message 13 of 16
(1,586 Views)

Hey, this line:

 

this.usb.OnDataRecieved += new UsbLibrary.DataRecievedEventHandler(this.usb_OnDataRecieved);

corresponds with this part in my example:

Event Callback registration.png

 

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. Smiley Very Happy

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
Message 14 of 16
(1,574 Views)

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.

 

send_data_2013.png

 

callback_2013.png

0 Kudos
Message 15 of 16
(1,564 Views)

@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.

USB Reader_Writer2.png

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.

 

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 16 of 16
(1,553 Views)