LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Connection between MySQL and LabVIEW

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

MySQL connection

 

Can somebody please help me?

Thank you in advance

Best regards,

faLabor

 

0 Kudos
Message 1 of 10
(4,306 Views)

 

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.

 

Example_VI.png

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

0 Kudos
Message 2 of 10
(4,298 Views)

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.

0 Kudos
Message 3 of 10
(4,296 Views)

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

 

 

0 Kudos
Message 4 of 10
(4,247 Views)

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).

Best regards,

Jarle Ekanger, MSc, PhD, CLD
Flow Design Bureau AS

- "The resistance of wires in LabVIEW is not dependent on their length."
0 Kudos
Message 5 of 10
(4,241 Views)

I changed the false condition by connected open database directly to close database.

and it still records the data every second...

 

Unbenannt.png

0 Kudos
Message 6 of 10
(4,235 Views)

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!

Best regards,

Jarle Ekanger, MSc, PhD, CLD
Flow Design Bureau AS

- "The resistance of wires in LabVIEW is not dependent on their length."
0 Kudos
Message 7 of 10
(4,231 Views)

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

0 Kudos
Message 8 of 10
(4,222 Views)

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.

0 Kudos
Message 9 of 10
(4,194 Views)

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 🙂

0 Kudos
Message 10 of 10
(4,184 Views)