Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Work with BinData #19

@atimin

Description

@atimin

I like the bindata library, and I think that would be fine if RModBus will provides a simple method to work with it:

  require 'bindata'
  require 'rmodbus'

  class Pump < BindData::Records
    endian :big

    uint16 :state
    float  :temp
    float  :pressure

    def stopped?
      state == 0
    end
  end

  ModBus::TCPClient.connect('localhost') do |cl|
    cl.with_slave(1) do |sl|
       pump1 = sl.make_image(Pump, :holding, 0...10)
       pump1.read

       pump1.stopped?  #=> false
    end
  end

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions