String to Event Switch

17 views
Skip to first unread message

Anro le Roux

unread,
Oct 16, 2011, 6:28:02 PM10/16/11
to FBDK
Hi,

Im trying to create a FB to fire specific events, depending on a
string in the DESC input.

Can anyone help me to fix my FB below or suggest a better way.

Thank you!
Anro

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE FBType SYSTEM "http://www.holobloc.com/xml/
LibraryElement.dtd" >
<FBType Name="Switch" Comment="Basic Function Block Type" >
<Identification Standard="61499-2" />
<VersionInfo Organization="Holobloc Inc" Version="0.3" Author="JHC"
Date="2009-09-15" Remarks="Changed transition priorities." />
<VersionInfo Organization="Rockwell Automation" Version="0.2"
Author="JHC" Date="2003-12-04" Remarks="Renamed for better indexing." /
>
<VersionInfo Organization="Rockwell Automation" Version="0.1"
Author="JHC" Date="2002-11-05" Remarks="Corrected missing ST element
in Algorithm REQ." />
<VersionInfo Organization="Rockwell Automation" Version="0.0"
Author="JHC" Date="2000-05-30" />
<CompilerInfo header="package fb.rt.RMSL1;" >
</CompilerInfo>
<InterfaceList>
<EventInputs>
<Event Name="INIT" Comment="Initialization Request" >
<With Var="QI" />
</Event>
<Event Name="REQ" Comment="Normal Execution Request" >
<With Var="QI" />
<With Var="DESC" />
</Event>
</EventInputs>
<EventOutputs>
<Event Name="INITO" Comment="Initialization Confirm" >
<With Var="QO" />
</Event>
<Event Name="CNF" Comment="Execution Confirmation" >
<With Var="QO" />
</Event>
<Event Name="STAT" >
</Event>
<Event Name="POSN" >
</Event>
<Event Name="OUTP" >
</Event>
<Event Name="SENS" >
</Event>
</EventOutputs>
<InputVars>
<VarDeclaration Name="QI" Type="BOOL" Comment="Input event
qualifier" />
<VarDeclaration Name="DESC" Type="WSTRING" />
</InputVars>
<OutputVars>
<VarDeclaration Name="QO" Type="BOOL" Comment="Output event
qualifier" />
</OutputVars>
</InterfaceList>
<BasicFB>
<ECC >
<ECState Name="START" Comment="Initial State" x="588.2353"
y="682.3529" >
</ECState>
<ECState Name="INIT" Comment="Initialization" x="341.17645"
y="82.352936" >
<ECAction Algorithm="INIT" Output="INITO" />
</ECState>
<ECState Name="REQ" Comment="Normal execution" x="135.29411"
y="1417.647" >
<ECAction Algorithm="REQ" Output="CNF" />
</ECState>
<ECState Name="TrigSTAT" x="3241.1765" y="123.52941" >
<ECAction Output="STAT" />
</ECState>
<ECState Name="TrigPOS" x="3235.294" y="517.64703" >
<ECAction Algorithm="REQ" Output="POSN" />
</ECState>
<ECTransition Source="INIT" Destination="START" Condition="1"
x="223.5294" y="600.0" />
<ECTransition Source="START" Destination="TrigSTAT"
Condition="REQ [DESC = &#34;A&#34;]" x="1676.4706" y="123.52941" />
<ECTransition Source="START" Destination="TrigPOS"
Condition="REQ [DESC = &#34;B&#34;]" x="2017.647" y="517.64703" />
<ECTransition Source="START" Destination="REQ" Condition="REQ"
x="588.2353" y="1052.9412" />
<ECTransition Source="START" Destination="INIT" Condition="INIT"
x="588.2353" y="282.35294" />
<ECTransition Source="REQ" Destination="START" Condition="1"
x="229.41176" y="835.2941" />
<ECTransition Source="TrigSTAT" Destination="START"
Condition="1" x="1676.4706" y="252.94118" />
<ECTransition Source="TrigPOS" Destination="START" Condition="1"
x="1847.0588" y="635.2941" />
</ECC>
<Algorithm Name="INIT" Comment="Initialization algorithm" >
<ST />
</Algorithm>
<Algorithm Name="REQ" Comment="Normally executed algorithm" >
<ST />
</Algorithm>
</BasicFB>
</FBType>

James Christensen

unread,
Oct 16, 2011, 8:03:39 PM10/16/11
to fb...@googlegroups.com
Could you send the FB type file as an attachment, so that it can be
opened easily in the FBEditor? If you include it in the text of the
message, the receiving E-mail clients insert end-of-line characters at
arbitrary locations, which makes it unparsable.
--
Regards,
Jim Christensen

Anro le Roux

unread,
Oct 17, 2011, 1:10:14 PM10/17/11
to fb...@googlegroups.com
Ok, finally figured out how to attach a file.
Here it is Mr Christensen.

Thanks
Switch.fbt

James Christensen

unread,
Oct 17, 2011, 1:47:23 PM10/17/11
to fb...@googlegroups.com
You have found a bug in the ST-to-Java translator! It translates the
61131-3 operator "=" to the Java identity operator "==", which works
for numerical values but not for strings.

Attached is an FB type file that provides a general-purpose
WSTRING-selector version of the E_DEMUX FB type. This works around the
Java translator bug by having the algorithm directly written in Java,
and allows you to have your selector strings as inputs to the FB
rather than hidden inside the code - much better for reuse if you
decide to change the values of your selector strings later on.

As you can see from the generated Java code in this example, you can
write algorithms in Java without having an ECC if there is a
one-to-one correspondence between an input event name and the
algorithm name. In this case you have to fire the output events
yourself by invoking the serviceEvent(this) method on the appropriate
output.

I find that filling in the Properties section and commenting
everything as I go along often helps me to clarify what I am trying to
do.
--
Best regards,
Jim Christensen

E_DEMUX_W.fbt

Anro le Roux

unread,
Oct 18, 2011, 11:16:15 AM10/18/11
to FBDK
Thank you Mr Christensen,

the E_DEMUX_W.fbt works perfect for me. And thanks for the tip on
organizing my work. Will do.

Your help is much appreciated.
Anro

On Oct 17, 7:47 pm, James Christensen <james.h.christen...@gmail.com>
wrote:
> On Mon, Oct 17, 2011 at 1:10 PM, Anro le Roux <alerou...@gmail.com> wrote:
>
> > Ok, finally figured out how to attach a file.
> > Here it is Mr Christensen.
>
> > Thanks
>
>
>
>  E_DEMUX_W.fbt
> 2KViewDownload
Reply all
Reply to author
Forward
0 new messages