Sign in to follow this  
Followers 0
bagged2drag

Function Blocks and Data logging to CSV

4 posts in this topic

2 subjects here.  

First, I am pretty new to function blocks.  I somewhat get that you can create a function block and use it in multiple places to control similar functions.  I am working on a program that someone else created.  It uses a function block to control a variety of servos.  What I don't quite understand is how it is determined what outputs to use.   The system uses profinet.   I watched a couple videos, but they really didn't explain anything....they just showed how to make a simple function block with no dialogue. 

 

More importantly. and unrelated, I need to somehow export some data (scrap and production counts) to a CSV or via ftp to a computer.    I am using TIA Portal V13 with WinCC Comfort.    I've done similar functions in the past using Automation Direct and Proface HMI's, and they were much more intuitive than the Siemens. 

 

Thanks,

Share this post


Link to post
Share on other sites

I really hope I don't mess this up, but this is my understanding of FB's. I have not used TIA Portal specifically, but as I understand it, it is just a suite containing the various Siemens' software (Simatic Step 7 Manager, STARTER, etc.)

After you have created an FB in Simatic Manager via Insert Object -> Function Block, you can open the newly created FB and begin coding in it. Once inside the new FB, there is a Declaration Table at the top of the page with In, Out, In/Out, Temp, Stat variable trees. This is where you label and define the generic variables to be used inside the FB for processing.

At my site, we have a generic double-solenoid valve FB called many different places. For example, you have a valve with two solenoids each powered from an output from a Siemens' module. You could define an "Out" for "Sol_A" of type "Boolean" in this new FB's Declaration Table. Now, if you save this block, and then make a block call in another FC/FB/OB for this FB, it will display the FB and FB number as a box, with a variable on the outgoing side of the box labeled "Sol_A". You would then assign the address (Absolute or Indirect) for the specific output you want turned on to energize this solenoid next to this "Out" parameter.

The process is repeated for all other generic variables inside your FB. Determine the nature of this signal: is it only brought into the FB (In); is it only an output of the FB (Out); is a signal both brought into the FB, processed, and sent out (In/Out); a Temp acted on only during each scan cycle and then "forgotten"; or a "Stat" which is a Static variable retained after the execution of the block and saved in the associated Instance DB of the FB. Then, define a name and the type of data related to this variable: Boolean, S5Time, INT, REAL, etc.

When this block is called in another FC/FB/OB, you will then assign all the actual addresses you want manipulated in the respective slots that are populated on the incoming and outgoing sides of the FB.

The water gets murkier for me when you get into Multi-Instance DB's, combining Instance DB's into a calling FB's Instance DB, but I would really recommend reading the Siemens' manuals for "Simatic Programming with STEP 7" and the programming manuals for whatever processor you are using.

As for the .CSV question, I cannot help you there in Step 7. If you are using WonderWare, I know there is a way to export tag data to a .CSV at different intervals for data logging, though I have never personally used it.

Adam

 

1 person likes this

Share this post


Link to post
Share on other sites
On 9/4/2017 at 11:17 PM, CoveredInColor said:

The water gets murkier for me when you get into Multi-Instance DB's, combining Instance DB's into a calling FB's Instance DB, but I would really recommend reading the Siemens' manuals for "Simatic Programming with STEP 7" and the programming manuals for whatever processor you are using.

Basically, when you finish an FB, the declaration area at the top becomes the structure of a data block.  When you call the FB, you assign a DB to it.  If you're calling it from within another FB, you can create a variable in the declaration area of the calling FB that's the same type as the called FB, essentially embedding the DB inside another DB.  This is essential if you're going to be calling the FB more than a couple of times.  If you call it from FCs or if you don't want to muck with the declaration area of an FB in a working machine (which I TOTALLY understand), you'll need a separate DB for each call of the FB.

 

Example.  Let's say you create FB100 to do something.  In most of our machines, FBs are only used once so what they would do is create DB100 as an instance DB of FB100 and use them together.  It's definitely not necessary to match the FB and DB numbers, it's just a convention that the particular OEMs who built our machines use.  It gets more complicated with multiple calls to the same FB.  Let's say you want to call FB100 5 times from within FCs (or from other FBs without modifying their DBs).  You would create 5 DBs, each an instance DB of FB100.  You can number them anything you want, let's say DB75, DB109, DB115, DB209, and DB1056 (totally random numbers....).  Each time you called FB100, you would use a different instance DB.

If you call FB100 from only within other FBs, you can create variables in the declaration areas of the calling FBs.  You would assign the variable's Data Type to match the symbolic name of the FB you want to call.

Here's a screenshot showing an example in Simatic Manager.  Portal will look different, but the principle should be the same (we just ordered a license to upgrade Simatic Manager to Portal but it hasn't arrived yet so I can't see what the differences are yet):

EmbeddedInstanceDB.thumb.png.772cf20ba4a

The window in the back is the blocks folder of Simatic Manager with FB11 selected.  Note that its Symbolic name is "PosStatus". The window on top is the block editor with FB10 opened and its interface (declaration area) opened to the STAT area.  The programmer has declared a number variables of Data Type "PosStatus".  In the ladder window (Network 12), you can see a function call to FB11 that's using one of the embedded data structures. If you right-click on the call instruction and open the called block, it takes you to FB11, even thought that's not at all clear from looking at the call instruction.

 

Edited by Joe E.
Typos and clarification
1 person likes this

Share this post


Link to post
Share on other sites
On 19-7-2017 at 6:18 AM, bagged2drag said:

More importantly. and unrelated, I need to somehow export some data (scrap and production counts) to a CSV or via ftp to a computer.    I am using TIA Portal V13 with WinCC Comfort.    I've done similar functions in the past using Automation Direct and Proface HMI's, and they were much more intuitive than the Siemens. 

The machines I'm working on use VBscript in the HMI. The csv is stored on the USB or SD card.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0