LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Re-initializing my array with reset button

Solved!
Go to solution
0 Kudos
Message 51 of 93
(1,384 Views)

A quick question: How large is the array output by the 'Registers' output of the Serial Master Query? I'm guessing it's just one value?

 

Followed by a few quick comments:

  • You're using Delete From Array to take the outputs of your array of data values and place them in the bundle. I'm not certain you still need this cluster or the separate values, but if you do then you can instead use Index Array, and drag the node down. It will give the 0th, 1st, ... element if you don't wire the numeric input specifying index.
  • You still have the loop in Logging Volt, containing an event structure with the timeout holding the subVI. This SubVI has its own loop. It's extremely unlikely that you want the subVI to contain a loop, or any event structure. I'm not certain you want the loop even in the main VI there, you might prefer to have Logging Volt transition into Logging Volt unless Stop is pressed. An example (that doesn't do anything except show one state requeuing itself) is below. I'm not sure if you already saw this link (or indeed, even if I already posted it) but you should check this State Machine tutorial.

statemachi ne.png


GCentral
0 Kudos
Message 52 of 93
(1,379 Views)

@cbutcher wrote:

A quick question: How large is the array output by the 'Registers' output of the Serial Master Query? I'm guessing it's just one value?

 

Followed by a few quick comments:

  • You're using Delete From Array to take the outputs of your array of data values and place them in the bundle. I'm not certain you still need this cluster or the separate values, but if you do then you can instead use Index Array, and drag the node down. It will give the 0th, 1st, ... element if you don't wire the numeric input specifying index.
  • You still have the loop in Logging Volt, containing an event structure with the timeout holding the subVI. This SubVI has its own loop. It's extremely unlikely that you want the subVI to contain a loop, or any event structure. I'm not certain you want the loop even in the main VI there, you might prefer to have Logging Volt transition into Logging Volt unless Stop is pressed. An example (that doesn't do anything except show one state requeuing itself) is below. I'm not sure if you already saw this link (or indeed, even if I already posted it) but you should check this State Machine tutorial.

statemachi ne.png


Yes, you are right, I only want one value from it. 

 

Im not sure what you mean by there is another loop inside my subVI because I removed the while loop that is within that subVI already.

0 Kudos
Message 53 of 93
(1,375 Views)

@Jarrold wrote:
Im not sure what you mean by there is another loop inside my subVI because I removed the while loop that is within that subVI already.

Oops - my mistake. I was still looking at the one you most recently uploaded. I'm attaching a slightly modified SubVI with another VI, perhaps you can see what I mean about packaging some of this up. I used Build Array on the output to make the wires play nicely, but you don't need to do this - just make all of the outputs be the single value and you can also drop the Index Array from outside of the case structure. I just didn't want a load of broken wires.

 

This can also be placed in a For loop like I mentioned.


GCentral
Download All
0 Kudos
Message 54 of 93
(1,370 Views)

Hey cbutcher, 

 

I would like to check with you, do you know why my radio button is stuck in a stage whereby it only allows me to click once and the whole program gets stucks there?

0 Kudos
Message 55 of 93
(1,366 Views)

@Jarrold wrote:

Hey cbutcher, 

 

I would like to check with you, do you know why my radio button is stuck in a stage whereby it only allows me to click once and the whole program gets stucks there?


No, I don't. Looking at the last version that I have though, I would guess that it acts as if it was the previous value you clicked on (not the most recent, but the one before).

 

This is because the control is read in the beginning of the while loop's iteration, and the event structure uses the value from before the event change. You should either place the control inside the event structure in the value change event, or use the "New Value" input from the Event structure on the left hand side of the structure.


GCentral
0 Kudos
Message 56 of 93
(1,363 Views)

@cbutcher wrote:

@Jarrold wrote:

Hey cbutcher, 

 

I would like to check with you, do you know why my radio button is stuck in a stage whereby it only allows me to click once and the whole program gets stucks there?


No, I don't. Looking at the last version that I have though, I would guess that it acts as if it was the previous value you clicked on (not the most recent, but the one before).

 

This is because the control is read in the beginning of the while loop's iteration, and the event structure uses the value from before the event change. You should either place the control inside the event structure in the value change event, or use the "New Value" input from the Event structure on the left hand side of the structure.


Thanks for the help there ! 

 

Anyway, back to the question. Right now I am getting data but my wavechart isn't updated real time at all. I manage to create my own set of diagrams with reference to the one you shared with me. Now I just need to figure out how to ensure that my mainVI wavechart can receive real time updates just like my SubVI.

 

I am still trying to figure out your read single address subVI. Can you explain again why are you doing that so i can get a better understanding. I feel so dumb, sorry if I seem to have never ending problems :(:(

 

 

0 Kudos
Message 57 of 93
(1,359 Views)

 


@Jarrold wrote:

I am still trying to figure out your read single address subVI. Can you explain again why are you doing that so i can get a better understanding. I feel so dumb, sorry if I seem to have never ending problems :(:(


So the ReadSingleAddress.vi was just because I see that in your ModBus Data VI.vi, you use the same collection of code many times - you create a MB Modbus Command cluster (in which only the address changes from one call to another), then call MB Serial Master Query.vi, then unbundle the cluster output and take the Registers array, then divide the array by 10, then index the first element (this part is currently outside of the case structure).

 

By placing all of that code inside a subVI, and only taking the necessary input (VISA, Address, Serial Parameters, Error In) and giving necessary output (VISA, Error out, and the data value you care about - seemingly this is Registers[0] / 10 -> dbl) you can save a lot of block diagram space and make it much easier to check things are working properly. You can line these up easily, or even better, pass an array of addresses and get an array of outputs, like this:

 

exampleloop.png

 

If you remove the loop and event structure from the subVI (which you just uploaded) and instead only use the loop in the main VI, it should pass out normally. You'll get one reading for each register, each time you call the subVI, and it will be called over and over again by the main VI, which will collect the data and add it to the chart in the main VI.


GCentral
0 Kudos
Message 58 of 93
(1,354 Views)

@cbutcher wrote:

 


@Jarrold wrote:

I am still trying to figure out your read single address subVI. Can you explain again why are you doing that so i can get a better understanding. I feel so dumb, sorry if I seem to have never ending problems :(:(


So the ReadSingleAddress.vi was just because I see that in your ModBus Data VI.vi, you use the same collection of code many times - you create a MB Modbus Command cluster (in which only the address changes from one call to another), then call MB Serial Master Query.vi, then unbundle the cluster output and take the Registers array, then divide the array by 10, then index the first element (this part is currently outside of the case structure).

 

By placing all of that code inside a subVI, and only taking the necessary input (VISA, Address, Serial Parameters, Error In) and giving necessary output (VISA, Error out, and the data value you care about - seemingly this is Registers[0] / 10 -> dbl) you can save a lot of block diagram space and make it much easier to check things are working properly. You can line these up easily, or even better, pass an array of addresses and get an array of outputs, like this:

 

exampleloop.png

 

If you remove the loop and event structure from the subVI (which you just uploaded) and instead only use the loop in the main VI, it should pass out normally. You'll get one reading for each register, each time you call the subVI, and it will be called over and over again by the main VI, which will collect the data and add it to the chart in the main VI.


Hi there cbutcher,

 

I finally understand what you mean. This method really tidied up my codes like crazy ! 

 

After implementing this technique that you showed me, I am able to plot the wavechart and produce the data in an array. The following are the problems now.

 

1. It is observed that the wavechart displays the combined result of my array table. However, what i want is that the wavechart display only information of individual elements.

(Im not sure if this is clear, do let me know.)

With respect to the attachments below, refer to FP2.

For example, element 0 is 21.8. I would want the wavechart to display only 21.8 and not all the elements because each element represent a different register which also represents a different information. 

 

2. I would like to convert the array into a 2D array such that everytime i click on "start" it will produce a new set of information and shift the only information to the right. This can be done with a "reversed array" function even though the information is a 2D array?

 

 

Download All
0 Kudos
Message 59 of 93
(1,345 Views)

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.

GCentral
0 Kudos
Message 60 of 93
(1,341 Views)