Class: HuaweiSolar

Inherits:
Object
  • Object
show all
Defined in:
lib/huawei_solar.rb,
lib/huawei_solar/version.rb

Defined Under Namespace

Modules: VERSION Classes: I16, I32, String, U16, U32

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, port = 502, **opts) ⇒ HuaweiSolar

Returns a new instance of HuaweiSolar.



8
9
10
11
12
13
# File 'lib/huawei_solar.rb', line 8

def initialize(host, port=502, **opts)
  @client = ModBus::TCPClient.connect(host, port, opts)
  @client.debug = !ENV["DEBUG"].nil?
  @slave = @client.with_slave(1)
  @registers = YAML.load_file(File.expand_path("../data/registers.yml", __dir__))
end

Class Method Details

.gem_versionObject



17
18
19
# File 'lib/huawei_solar/version.rb', line 17

def self.gem_version
  Gem::Version.new VERSION::STRING
end

.versionObject



13
14
15
# File 'lib/huawei_solar/version.rb', line 13

def self.version
  VERSION::STRING
end

Instance Method Details

#closeObject



23
24
25
# File 'lib/huawei_solar.rb', line 23

def close
  @client.close
end

#read(name, **options) ⇒ Object



15
16
17
# File 'lib/huawei_solar.rb', line 15

def read(name, **options)
  name.is_a?(Array) ? read_multiple(name, **options) : read_single(name, **options)
end

#read_all(**options) ⇒ Object



19
20
21
# File 'lib/huawei_solar.rb', line 19

def read_all(**options)
  read_multiple(@registers.keys, **options)
end