1

I've been looking around but cant seen to find what data structure I can implement to represent a ladder diagram from a PLC program PLC in python.

For those not familiar with ladder diagrams. It is basically a multilevel linked list where nodes in a level can both be connected back to a higher level in the next column and be connected to a node in the same level further down.

I've attached a picture.

I have tried using multilevel linked list where I save previous nodes as left_neighbours and next nodes and right_neighbours.

I am unsure if this is the best approach and also im unsure how I traverse this list to get all nodes without duplicates.

Prerequisites:

  • Identical nodes can be present in different places in the diagram
    • To check equality you have to check if neighbours are the same?
  • Multiple inputs
  • Nodes can have multiple neighbours both left and right
  • Branches can merge back together

Constraints:

  • Just one output
    • Making it possbible starting traverse from output node backwards?

The code I have is not possible to understand without context since I have a huge method trimming the custom syntax from the program where I extract text based logic from ladder logic. Also im unsure if its suitable posting it online since its IP not owned by me even though developed by me.

My question is very general and regarding a suitible data structure.

Below is an example picture of ladder logic

Example from google

  • *"I've attached a picture."*: where? *"I am unsure if this is the best approach and also im unsure how I traverse this list to get all nodes without duplicates."*: please share your code and focus your question on the problem you encountered in making it work as intended. – trincot Apr 12 '23 at 08:17
  • 1
    How you represent it really depends on what you want to use the representation for. For most purposes, though, I would use a list of (output_name, expression_tree) – Matt Timmermans Apr 12 '23 at 17:46
  • Ladder logic, if only simple binary functions are used, can be represented by Boolean algebra, based on logic gates (AND, OR, NOT... ), it would be possible to model a class to store a network (branch) as a formula (the output is the result of the expression: A OR B AND NOT C = OUTPUT)... As @Matt said, it depends a lot on your purpose, this could be an idea. – dwpessoa Jun 21 '23 at 11:34

0 Answers0