https://github.com/engineerjoe440/py-ladder-diagram
Ladder Logic Diagrams written in Python
https://github.com/engineerjoe440/py-ladder-diagram
Last synced: 3 months ago
JSON representation
Ladder Logic Diagrams written in Python
- Host: GitHub
- URL: https://github.com/engineerjoe440/py-ladder-diagram
- Owner: engineerjoe440
- License: mit
- Created: 2024-05-10T17:33:20.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-05-13T22:29:47.000Z (about 2 years ago)
- Last Synced: 2025-03-07T01:01:50.402Z (over 1 year ago)
- Language: Python
- Size: 21.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Py-Ladder-Diagram
Ladder Logic Diagrams written in Python.
## Installation
Install with `pip`:
```shell
pip install py-ladder-diagram
```
## Usage
A simple, two-rung system can be modeled with the following code:
```python
from pyld import Ladder, Rung
from pyld.elements import Coil, Contact, NegatedContact
Ladder(
Rung(
Contact("In1"),
Contact("In2"),
Coil("Out1"),
),
Rung(
Contact("In1"),
NegatedContact("In2"),
Coil("Out2"),
)
)
# Renders:
# █
# █ In1 In2 Out1
# █─────┤ ├────┤ ├────( )
# █
# █ In1 In2 Out2
# █─────┤ ├────┤/├────( )
# █
```
The addition of a branch is relatively easy, and can render a few ways:
```python
from pyld import Ladder, Rung, Branch
from pyld.elements import Coil, Contact, NegatedContact
Ladder(
Rung(
Branch(
Rung(
Contact("In1"),
Contact("In2"),
),
Rung(
Contact("In1"),
NegatedContact("In2"),
)
),
Coil("Out3"),
)
)
# Renders:
# █
# █ In1 In2 Out3
# █─────┬───┤ ├────┤ ├──┬────( )
# █ │ │
# █ │ In1 In2 │
# █ └───┤ ├────┤/├──┘
# █
# █
Ladder(
Branch(
Rung(
Contact("In1"),
Contact("In2"),
Coil("Out1"),
),
Rung(
Contact("In1"),
NegatedContact("In2"),
Coil("Out2"),
)
)
)
# Renders:
# █
# █ In1 In2 Out1
# █───┬───┤ ├────┤ ├────( )
# █ │
# █ │ In1 In2 Out2
# █ └───┤ ├────┤/├────( )
# █
# █
```
### YAML Format (Future Work)
At some point in the future, functionality will be built in to model ladder
diagrams from YAML.
```yaml
Rung:
- Contact: In1
- Contact: In2
- Coil: Out1
Rung:
- Branch:
- Rung:
- Contact: In1
- Contact: In2
- Rung:
- Contact: In1
- NegatedContact: In2
- Coil: Out3
```