LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to return arrays from subVi?

Hi everyone,

 

I'm trying to return an array from a subVi but it is not working. Basically, my subVi performs a write to a controller and read back the data, and store them in an array. The read also returns a number indicating a good or bad read. The commands are working because the controller responds appropriately. However, the indicator from the main Vi shows the right number of array elements but all zeros which is incorrect. Please help!

Cat Happy

Thanks in advance!

 

 

Download All
0 Kudos
Message 1 of 10
(3,282 Views)

Just attaching code pictures is useless to troubleshoot this. Where Is the output array connected to the connector pane (I don't see anything in the main VI that would indicate where it would return that array). I don't understand why "appended array" is not wired where you currently have the local variable. Why do you think you need a local variable at all?

 

Please attach the VIs instead.

0 Kudos
Message 2 of 10
(3,273 Views)

Hi altenbach,

 

My apologies. I have attached all the vi's below. The appended array is used to pass the command to the write function and is not related to the read out. I must have accidentally deleted the return array indicator terminal. The return array is called "return receipt" in the Write and Read.vi. The Template.vi is my main vi. 

 

Thanks!

0 Kudos
Message 3 of 10
(3,260 Views)

Your "Development Template.vi" calls "Read and Write.vi" which sends an array to indicator "Return Receipt", but in "Development Template.vi" you haven't wired the ""Return Receipt" output of "Read and Write.vi" to anything; so of course it doesn't go anywhere.

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 4 of 10
(3,252 Views)

Hi paul_cardinale,

I accidentally deleted the indicator to the return receipt terminal before I closed out of LabView. I mentioned it in my reponse to altenbach. When I had the indicator there, it showed the correct number of elements but the element values were zeroes.

 

I currently don’t have a computer with Labview installed so I can’t make any changes.

Thanks! 🙂

 

0 Kudos
Message 5 of 10
(3,248 Views)

So, I placed a random pop-up message inside the for-loop of the Write and Read.vi to see if the loop was executed and somehow I got the correct reading at the end of the main execution. I still don't know exactly why....? 

0 Kudos
Message 6 of 10
(3,234 Views)

be more precise in your wording, we don't want to guess.

moreover, we can't run your code, as we don't have acces to the necesarsy SiUSBXp.dll

- does the .dll need to some external hardware to be execute properly?

 

so, this is all about  the call libraray node "SiUSBXp.dll:SI_Read" in the subVi "write and Read.vi"

not returning the desired output.

 

Ask the developer of the .dll

 

- do you have a manual, which we could access online?

- have you imported the .dll by yourself, or did you get a set a .vis from your supplier?

- are you sure you are using it properly?

e.g. could it be that you need a new handle for each iteration?

e.g. is Buffer supposed to be an Array or a Scalar?

uint32_t SI_Read(uint32_t Handle, uint64_t *Buffer, uint8_t NumBytesToRead, uint32_t *NumBytesReturned);

 

After you run your code,

is the array "return receipt" empty, containing no elements at all?

 

empty.PNG.

 

or does it return an array of 0s with the right # of elements?

0.JPG

 

 

 

 

 

 

 

 

 

 

0 Kudos
Message 7 of 10
(3,219 Views)

Hi alexderjuengere,

This is the manual to the .dll I'm using silabs and it's required the controller to execute.

I had to import the .dll myself. The supplier only provided the commands to talk to the unit.

I have already written a program that works. Now, I want to use subVi's to make the program less messy looking.

When executing my code, I got the right size of array but all filled with 0's (Picture 2).

 Also, I was able to get the correct reading back by adding a "Display Message to User" to the for-loop. I found this about before bed so I haven't had a chance to do any further testing  Smiley Tongue .

Robot Happy

Thanks! 

0 Kudos
Message 8 of 10
(3,209 Views)

I'm trying to understand your Write and Read VI.  For one thing, it is a little confusing to have one routine that does both a Read (where data are expected as an output and a Write (where data are expected as an input).  I recommend that you adopt a (more) consistent use of Connectors.  if you are going to have Handle In and Handle Out, they should be "opposite" each other (i.e. both in the top outside terminals).  I'd put the Input (or Output) array second, Byte Count (in and out) third, and use the top and bottom, if required, for Status or other things.

 

I think Read is supposed to be able to "wait until all the bytes have been read".  If you are getting a buffer with 0's everywhere, it suggests you are not waiting for the number of bytes to be read.  I also see you seem to be using a For loop to read one byte at a time (I could be mistaken -- documentation isn't your strong suit), but the underlying Read function is designed to read N bytes, I think.

 

I'd scrap your current code, write simple low-level "wrappers" for the DLLs (or, maybe better, create a State Machine that wraps things for you, so you can "Init", "Open", "Read", "Write", etc. and keep the Handle "out of sight" of the User).  With such an improvement, writing the code to "do what you want" should be simple.  Note that this should also allow you to design some tests to ensure that your low-level code is "doing what you want" (as opposed to "doing what you tell it to do").

 

Bob Schor

0 Kudos
Message 9 of 10
(3,198 Views)

So, I placed a random pop-up message inside the for-loop of the Write and Read.vi to see if the loop was executed and somehow I got the correct reading at the end of the main execution. I still don't know exactly why....?
[...]

 Also, I was able to get the correct reading back by adding a "Display Message to User" to the for-loop.


"Display Message to User" is an Express VI, 

but I suppose you don't see the read fail message?

I would auto-index the return type to an array and manually look at the 0s and 1s, instead of relying on the case structure

 

 

Also, I suggest to replace the whole "Case-Structure-Express-Vi" construct in the read-write-sub-vi with the Wait.vi set to 10 ms

http://zone.ni.com/reference/en-XX/help/371361P-01/glang/wait_ms/

 

 

 

0 Kudos
Message 10 of 10
(3,164 Views)