09-03-2014 12:05 PM
Hi all,
I have some experience with MySQL database before, but I never worked with LabVIEW before.
I wanted is to create MySQL database recieving from OPC which connected to LabVIEW. This data is from current transducer which connected to solar panel, so the value will change depending on light intensity.
Right now i am able to insert data into MySQL database but the problem is.... it will insert the data every second, which is too much 😞
What i want is to insert data to table in database only when labview detects that the value has changed.
This is my current VI
Can somebody please help me?
Thank you in advance
Best regards,
faLabor
09-03-2014 12:21 PM - edited 09-03-2014 12:28 PM
First, you should move the open/close db connections outside the loop.
Second, keep the Panel_current in a shift register and compare the difference between successive readings and only write to the database when the difference exceeds a threshold.
09-03-2014 12:22 PM
Use shift registers to compare present and past values. http://k12lab-support-pages.s3.amazonaws.com/lvbasichome10.html
Only write to the database when the values are different.
09-04-2014 04:06 AM
Hi jcarmody,
I have done what you suggest but the problem still the same... LabVIEW still record data to the database every second.
is there something i missed?
for example in condition loop also have true and false condition, the setting is the same or not?
Best regards,
faLabor
09-04-2014 04:19 AM
The setting is NOT the same. The point of the "condition loop" (proper name is case structure) is to execute different bits of code according to the condition. So in your problem:
The TRUE case is executed if the code detects a value change in your input, it writes the value to the database.
The FALSE case is executed if the code could not detect a value change; nothing should be written to the database (just connect the terminals at either end of the case structure correctly, without a database write subVI).
09-04-2014 04:39 AM
I changed the false condition by connected open database directly to close database.
and it still records the data every second...
09-04-2014 04:42 AM - edited 09-04-2014 04:43 AM
Which leads to the conclusion that your condition is met at every iteration. What values are you measuring, and what is your threshold for change detection?
Also, you have wired your shift register wrongly. The new x value needs to wired to the shift register terminal on the right side of the loop!
09-04-2014 04:58 AM
Turn out I wired the x value wrong as you said.
Everything works perfectly fine now... Thank you so much for your help
best regards,
faLabor
09-04-2014 11:05 PM
I would be very reticent in using the root account to write to my db unless it was just a local development machine. This account should be pretty tied down on the mysql side. Create an account with limited access for your Labview VI. The best practice would be to use a parametrized stored procedure. Just my 2¢ and experience having public facing web apps with mysql backing.
09-05-2014 12:06 AM
If you already have an OPC connection, is there some reason you're not using the logging built into dsc to do this? (http://zone.ni.com/reference/en-XX/help/371618H-01/lvdsc/dsc_settings_db/#relationaldb). If I am not terribly mistaken, DSC handles the value changes/deadbanding what you probably want. Thats basically what the code the others have written does, but its built in. On the other hand, if you just have a few vars it probably isn't worth it. I'd mostly just recommend you look into it 🙂