Skip to content

Instantly share code, notes, and snippets.

View atimin's full-sized avatar
🎯
Focusing

Alexey Timin atimin

🎯
Focusing
View GitHub Profile
@atimin
atimin / With clearing buffer
Created June 27, 2012 21:14
RModBus perfomance. $ bundle exec ruby example/perfomance_rtu_via_tcp.rb
Rehearsal ------------------------------------------------------------
Read coils 0.480000 0.080000 0.560000 ( 0.495899)
Read discrete inputs 0.420000 0.140000 0.560000 ( 0.503507)
Read holding registers 1.360000 0.150000 1.510000 ( 1.436041)
Read input registers 1.330000 0.150000 1.480000 ( 1.424927)
Write single coil 0.290000 0.120000 0.410000 ( 0.335850)
Write single register 0.300000 0.090000 0.390000 ( 0.329078)
Write multiple coils 0.510000 0.120000 0.630000 ( 0.564480)
Write multiple registers 1.540000 0.110000 1.650000 ( 1.582799)
--------------------------------------------------- total: 7.190000sec
require "lipa/web"
#Configuration
srv = root :server do
node :message do
html text("Hello World!")
end
end
srv.run!
@atimin
atimin / test_rmd.rb
Created October 29, 2011 15:27
Pass options from client to slave
require "rmodbus"
ModBus::TCPClient.connect('127.0.0.1',9999) do |cl|
cl.debig = true
cl.with_slave(1) do |sl_1|
sl_1.debug #=> true
end
cl.with_slave(2) do |sl_2|
sl_2.debug = false
require "rmodbus"
s = ModBus::TCPServer.new(9999, 1)
s.holding_registers = [1] * 10
s.start
ModBus::TCPClient.connect('127.0.0.1',9999) do |cl|
cl.with_slave(1) do |slave|
slave.raise_exception_on_mismatch = true
slave.debug =true
@atimin
atimin / access_in_unix_style.rb
Created October 27, 2011 18:25
Examples for new features of lipa-0.3.0
dir_2["dir_1/dir_2/searched_obj"]
dir_2["searched_obj"]
dir_2["./searched_obj"]
dir_2["../dir_2/searched_obj"]
@atimin
atimin / calc_tree.rb
Created October 20, 2011 16:07
For articles about Lipa #1
require "lipa"
store = Lipa::Tree.new :store do
kind :category, :for => :node do
unit_count Proc.new {
count = 0
children.values.each do |u|
count += u.count if u.kind == "unit"
end
@atimin
atimin / fixed_bunch.rb
Created October 19, 2011 18:46
Lipa release-0.2.1
t = Lipa::Tree.new :tree do
kind :some_kind, :for => :node
with :attr_1 => 999 do
some_kind :obj_1
end
end
@atimin
atimin / access_lipa.rb
Created October 17, 2011 17:35
Lipa release-0.2.0
Lipa::Tree["tree://dir_1/dir_2/file_1"].size
#or
tree["dir_1/dir_2/file_1"].size
#or
tree.dir_1.dir_2.file_1.size
@atimin
atimin / xpca_modbus
Created October 17, 2011 09:46
Example XPCA gateway for ModBus
#!/usr/bin/env ruby
=begin
It's very simple example of implementation
REST-PCA gateway
for communication with TCP ModBus devices
It receives REST requests
(e.g http://127.0.0.1:4567/mb/127.0.0.1/8502/1/coils/6/17 )
and returns data in JSON format addr : data:
{"coils": {
"6":{
@atimin
atimin / sun_system.rb
Created October 17, 2011 07:17
Example for Lipa
require 'lipa'
un = root :universe do
kind :planet_system do
num_planet run{
count = 0
children.values.each do |planet|
count += 1 if planet.kind == :planet
end
count