LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to populate 2D array


@altenbach wrote:

@eenjeruu wrote:

There are also multiple points plotted per reading taken, as shown in the image below - how do I make it only show one point per reading? 

 

eenjeruu_0-1669611728390.png

 


We can assume that you read stale data if the received string is identical to the previously received string (why that can happen is a different discussion and can probably be avoided). So just update the chart if the new string differs from the previous. Since this is a chart, doing conditional updates will cause your time axis to become nonlinear.



Thank you for the response. For this conditional updates, should I use a case structure? I previously used a timer connected to a case structure to output every 1 second but that "cut" off some readings, which is highly undesirable.

0 Kudos
Message 11 of 38
(710 Views)

@GerdW wrote:

Hi eenjeruu,

 


@eenjeruu wrote:

Either way, I managed to populate the array, but there are some issues


Why is this outer FOR loop dependent on the [i]of the WHILE loop? Do you expect zero samples in the first execution and 1000 samples in the 1001st iteration???

 

I wanted to make the number of rows of the array dependent on the number of values I get from the PLC but I think I can't imagine the flow 😞

 

Why do you prepend new samples to an evergrowing string?

Why do you need to parse that evergrowing string again and again? Why don't you parse the new data only/once?

 

I do not understand this, but I was basically given that portion as a skeleton code by someone who is also a beginner at labview. I am not sure what to do here, but it makes sense as to why the program crashes after 10-ish minutes.

 


@eenjeruu wrote:

after awhile, the values received are not what was specified by the PLC providing these values.


Unfortunately your "data" string is empty. It would help to set typical PLC response data as default data in this string indicator so we can examine it too…

 

The pseudocode of what is sent out by the PLC is as such (I do not know how to program this in labview unfortunately):

 

A:0.00,14.00,0.00 //exact string sent out by PLC

A=0

 

if A=0

A:0.00,14.00,0.00

A=1

 

if A=1

A:1.00,13.00,13.00

A=2

 

if A=2

A:2.00,12.00,24.00

A=3

 

if A=3

A:3.00,11.00,33.00

A=4

 

if A=4

A:4.00,10.00,40.00

A=5

 

if A=5

A:5.00,9.00,45.00

A=6

 

if A=6

A:6.00,8.00,48.00 

A=7

 

if A=7

A:7.00,7.00,49.00

A=0

 

this repeats itself.

Do you think it would be easier to parse a spreadsheet string using SpreadsheetStringToArray instead of using a loop with MatchRegEx?

 

I am not sure how to go about doing this, but I am open to ideas! Thank you very much for taking the time to look at my code.


 

0 Kudos
Message 12 of 38
(615 Views)

@altenbach wrote:

@altenbach wrote:

As a first step, create a hardware free simulation where you generate typical data in a slow while loop and then build up the 2D array the way you want.


See if this can give you some ideas.

 

altenbach_0-1669648529341.png

 


 

Unfortunately, I've seen many of your responses (big fan!!) to similar questions like mine and I've tried a lot of them out but I can't relate it back to my example, because of the way the TCP reading starts the while loop and then having to parse the received strings and extract the decimal values. Basically, I am tasked with creating a GUI to be used to monitor a fuel cell's performance.

 

The fuel cell is being linked to the PLC (FMD88-10), which will send values of:
A - current, voltage, power

B - 5 temperatures of the fuel cell (therefore 5 columns needed in the array)

C - 12 cell voltages

D - 4 analog voltages

E - fan blower 1, fan blower 2, cathode blower, hydrogen pressure.

 

Each of these values were set by my PLC to simulate before using it for actual testing. B-E are all static values, as such:

eenjeruu_0-1669684135550.png

I was informed that I could use a TCP connection to connect the PLC to Labview, or using MODBUS also works (manufacturer mentioned)

eenjeruu_1-1669684226780.png

My colleague figured out how to use the TCP protocol, so that was what we used. When the GUI receives a signal from the PLC, the while loop will run indefinitely until either the user decides to end it using a stop button, or specify a time at which the GUI stops running. 

 

The string values are sent and the decimal values are extracted/parsed using regex and plotted into a chart - I chose a chart as we would be running the fuel cell for hours on end and we would need all the data within this time.

 

There are other functions in the full program I attached in an earlier comment, such as the upload to excel button where it takes the history from the chart and put into excel (courtesy of another labview user whose code I just took), as well as to put the pictures of the charts in a file specified by the user (hard-coded). If need be, I can take a screen recording of the full GUI and list some issues that I am facing at the moment. Thank you for taking the time to read this.

 

 

0 Kudos
Message 13 of 38
(701 Views)

@altenbach wrote:

I agree that this code makes absolutely no sense. I would recommend to start with a few basic tutorials about dataflow.

 

In additions to what has been said:

  • There is no obvious way to stop the while loop.
  • Your event structure can only run once and the loop will start running first. If you would ever press the "connect" button a second time, the VI will lock up forever, because the event is set to lock the panel until it can complete, but it can never complete. after the second press.
  • Prepending a new string to an ever-growing existing string will eventually cause you to run out of memory. Are you fully aware how feedback nodes work?
  • The FOR loop pyramid makes no sense.
  • Why would you form a 2D array, throw everything away except the first row, the build that back into a 2D array???
  • What's the point of the get function that produces no output?
  • Why is port number orange?
  • Are you sure you are using the right TCP mode?

 

To help you, we need very little information:

  • How does the received string look like? (how much data per iteration of the while loop (one? three? more?)
  • Your 2D array container has three rows and and many columns. Do you want three columns?

As a first step, create a hardware free simulation where you generate typical data in a slow while loop and then build up the 2D array the way you want. Once that is worked out, add your PLC communication in a proper state machine with at least four states (idle, connect, disconnect, read, etc.)



I replied to this once already with all my explanations/questions, but my entire reply is gone? 

0 Kudos
Message 14 of 38
(762 Views)

@altenbach wrote:

I agree that this code makes absolutely no sense. I would recommend to start with a few basic tutorials about dataflow.

 

In additions to what has been said:

  • There is no obvious way to stop the while loop.

In my full code, the user can choose to stop it whenever, including a timer they can set 🙂 dataflow is confusing to me, if you have any good recommendations, I would love to see it! I watched a few tutorials on Youtube before starting this project but it must have not been enough, unfortunately.

 

Your event structure can only run once and the loop will start running first. If you would ever press the "connect" button a second time, the VI will lock up forever, because the event is set to lock the panel until it can complete, but it can never complete. after the second press.


I did notice this issue as well, but I do not know what to do - this button should be pressed so that the TCP listen can receive the signal from the PLC in the first place. What is the alternative/good practice?


  • Prepending a new string to an ever-growing existing string will eventually cause you to run out of memory. Are you fully aware how feedback nodes work?

No, I will have to admit I do not fully know how they work. I tried running the program when I removed the feedback node and concatenate string function but the values keep jumping back to 0: 

eenjeruu_0-1669702918213.png


  • The FOR loop pyramid makes no sense.
  • Why would you form a 2D array, throw everything away except the first row, the build that back into a 2D array???
  • What's the point of the get function that produces no output?
  • Why is port number orange?
  • Are you sure you are using the right TCP mode?

 


I apologise for the pyramid, I took it from a very basic dataflow video on forming 2d arrays and replaced the Random Number block with my regex. 

The 2D array was for me to be able to take these saved values and put it into an excel file in the full GUI. I used a History property node earlier

but due to the multiple stale values, there were a lot of repeats per reading taken into the chart so I tried working around it. 

The GET function allows my button to work but I am probably doing it wrong (GUI can't receive any signals without the GET function that is in the while loop)

 

I am not clear about the TCP mode, but I assumed it was working fine as I could collect signals etc but I might be gravely wrong!

 

The expected output etc I believe I responded in another reply, let me know if that makes sense. I will try to work on a state machine, in the meantime. Thank you very much for reading!

0 Kudos
Message 15 of 38
(757 Views)

Please use zip for attachments. Nobody should be forced to install extra software (of sometimes questionable origin) just to open your rar file.

0 Kudos
Message 16 of 38
(726 Views)

I think my earlier code would work perfectly well once you sort out your TCP connection. Is there anything special about the received message? (Size? termination character?) For example "immediate mode" is certainly not typical. (see also)

 

Do you have the manual for the device? can you attach the pdf?

0 Kudos
Message 17 of 38
(723 Views)

You have that "HTTP get commend" in your original code (with no outputs wired!). What output does it provide? (remove all the other TCP stuff).

 

Can you create indictors for all its outputs, run in in your setup, and shows us what the output is?

0 Kudos
Message 18 of 38
(713 Views)

@altenbach wrote:

Please use zip for attachments. Nobody should be force to install extra software (of sometimes questionable origin) just to open your rar file.


My apologies, I thought it was the same for rar files! 

0 Kudos
Message 19 of 38
(711 Views)

Windows only supports zip natively, nothing else (rar, 7z, etc.).

 

(Don't forget to save the project for previous before attaching. your rar was again in 2022)

0 Kudos
Message 20 of 38
(705 Views)