1

Is there a know way to convert an existing structured text PLC code to a function block diagram? (Or even CFC with Beckhoff)
I know this is difficult because of the different flows the languages are based on.
Maybe only partialy or atleast some structure with the right variables connected to the function blocks?
I have to create a logic code overview in Visio, based on the look of FBD, and it would be a great help to have atleast some structure to base my drawings on and not have to draw everything from base ST code.

A small example code woudl be this 'BrakeControl' FB done in ST, but there are much larger FBs I need to map:

IF stSettings.bExists THEN
      IF stSettings.eMode = E_OPMode.eOPModeOpen OR stSettings.eMode = E_OPMode.eOPModeClose THEN
        // close brake manual - only possible if below max braking rpm and hydraulic closed
        bCloseBrake := stSettings.eMode = E_OPMode.eOPModeClose AND stIO.stGenerator.IstGen_Speed.fPercent < stSettings.fStartRev AND itfHydCtrl.IsClosed;
    ELSE
        IF stIOs.IbBrake_Auto AND stIOs.IbBrake_Worn AND  
           (itfTurbCtrl.State = E_TurbState.eTurbStateFault OR 
            itfTurbCtrl.State = E_TurbState.eTurbStateStop OR
            itfTurbCtrl.State = E_TurbState.eTurbStateReady )           
        THEN
            IF stIO.stGenerator.IstGen_Speed.fPercent < stSettings.fStartRev AND itfHydCtrl.IsClosed THEN
                bCloseBrake := TRUE;
            END_IF  
        END_IF

        IF stIOs.IbBrake_Auto AND NOT stIOs.IbBrake_Worn AND itfTurbCtrl.ManualMode THEN    
            IF stIO.stGenerator.IstGen_Speed.fPercent < stSettings.fStartRev AND  stIO.stPenstock.IbBypass_Closed 
                AND stIO.stPenstock.IbMIV_Closed AND itfHydCtrl.IsClosed THEN
                bCloseBrake := TRUE;
            END_IF  
        END_IF

    END_IF

    IF bBrakeRelease THEN
        bCloseBrake := FALSE;
    END_IF  
    stIOs.QbBrake_On := bCloseBrake;
Markus Wurm
  • 53
  • 1
  • 11
  • 1
    Why? Because you understand CFC better? This beautiful and very clear part of code will look really ugly in CFC, – Sergey Romanov Jan 23 '19 at 05:18
  • Unfortunately it is required by one of our customers ... If I can not find any software to atleast partially convert the code, I have to draw it all manually right from the ST code, like in this example: https://i.stack.imgur.com/MHUee.png At the moment I am experimenting with Visio and bound data out of an Excel sheet, to at least be able to somewhat manage the IO and variable names a litte bit better – Markus Wurm Jan 23 '19 at 10:05
  • Basicly this question is pretty much linked to another question over on **"Software Recommendations"**: [link](https://softwarerecs.stackexchange.com/questions/54783/software-for-drawing-function-diagrams-of-plc-st-code) – Markus Wurm Jan 23 '19 at 10:29
  • I agree with Mark Lazz, you do not need to draw every block logic. Just add this block on the diagram and not diagram of how block works. – Sergey Romanov Jan 23 '19 at 13:06

1 Answers1

0

No, this is not directly possible. There is conversion between Ladder and FBD, and if you port the code to Codesys you can add IL to that list. Unfortunately, ST cannot be automatically ported in any way.

Where I have had client requirements before, I've put the code into a separate library, then use the FB as a block in FBD / CFC. This might seem a bit "unfair", but the point of well written software is to create abstractions at increasingly high levels. You could argue that this low level Brake control block is at an appropriate level of abstraction to not require further detail - you wouldn't pull apart the "TON" block for your customer. I realise this may not work for some of your larger FBs, but perhaps you could do some refactoring of those into smaller FBs and then use the approach above?

If pushed - I ported the code and reran my tests on the new language. I'm not sure I'd be comfortable doing a "paperwork port" and guaranteeing the same functionality for something non-trivial. CFC blocks have a specified call order which can cause race conditions if you're not careful, and FBD is approached backwards (or, that's the way I think of it, anyway!).

Best of luck with it.

Mark Lazarides
  • 366
  • 2
  • 13
  • I just came across your answer by accident as I was looking at the PLC tag. You say "reran my tests on the new language". Can you elaborate on that (especially the tests)? I am continually looking for how to apply general software principles to PLC code and a testing framework is something that is sorely missing. – Peter M Jan 29 '19 at 16:51
  • Hi Peter. I have my own library with a test base class exposing a stopwatch, timer, some start/stop flags, msg logging (to windows system log) and asserts. I try to write most of my code with interfaces to make mocking easier, therefore with the above, I can have test projects that run all the objects through their paces. A lot of it would be classified as "integration tests" as they are often asynchronous (multi scan). I've got some good blogs (of other people) I can point you at, and my library is freely available on Bitbucket if you're interested. – Mark Lazarides Jan 30 '19 at 20:23
  • Thanks for the offer Mark. I mainly work on Ladder on GE so I doubt your libraries would be useful other for curiosities sake, however I am interested in seeing what related blogs exist. I stumbled onto [Stefan Henneken](https://stefanhenneken.wordpress.com) today which was an eye opener for me. So I'd love to see more! – Peter M Jan 30 '19 at 22:13