rmodbus 1.3.1 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 527837e39897ba74bd43ca15325a17e931fea9a8
4
- data.tar.gz: e244ecaa6b7ae3d0c2a80798ad4f799f58458a30
3
+ metadata.gz: 14b716e9730d683db654f82d88e801739a0786e6
4
+ data.tar.gz: 17f4c3fd6ab5d45f637c4abb032ed752a2930b3d
5
5
  SHA512:
6
- metadata.gz: 127f4c8fa6f2958425a750f144d70223747dc1b058a1e7954bad9bf1d1a15d8378e592c9f017f38807fbf66683790274a3e0fe9f782ee31a00634a48c95fa3d7
7
- data.tar.gz: 54a418c81c178a32890040396f2658fc123d561cfd4821044b3f75168bf254c50a8bf32d388b78f12ac614f0192022dc108040ff55e183363b1d0e8d0d8863cc
6
+ metadata.gz: 9cfe7c1e4a91739f80ff23647e57f6ff41fba15eda4f1469699331e4d8a11f36bd664005610b195785def7241fcc9bdfa7f14c8852908da54876c6ee040c0d72
7
+ data.tar.gz: 26ddc5f16f7d175061dc86a5dae065deed8cb542d7b8a9850ff9a0c1e655eeb12d3b1154598e8faf67a5c852c3b5edfd91bf701b56d60f07e12d51855790c382
data/NEWS.md CHANGED
@@ -1,3 +1,8 @@
1
+ ###2017-03-30 Release 1.3.2
2
+
3
+ 1. Fix Fixnum warning on Ruby 2.4
4
+ 2. Add extension method to support unpacking 32-bit Int using little-endian order
5
+
1
6
  ###2016-10-18 Release 1.3.0
2
7
 
3
8
  1. Turn the following dependencies optional: serialport, gserver
data/lib/rmodbus/ext.rb CHANGED
@@ -39,6 +39,12 @@ class Array
39
39
  self.each_slice(2).map { |(lsb, msb)| [msb, lsb].pack('n*').unpack('g')[0] }
40
40
  end
41
41
 
42
+ # Given an array of 16bit Fixnum, we turn it into 32bit Int in little-endian order, halving the size
43
+ def to_32f_le
44
+ raise "Array requires an even number of elements to pack to 32bits: was #{self.size}" unless self.size.even?
45
+ self.each_slice(2).map { |(lsb, msb)| [lsb, msb].pack('n*').unpack('g')[0] }
46
+ end
47
+
42
48
  # Given an array of 32bit Floats, we turn it into an array of 16bit Fixnums, doubling the size
43
49
  def from_32f
44
50
  self.pack('g*').unpack('n*').each_slice(2).map { |arr| arr.reverse }.flatten
data/lib/rmodbus/proxy.rb CHANGED
@@ -9,7 +9,7 @@ module ModBus
9
9
  # Read single or multiple values from a modbus slave depending on whether a Fixnum or a Range was given.
10
10
  # Note that in the case of multiples, a pluralized version of the method is sent to the slave
11
11
  def [](key)
12
- if key.instance_of?(Fixnum)
12
+ if key.instance_of?(0.class)
13
13
  @slave.send("read_#{@type}", key, 1)
14
14
  elsif key.instance_of?(Range)
15
15
  @slave.send("read_#{@type}s", key.first, key.count)
@@ -24,7 +24,7 @@ module ModBus
24
24
  # Note that in the case of multiples, a pluralized version of the method is sent to the slave. Also when
25
25
  # writing multiple values, the number of elements must match the number of registers in the range or an exception is raised
26
26
  def []=(key, val)
27
- if key.instance_of?(Fixnum)
27
+ if key.instance_of?(0.class)
28
28
  @slave.send("write_#{@type}", key, val)
29
29
  elsif key.instance_of?(Range)
30
30
  if key.count != val.size
@@ -1,4 +1,4 @@
1
1
  module ModBus
2
2
  # Package version
3
- VERSION = '1.3.1'
3
+ VERSION = '1.3.2'
4
4
  end
data/spec/ext_spec.rb CHANGED
@@ -24,10 +24,15 @@ describe Array do
24
24
  [20342, 17344, 20342, 17344].to_32i.size.should == 2
25
25
  end
26
26
 
27
- it "should turn an array into 32b floats" do
27
+ it "should turn an array into 32b floats big endian" do
28
28
  [20342, 17344].to_32f[0].should be_within(0.1).of(384.620788574219)
29
29
  [20342, 17344, 20342, 17344].to_32f.size.should == 2
30
30
  end
31
+
32
+ it "should turn a an array into 32b floats (little endian)" do
33
+ [17344, 20342].to_32f_le[0].should be_within(0.1).of(384.620788574219)
34
+ [17344, 20342, 17344, 20342].to_32f_le.size.should == 2
35
+ end
31
36
 
32
37
  it "should turn an array from 32b ints into 16b ints, big endian" do
33
38
  [1136676726].from_32i.should == [20342, 17344]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rmodbus
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - A.Timin, J. Sanders, K. Reynolds, F. Luizão
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-23 00:00:00.000000000 Z
11
+ date: 2017-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -187,7 +187,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
187
187
  version: '0'
188
188
  requirements: []
189
189
  rubyforge_project:
190
- rubygems_version: 2.6.6
190
+ rubygems_version: 2.6.11
191
191
  signing_key:
192
192
  specification_version: 4
193
193
  summary: RModBus - free implementation of protocol ModBus