GithubHelp home page GithubHelp logo

ruby_s7plc's Introduction

Version Inline docs

ruby_s7plc

Ruby library for Siemens Simatic S7-300 PLC data exchange.

Quick start

  require 'simatic'
  Simatic::Plc.exchange('192.168.0.1') do |plc|
    plc.write('db1.dbw2'=> 0xffff)
    res = plc.read('db1.dbw2')
    puts "#{res.verbal} = #{Simatic::Types::Word.parse(res.value)}"
  end

Reference

Install

  # in Gemfile
  gem 'simatic'

or

  gem install simatic

Requires

  require 'simatic'

Client creation

  plc = Simatic::Plc.new('192.168.0.1')
  plc.connect
  # Add you code here
  plc.disconnect

Or with block:

  Simatic::Plc.exchange('192.168.0.1') do |plc|
    # Add you code here
  end

You can specify rack and slot parametrs by adding a hash args to functions or , defaults rack: 0, slot: 2

Simatic::Plc.new('192.168.0.1', rack: 0, slot: 2) ...
Simatic::Plc.exchange('192.168.0.1', rack: 0, slot: 2) do |plc| ...

Exchange functions

plc.read('db1.dbx0.0')

This function can understand verbal adressing in Simatic Step 7 notation, like M0.0, DB1.DBB23, C0, T1 and so on. Result of this funtion is a MemoryMapper object that can give you raw_data and value of plc response. After this function you should use SymaticTypes module to convert data into ruby undestandable types.

plc.write('db1.dbw2' => 0xffff)

This function take a hash with verbal addresses and values to write pairs. Values can be simple types like Integer, Float, one char String, Date, Time or it can be special types of SimaticTypes Module.

plc.write('db1.dbb18[2]'  => Simatic::Types::S5time.new(711.3))

Convertation functions

Simatic::Types::Bool   # use TrueClass, FalseClass
Simatic::Types::Byte   # use Numeric
Simatic::Types::Word   # use Numeric
Simatic::Types::Dword  # use Numeric
Simatic::Types::Int    # use Numeric
Simatic::Types::Dint   # use Numeric
Simatic::Types::Real   # use Numeric
Simatic::Types::S5time # use Numeric as a time in seconds
Simatic::Types::IECTime     # use Numeric as a time in seconds
Simatic::Types::IECDate     # use Numeric as a days
Simatic::Types::TimeOfDay   # use Numeric as a seconds from start of day 0:00 a.m.
Simatic::Types::DateAndTime # use Time
Simatic::Types::S7String    # use String with length of buffer param

Each of this objects take Ruby types with new method and gives you with parse method:

Simatic::Types::S5time.new(10.2)
Simatic::Types::S5time.parse(res.raw_data)
Simatic::Types::S7String.new("hello world", 15) # 15 is a length of buffer (address for this string to read or write must be [17])

For special types like S5time, IECTime, IECDate, TimeOfDay, DateAndTime, S7String you should use raw_data method instead of value, because if you write an adress with [] notation of bytes value will return a array of chars.

Waring

This is beta code! Do not use it in danger manufactory!

See also

Father and oldest of all open Simatic communication libraries is Libnodave project:

Another interesting projects:

ruby_s7plc's People

Contributors

dasgib avatar konstantin-ryzhov avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.