From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Re-initializing my array with reset button

Solved!
Go to solution

@cbutcher wrote:

I wonder - do you store your code in a git repository or similar? Again I'm faced with wondering what other changes you might have made, and how you want to process the output in this VI (which I think is the subVI, ModBus Data VI?) and the main VI, and possibly other parts of the main VI.

 

If you upload the most recent versions of the main VI, the subVI and any other bits that might be relevant, I can keep deleting old copies and downloading new copies, but if you're storing them somewhere online and can give me read access, I can just keep pulling your changes and we can work through your code that way.

 

I'm guessing you don't, so this is a long post saying - can I see the main VI as well? 🙂 But who knows, maybe you're a Git master (in which case, please give me some tips 🙂 )

 

Edit: As a couple of quick follow up notes:

  • You can initialize the visa connection outside of the device case - they all need to be initialized, right?
  • You probably don't want a Time Elapsed case in the SubVI - the main VI should handle this situation, and just end the loop when the time is elapsed. Then it won't call the subVI anymore
  • Make sure all of the reads you make using the VI I gave you are to Read a register (i.e. command 3). I saw in your previous BD, you had one read to alarm status.

Hi there cbutcher,

Sorry for the late reply. I was taking sometime to retidy my code because I am cultivating this good habit 😉 😉

 

Anyway, attached is the latest VI. By the way, are you able to run my VI? If you are, then I can give you a few steps so that you can understand how my program runs and we will be able to to communicate better ! 

0 Kudos
Message 61 of 93
(653 Views)

Answering the following questions

  • You can initialize the visa connection outside of the device case - they all need to be initialized, right?

Does it matter if i initialize inside or outside the case? Eg. Slows the VI down? 

Anyway, I have shifted it outside the case already. 

 

  • You probably don't want a Time Elapsed case in the SubVI - the main VI should handle this situation, and just end the loop when the time is elapsed. Then it won't call the subVI anymore

I am not sure how to go about doing this. Because I only want the information to be displayed in the array when time elapsed. As for the wavechart, I would like to have a real-time update. I have been stucked here quite some time because I do not have any idea how to approach this.

 

  • Make sure all of the reads you make using the VI I gave you are to Read a register (i.e. command 3). I saw in your previous BD, you had one read to alarm status.

Yeah, all reads are using command 3. As for the alarm status, it is a special case and I have removed it. After doing up the basic needs then i will attempt to solve this problem again 🙂

0 Kudos
Message 62 of 93
(653 Views)

It doesn't matter from an execution speed point of view - but if you put it inside the case, you have to write it every case. Outside, you only have to write it once! Do this for all the code you're using in every case - if you can save yourself writing something over and over, do it (same idea with the SubVI!)

 

I'm pretty sure you can solve your array/wavechart problem of not updating properly by inserting a Build Array node in the output - so that the 1D array becomes 2D. Don't expand the node - just have a single input and the one output. This should make your chart do what you want (I think - maybe I still don't understand what you want)

 

Regarding running the code - no, sorry. I don't have the hardware to make this work. I could probably try and hook it up to the machine tool I do have access to, but I'm not going to do that 😉 I have enough problems with it without accidentally destroying the parameter set or something 😛

 

I think a point you might be missing, is that the outputs from the while loop don't output a value every iteration. Outputs from a loop only output their values once the loop finishes running. For solid squares, they output the last, most recent value. For the [] boxes, they output an array of values - this is what you're using with the Read Single Address VI. But it's important to know, they aren't sent one at a time - they come as a block, once the loop finishes.

 

Some of your boolean outputs from the main VI sub-loop suggest maybe you forgot this 😉

 

 


GCentral
Message 63 of 93
(647 Views)

This example snippet might be helpful.

elapsedRandomData.png


GCentral
Message 64 of 93
(643 Views)

@cbutcher wrote:

It doesn't matter from an execution speed point of view - but if you put it inside the case, you have to write it every case. Outside, you only have to write it once! Do this for all the code you're using in every case - if you can save yourself writing something over and over, do it (same idea with the SubVI!)

 

I'm pretty sure you can solve your array/wavechart problem of not updating properly by inserting a Build Array node in the output - so that the 1D array becomes 2D. Don't expand the node - just have a single input and the one output. This should make your chart do what you want (I think - maybe I still don't understand what you want)

 

Regarding running the code - no, sorry. I don't have the hardware to make this work. I could probably try and hook it up to the machine tool I do have access to, but I'm not going to do that 😉 I have enough problems with it without accidentally destroying the parameter set or something 😛

 

I think a point you might be missing, is that the outputs from the while loop don't output a value every iteration. Outputs from a loop only output their values once the loop finishes running. For solid squares, they output the last, most recent value. For the [] boxes, they output an array of values - this is what you're using with the Read Single Address VI. But it's important to know, they aren't sent one at a time - they come as a block, once the loop finishes.

 

Some of your boolean outputs from the main VI sub-loop suggest maybe you forgot this 😉

 

 


Great news, cbutcher ! 🙂

My code is working perfectly great and it is working the way I want it to at this point of time. I would be adding more features/functionalities tomorrow.(Hopefully, you will still assist me if i happen to bump into any sort of problems. I know I am really full of problems 😞 ) I would like to share my code with you and perhaps you can take a look at some of the things I have done that you think that there might be a better way to do it, please let me know. (Cause I would like to learn more from you too 🙂 )

 

Yours sincerely,

Jarrold

 

 

0 Kudos
Message 65 of 93
(640 Views)

Jarrold wrote:

 

My code is working perfectly great and it is working the way I want it to at this point of time. I would be adding more features/functionalities tomorrow.(Hopefully, you will still assist me if i happen to bump into any sort of problems. I know I am really full of problems 😞 ) I would like to share my code with you and perhaps you can take a look at some of the things I have done that you think that there might be a better way to do it, please let me know. (Cause I would like to learn more from you too 🙂 )

Yours sincerely,

Jarrold


Fantastic! I'm really glad that you could get it to do what you wanted. I'm sure you're also very happy!

 

Here are a few more thoughts:

  • In a few places you have For loops with a constant 1 wired to the N. You can remove the loop if it will only run once 😉
  • In a few places you use Build Array with an empty array of the same dimension as the second input. You don't need this either - it won't do anything. If you use Build Array, it should either append elements to an existing array of that element type (e.g. adding one double to an array of doubles) or concatenate two arrays of the same dimension (this is how you have it set up, but the first is empty, so it does nothing). You can just remove it if you're concatenating with an empty array. Note, this isn't always true if they are different dimensions (e.g. adding the first double to an empty array of doubles).
  • You should try where possible (which is almost always possible) to have wires go from left to right. This convention makes it much clearer which are inputs and which are outputs. For example, in your Logging Volt case, I moved some of the parts around, removed some empty For loops and Build Arrays, and shuffled the boolean and array outputs to the right side of the inner While loop. Hopefully you'll agree it's a little easier to read (some broken wires, these are because I don't have typedefs. They're attached in the VI).

exampleClean.png

 

As a longer point, subVIs should be used to do one thing. I'll expand on that later - have to go now (but you can look up SRP if you want)


GCentral
Message 66 of 93
(634 Views)

@cbutcher wrote:

Jarrold wrote:

 

My code is working perfectly great and it is working the way I want it to at this point of time. I would be adding more features/functionalities tomorrow.(Hopefully, you will still assist me if i happen to bump into any sort of problems. I know I am really full of problems 😞 ) I would like to share my code with you and perhaps you can take a look at some of the things I have done that you think that there might be a better way to do it, please let me know. (Cause I would like to learn more from you too 🙂 )

Yours sincerely,

Jarrold


Fantastic! I'm really glad that you could get it to do what you wanted. I'm sure you're also very happy!

 

Here are a few more thoughts:

  • In a few places you have For loops with a constant 1 wired to the N. You can remove the loop if it will only run once 😉
  • In a few places you use Build Array with an empty array of the same dimension as the second input. You don't need this either - it won't do anything. If you use Build Array, it should either append elements to an existing array of that element type (e.g. adding one double to an array of doubles) or concatenate two arrays of the same dimension (this is how you have it set up, but the first is empty, so it does nothing). You can just remove it if you're concatenating with an empty array. Note, this isn't always true if they are different dimensions (e.g. adding the first double to an empty array of doubles).
  • You should try where possible (which is almost always possible) to have wires go from left to right. This convention makes it much clearer which are inputs and which are outputs. For example, in your Logging Volt case, I moved some of the parts around, removed some empty For loops and Build Arrays, and shuffled the boolean and array outputs to the right side of the inner While loop. Hopefully you'll agree it's a little easier to read (some broken wires, these are because I don't have typedefs. They're attached in the VI).

exampleClean.png

 

As a longer point, subVIs should be used to do one thing. I'll expand on that later - have to go now (but you can look up SRP if you want)


Hi cbutcher !

A very good morning ! 🙂 I will make the necessary changes that you have mentioned above. Because of my lack of Labview knowledge, thus I created a lot of redundant steps. I am sure those changes would work perfectly fine. 

 

As for SRP that you mentioned, I totally agree that one SubVI should only have one and solely one purpose. However, I faced problem with my program unable to load real time data thus i decided to put the whole block diagram inside. This happened for both my "Logging Temp" and "Logging Volt"'s clock. 

 

Lastly, I agree that inputs should enter from the left and exit from the right for better readability. 

Cheers and I truly appreciate your help all these while ! 

0 Kudos
Message 67 of 93
(625 Views)

Can you share one or both of your Clock VIs? I know you mentioned this problem with the updates before and I'm curious as to what's happening inside those VIs that makes them behave badly when separated.

 

You're right that they were the example I was thinking of - you have a set of inputs like Min, Sec, Elapsed Time Ref (string), Stop and the output Stop, and those all belong in a Clock subVI. At the same time you have the Modbus info, Model, and array/waveform outputs, which are part of a Read subVI. I'm not certain what you're doing with the waveform chart reference, but that would probably also belong with the Read, if it's needed. It might not need to be in the loop, depending on what you're using it for.


GCentral
0 Kudos
Message 68 of 93
(621 Views)

Hi there cbutcher, attached are the respective subVIs.

VoltClock - for voltage

Clock - for temperature

 

By the way, I also attached one diagram and would like to know how can i simplify it. I am sure there is a way but due to my lack of experience, I am unable to design a simplified circuit with similar function. Please enlighten me ! 🙂

Download All
0 Kudos
Message 69 of 93
(618 Views)

Here's my attempt at the ClockVI with some modifications - basically I just removed the loop. Can you check to see if it does what you want? You'll also need this snippet probably 🙂

 

clockvi_mod-snippet.png

 

Edit: Depending on how your measurement works, you might need to right click on the tunnel out of the loop and change the mode to Concatenating.


GCentral
0 Kudos
Message 70 of 93
(614 Views)