LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Writing to database

Solved!
Go to solution

Hey guys,

 

I am looking to write data to a database after each test step. I want to send a boolean Pass/Fail and a string name of test. I can read data and use parameters for my test step but i am having difficulty sending results to a different DB. I have followed the tutorial from  http://www.ni.com/pdf/manuals/371525a.pdf for writing data to database at at fig 5.2. I have no run test block in the vi below but i want to add a boolean and a string to the bundle by name but I get errors can anyne have a quick look and help me out. I want to test that my database reads  string value and a boolean before i add my run test block.

 

Thanks.

 

Damien

0 Kudos
Message 1 of 21
(5,155 Views)

Damien,

 

It's not clear how you're organizing your database table.  Are you planning on having one row per test that contains results for all the test steps or a separate row for each test step that contains only the results for that step?

 

If you're planning on having one row per test with a column for each test step (as implied by the column names in your VI), then inserting data after each step is going to be more complex.  You'll have to insert the row after the first step, then keep a reference to it and update it for the subsequent steps.

 

Inserting a new row for each step is easier when you're running the test, but it makes retrieving the results from the database more difficult.

 

Sorry if this is kind of vague, but if you can provide more details on your table layout I can get more specific.

 

 

0 Kudos
Message 2 of 21
(5,143 Views)

You have several errors in the VI.

  1. Auto indexed outputs for the DB refnum and error out
  2. improper cluster type (numeric and boolean instead of string and boolean)
  3. Cluster with no labels used as the definition for the "bundle by name" (you can leave them without labels for "bundle" but not "bundle by name")
  4. More elements in bundle by name than elements in the defining cluster

I attempted to fix this VI for you but I'm not sure I understand your requirements. The VI that I attached will write a string ("some string") to column Step1 and a boolean to column Step2 of table StepResults (whatever table name you put in the string control StepResults) and will do this the number of time specified by Numeric which is wired to the N terminal of the for loop. Note if N = 0 as it does by default in the code that you sent me, then nothing will be written to the data base.

 

All that said, your last sentence stated that you wished to read from the database. The attached VI is attempting to write to the database, not read from it. Please post back if you need help reading from the database.

Charles Chickering
Architecture is art with rules.

...and the rules are more like guidelines
Message 3 of 21
(5,142 Views)

Thanks for the reply guys, really appreciate it.

 

Sorry if i havent made my question clear. For instance I have 10 test steps after each test step i get a pass/fail. I would like to write back to the database after the 10 test steps saying PPPPPFFFFF in one row. Above each P or F will be the test step name for that colunm. It was suggested to me i might need a paste append function.

 

 

I have the read from database working fine and can extract the info i need no problem. My test block where i receive PPPPPFFFFF is a vision block i hevent completed just yet. Can ye give me suggestions or alter my code so i can achieve what i set out to do.  Thanks so much.

 

Damien

0 Kudos
Message 4 of 21
(5,132 Views)

I believe you want a database table that has 10 columns, named Step0 through Step9 (or whatever is appropriate). The data type for all columns is boolean. With these assumptions in mind you have two options:

  1. Buffer all ten results in LabVIEW until all tests are complete. Write all data in at the same time using a method similar to what I attached above (remove the string, write 10 booleans instead).
    1. This has the advantage of being simpler and faster
    2. This has the disadvantage of the test results not being written to the DB until they are all complete
  2. Write the first result to the DB using the method above, then for all remaining tests, you must use an update method. This requires that you have a way of uniquely identifying each row in order to tell the DB which row to update
    1. This has the advantage of writing all data as it is collected, in the event of a system crash on the 10th test, all previous results are saved
    2. This has the disadvantage of being complicated (uniqueness) and slow (10 DB writes/updates vs 1)

If you need further help from here please let me know which route you wish to go and if possible please send me the table schema.

Charles Chickering
Architecture is art with rules.

...and the rules are more like guidelines
Message 5 of 21
(5,127 Views)

The first option is precisely what i require as my test steps should only last 30 seconds in total. A couple of questions regarding your suggestions my experience is rather limited so;

 

1. Each input into the bundle by name function is from each test step?

2. To buffer the results just pass them straight through each state or how would i achieve this?

 

I have attached the vi perhaps slight alterations would point me in the right direction.

 

Thanks very much very helpful.

 

damien

 

 

 

 

0 Kudos
Message 6 of 21
(5,123 Views)

Check out this modification of your VI and let me know if you have questions. One non-obvious thing to point out, I am using the function "Array to Cluster", to make this work for your application, you MUST right click on that function and select "Cluster Size". I have already set this to 10 but if that number changes then let me know.

Charles Chickering
Architecture is art with rules.

...and the rules are more like guidelines
Message 7 of 21
(5,113 Views)

Hi Charles,

 

Thats great Charles thank you very much for your assistance, just a couple of questions then on this vi? Apologies if i am going off point here now but i am still learning labview.

 

 

My test block is in a state machine structure so after the 10 test steps my next state will be this writing to database.vi. Where in this vi do my results from the previous test steps link in. Is it the array to cluster and leave out the for loop. Or how would i get the results from the previous states into this vi? I can attach my overall vi if u like.

 

Thanks

 

Damien

0 Kudos
Message 8 of 21
(5,090 Views)

Also when i run my vi it says the table name given is blank? The name of my database table is called StepResults first colunm is TestStep1 etc. Is there a solution to this?

 

Damien

0 Kudos
Message 9 of 21
(5,087 Views)

I just changed the input to a constant with my table name re-run the code and an error occured.

 

Possible reason(s):
ADO Error: 0x80040E37
Exception occured in Microsoft JET Database Engine: Could not find output table 'TestResults'. in NI_Database_API.lvlib:Rec Create - Command.vi->NI_Database_API.lvlib:Cmd Execute.vi->NI_Database_API.lvlib:DB Tools Insert Data.vi->DatabaseWrite.vi

0 Kudos
Message 10 of 21
(5,082 Views)