LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

saving the latest value in Shift Register

Solved!
Go to solution

Hi,

How can I save the current value in Shift Register automaticly even if the application will be canceled.

The number is incrementing by 1 with every iteration and it has to continue also after canceling the program and starting it again. (f.e. for the firs time  i want to save number 3, after cancel and running the program again it will continue with number 4,5...)

Thank you for your help

 

0 Kudos
Message 1 of 17
(5,189 Views)

Hi Alex,

 

How can I save the current value in Shift Register automaticly even if the application will be canceled.

The value will be saved in the shift register as long as the VI stays in memory. You can "cancel" the app as often as you want - as long as the VI stays in memory…

When the VI will get removed from memory you need to store the value in a file and load it when starting your app again - as any other app has to do too!

 

On your image: BMP files are banned from the forum for a good reason: their size! And it doesn't get converted to JPG by just renaming the file suffix! Use a tool to convert such images to REAL JPG or PNG formats! (Conversion to PNG reduces filesize from 271kB to 3kB!)

 

 

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 17
(5,184 Views)

@GerdW wrote:

Hi Alex,

 

How can I save the current value in Shift Register automaticly even if the application will be canceled.

The value will be saved in the shift register as long as the VI stays in memory. You can "cancel" the app as often as you want - as long as the VI stays in memory…

[...]


Just for clarification purpose: Gerd's sentence refers to UNinitialized shift registers.

To be more exact: Gerd's sentence holds true for any shift register. However, before starting the loop interations, an initialized shift register will get a well-defined value whereas the UNinitialized shift register proceeds with the value written to it in the last execution.

 

In the hope to prevent confusions,

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 3 of 17
(5,173 Views)

I thought that using Shift register will save the latest value always if there is no inicialization as you mention in the first sentence but dont.

After cancelling the app it always start from 0 again.

Is then the storing and loading the value from the file the only option?

Its a banal code but i cant solve this small problem

0 Kudos
Message 4 of 17
(5,167 Views)
Solution
Accepted by topic author Aleeex07

Hi Alex,

 

Is then the storing and loading the value from the file the only option?

When you want to store data for the next run of your executable you need to use some storage that will last: files are the perfect items to do so…

(You could use the Windows registry too, if this is easier for you.)

 

Its a banal code but i cant solve this small problem

Define a file path, read the file content, increment a counter, store the new value in the same file:

check.png

 

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 5 of 17
(5,149 Views)

@Aleeex07 wrote:

[...]

After cancelling the app it always start from 0 again.

[...]

What does that sentence mean? You have a single VI with close to no code. I wouldn't call that VI an "app". So what is your "app" and what is "cancelling"?

 

Norbert

 

PS: Loading the VI  in LV, running it (ctrl+r) and repeating to run the VI (again ctrl+r) increases the value as expected. You must NOT close the VI between runs.

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 6 of 17
(5,147 Views)

For specification this is just a small part of code. The purpose of this is to save this number to the database as an ID because i´d like to insert a new row with this ID(myincrementingnumber) as a primary key to an existing table and at the same time create a new table with the same ID (the same number). 

So each time a press a button (save to DB) some data with the incrementing ID number will be saved in a table and also one new table (table1 will be created)

When I push a button for the second time that will insert data to a second row (ID 2) and create a new table (table2).

Cancelling I mean close the whole application and after the next opening and running the vi it has to continue (ID3...table3)..

0 Kudos
Message 7 of 17
(5,132 Views)

If this is a primary key in a database... why don't you use a database auto-incremented value and read that out for usage in the relating table?

 

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 8 of 17
(5,122 Views)

I´ve tried to set the auto-increment in DB, but when i access and insert rows to DB from labview, the ID numbers arent incrementing. The ID numbers are random, so I try to solve this problem only through Labview.

0 Kudos
Message 9 of 17
(5,115 Views)

Auto-increment is a feature of the database. If the database provides that feature, it is a configuration setting of the table.

It seems that your primary key of the table is "Random ID or passed by parameter when writing a new record".

If you stick to that configuration (or the database does not support auto-incrementation), you have to create the counter with LV.

There are two professional options:

a) Read out the number of records of the primary table and use this as counter

b) Keep the counter 'backed up' in an external file just like Gerd proposed

 

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 10 of 17
(5,107 Views)