0.0
No release in over 3 years
Low commit activity in last 3 years
We aim to design abstraction ladder which is able to run on any PLC with same ladder source or binary and prepare full stack tools.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 13.0
~> 2.1

Runtime

~> 0.1, >= 0.1.1
~> 2.1
~> 1.9, >= 1.9.24
~> 3.0, >= 3.0.3
~> 2.0, >= 2.0.0
~> 1.3, >= 1.3.1
~> 0
 Project Readme

[Japanese description is here.]

LadderDrive

The ladder_drive is a simple abstract ladder for PLC (Programmable Logic Controller).

We aim to design the abstraction ladder which can run on any PLC with same ladder source or binary and prepare full stack tools.

Getting started

It's required the Ruby environment. To prepare the Ruby environment, please find websites.

Install LadderDrive at the command prompt.

$ gem install ladder_drive

https://gyazo.com/6f00d74612def41fb33d836275b74c24

Create a LadderDrive project

At the command prompt, create a new LadderDrive project.

$ ladder_drive create my_project
$ cd my_project

https://gyazo.com/c538f66129aa425e2b1da4f478a10f52

Created files have consisted like the tree below.

.
├── Rakefile
├── asm
│   └── main.esc
├── config
│   └── plc.yml
└── plc
    └── mitsubishi
        └── iq-r
            └── r08
                ├── LICENSE
                └── r08.gx3

Connection configuration

PLC configuration

There is a plc project under the plc directory. Launch one of the plc projects which you want to use. (Currently, we support the Emulator and MITSUBISHI iQ-R R08CUP only.)

Configure ethernet connection by the tool which is provided by plc maker. Then upload settings and plc program to the plc.

LadderDrive configuration

There is a configuration file at config/plc.yml. Currently, we support MITSUBISHI iQ-R R08CUP and the Emulator. You only change host to an IP address of your plc.

# plc.yml
plc:                        # Beginning of PLC section.
  iq-r:                     # It's a target name
    cpu: iq-r               # It's just a comment.
    protocol: mc_protocol   # It's a protocol to communicate with PLC.
    host: 192.168.0.10      # It's PLC's IP address or dns name.
    port: 5007              # It's PLC's port no.

LadderDrive programming

The Ladderdrive program file is located under the asm directory. By default, use asm/main.esc. Edit it and programming.

Refer Wiki to check mnemonic.

# main.esc
# |M0|-|M1|----(M2)
LD  M0
AND M1
OUT M2
END

Transfer the LadderDrive program

At the command prompt, use rake command to upload ladder_drive program to the plc. By default, the target plc is emulator. Then launch the Emulator.

$ rake

If you use with the target option, the target PLC is it.

$ rake target=iq-r

You can describe the default target by the target section in plc.yml.

# plc.yml
default:
  target: iq-r

rake is same as rake target=iq-r.

The LadderDrive program runs immediately after upload.

$ rake [target=iq-r]
uploading build/main.hex ...
launching emulator ...
done launching
done uploading

  LadderDrive is an abstract PLC.
  This is a console to communicate with PLC.

>

After uploading the program, it becomes in to console mode. You can read and write a device by entering commands.

Use the r command if you want to read devices. Below example reads values of devices from M0 to M7.

> r m0 8

Below example writes values to devices from M0 to M7.

> w m0 0 0 0 1 1 0 1 1

If you want to turn on and off the device like pushing a button, use p command.

> p m0

You can describe turn on time duration after a device. The unit is sec.

> p m0 1.5
# |M0|---(M1)
LD  M0
OUT M1

https://gyazo.com/565d24a35887503281a46775f6ccd747

Raspberry Pi

You can run it on the Raspberry Pi. X or Y devices are assigned to GPIOs.

Installation

$ sudo apt-get update
$ sudo apt-get install ruby-dev
$ sudo apt-get install libssl-dev
$ sudo gem install ladder_drive --no-ri --no-rdoc

Execution

$ ladder_drive create project
$ cd project
$ sudo rake target=raspberrypi

I/O settings

You can describe io configuration by confing/plc.yml file. Define inputs pins by inputs section. Devine outputs pins by outptus section. You can specify pull up or pull down and invert options for input.

  # Raspberry Pi
  raspberrypi:
    cpu: Raspberry Pi
    io: # assign gpio to x and y
      inputs:
        x0:
          pin: 4        # gpio no
          pull: up      # up | down | off
          invert: true
        x1:
          pin: 17
          pull: up
          invert: true
        x2:
          pin: 27
          pull: up
          invert: true
      outputs:
        y0:
          pin: 18
        y1:
          pin: 23
        y2:
          pin: 42

Run Ladder Drive as a service

Follow these steps to run ladder drive as a service at your project directory.

$ sudo rake service:install
$ sudo rake service:enable
$ sudo rake service:start

LadderDrive on Raspberry Pi

Accessing a device values

You can use LadderDrive as a accessing tool for the PLC device.

You can read/write device like this.

require 'ladder_drive'

plc = LadderDrive::Protocol::Mitsubishi::McProtocol.new host:"192.168.0.10"

plc["M0"] = true
plc["M0"]         # => true
plc["M0", 10]     # => [true, false, ..., false]

plc["D0"] = 123
plc["D0"]       # => 123
plc["D0", 10] = [0, 1, 2, ..., 9]
plc["D0".."D9"]   => [0, 1, 2, ..., 9]

Plugin

If you want to an enhancement function Ladder drive running on Unix based machine, use a plugin.

Put xxx_plugin.rb into your project's plugins directory. xxx is the name of the plugin. i.e.) If your plugin name is 'bar' then xxx is 'bar' . -> bar_plugin.rb

Callbacks

Ladder drive calls plugin_xxx_init function for the initialization. If you need to initialize it, to do here.

It also calls plugin_xxx_exec for execution of your plugin.

plugins

Ladder drive has several plugins by default. If you want to use a plugin, execute below command.

$ ladder_drive plugin plugin_name
Plugin name description
ifttt Launch IFTTT's Webhooks trigger service.
google_drive Writing data to Google spreadsheet.
plc_mapper Share other PLCs data with Ladder drive device.
slack Cast the data to the Slack.
trello Move the card of Trello to specified list.
ambient Writing data to Ambient.

Information related ladder_drive

License

The gem is available as open source under the terms of the MIT License.