rmodbus 1.3.1 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/NEWS.md +5 -0
- data/lib/rmodbus/ext.rb +6 -0
- data/lib/rmodbus/proxy.rb +2 -2
- data/lib/rmodbus/version.rb +1 -1
- data/spec/ext_spec.rb +6 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 14b716e9730d683db654f82d88e801739a0786e6
|
4
|
+
data.tar.gz: 17f4c3fd6ab5d45f637c4abb032ed752a2930b3d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9cfe7c1e4a91739f80ff23647e57f6ff41fba15eda4f1469699331e4d8a11f36bd664005610b195785def7241fcc9bdfa7f14c8852908da54876c6ee040c0d72
|
7
|
+
data.tar.gz: 26ddc5f16f7d175061dc86a5dae065deed8cb542d7b8a9850ff9a0c1e655eeb12d3b1154598e8faf67a5c852c3b5edfd91bf701b56d60f07e12d51855790c382
|
data/NEWS.md
CHANGED
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?(
|
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?(
|
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
|
data/lib/rmodbus/version.rb
CHANGED
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.
|
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:
|
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.
|
190
|
+
rubygems_version: 2.6.11
|
191
191
|
signing_key:
|
192
192
|
specification_version: 4
|
193
193
|
summary: RModBus - free implementation of protocol ModBus
|