Jump to content

Function Blocks won't run correctly outside of !Main Routine

Recommended Posts



Do certain function blocks only work correctly in the !Main Routine? Even if they are in a subroutine that is called every cycle?



Hardware: V570-57-T10 with multiple I/O Expansions 

Hardware OS: 3.9 (06)

Software: 9.7.44 Build 0


Had an unusual issue popping up while attempting to write a delimited line to Excel CSV, also ran into the same problem with the Num to ASCII function block.



Any time I use the Create Delimited Line function block using the System Date/Time SI's to create a custom string and three ML, then attempted to write out the results to the SD card, the date-time string would process fine but all the ML data would populate to Zero regardless of the value stored in the ML.


Each line in the CSV would look like this:


Example Bad Output:






Next I attempted to use Num to ASCII to create a string.  The value stored in the target MI for the string always remained zero and attempting to reference the target MI for Create Delimited Line resulted in the same CSV output above.



Out of curiosity I moved the Num to ASCII to !Main Routine and for no apparent reason the target MI now populated with a results as intended.  In fact, the output is now correct but only when I run the FB's in !Main, anywhere else and I get bad output.


Example Good Output:






Additional thoughts


-The routine that I'm placing the Function block isn't being called.  
Not an issue.  I tested this in Subroutines that I know are being called, and regardless of which subroutine I put them in, they fail to function while all other logic in the subroutine performs as intended.  The blocks only function in !Main Routine.


Link to comment
Share on other sites

  • 2 weeks later...



It is recommended that the CONFIG FB's (from FB's menu) will be placed inthe main routine but it can also be placed in a routine that is called every scan.

I don't think the issues that you are facing with NUM to ASCII and write delimited line should not be related to the fact tehy are not placed in the main routine.

The problem might be related to the order of the logic.

In case you are still facing this issue you can send the applicaiton to support@unitronics.com and we will check it.

Link to comment
Share on other sites

I know certain config blocks state they need to be called every scan, and I have some of those in other programs running both in, and outside of, the main ladder.


The order doesn't seem to matter with the NUM to ASCII block though.   It only misbehaves when I put it within a subroutine regardless of the subroutine being called every scan.


Operand A, start address of the vector, which is not dependent on any logic, shows 0 when I attempt to run NUM to ASCII from outside of the Main!.  As soon as I put it in Main! operand A takes on a value.



If you'd like I can get some screen shots of the behavior.

Link to comment
Share on other sites



I woluld check all the instances of this MI (which is Operand A as you mentioned) in the program using the find tool.

If you dont find it ..  check if there are MIs before this address that somehow overwrite this MI.

For example if the address of this MI is 104 and in other place of the program you are perfroming for example RTC to ASCII and the result goes to MI100 , it can overwrite MI104.


In case you dont find the reason - send the applicaiton to support@unitronics.com and we will check it.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...