rmodbus 1.3.0 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +17 -3
- data/lib/rmodbus.rb +0 -12
- data/lib/rmodbus/client.rb +1 -15
- data/lib/rmodbus/debug.rb +2 -18
- data/lib/rmodbus/errors.rb +37 -51
- data/lib/rmodbus/ext.rb +79 -94
- data/lib/rmodbus/options.rb +2 -17
- data/lib/rmodbus/proxy.rb +2 -15
- data/lib/rmodbus/rtu.rb +3 -19
- data/lib/rmodbus/rtu_client.rb +0 -13
- data/lib/rmodbus/rtu_server.rb +0 -14
- data/lib/rmodbus/rtu_slave.rb +0 -13
- data/lib/rmodbus/rtu_via_tcp_client.rb +0 -14
- data/lib/rmodbus/rtu_via_tcp_server.rb +11 -22
- data/lib/rmodbus/rtu_via_tcp_slave.rb +0 -13
- data/lib/rmodbus/server.rb +0 -15
- data/lib/rmodbus/slave.rb +0 -15
- data/lib/rmodbus/sp.rb +0 -14
- data/lib/rmodbus/tcp.rb +1 -14
- data/lib/rmodbus/tcp_client.rb +0 -13
- data/lib/rmodbus/tcp_server.rb +5 -14
- data/lib/rmodbus/tcp_slave.rb +3 -16
- data/lib/rmodbus/version.rb +1 -14
- metadata +13 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 527837e39897ba74bd43ca15325a17e931fea9a8
|
4
|
+
data.tar.gz: e244ecaa6b7ae3d0c2a80798ad4f799f58458a30
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 127f4c8fa6f2958425a750f144d70223747dc1b058a1e7954bad9bf1d1a15d8378e592c9f017f38807fbf66683790274a3e0fe9f782ee31a00634a48c95fa3d7
|
7
|
+
data.tar.gz: 54a418c81c178a32890040396f2658fc123d561cfd4821044b3f75168bf254c50a8bf32d388b78f12ac614f0192022dc108040ff55e183363b1d0e8d0d8863cc
|
data/README.md
CHANGED
@@ -88,14 +88,28 @@ Given a version number MAJOR.MINOR.PATCH, increment the:
|
|
88
88
|
MAJOR version when you make incompatible API changes,
|
89
89
|
MINOR version when you add functionality in a backwards-compatible manner, and
|
90
90
|
PATCH version when you make backwards-compatible bug fixes.
|
91
|
-
Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR.PATCH format.
|
92
91
|
```
|
93
92
|
|
94
|
-
|
93
|
+
Contributing
|
95
94
|
----------------------------------
|
96
95
|
|
97
|
-
|
96
|
+
See [CONTRIBUTING](CONTRIBUTING.md).
|
97
|
+
|
98
|
+
Reference
|
99
|
+
----------------------------------
|
98
100
|
|
99
101
|
RModBus on GitHub: http://github.com/rmodbus/rmodbus
|
100
102
|
|
103
|
+
Documentation: http://www.rubydoc.info/github/rmodbus/rmodbus
|
104
|
+
|
101
105
|
ModBus specifications: http://www.modbus.org/specs.php
|
106
|
+
|
107
|
+
License
|
108
|
+
----------------------------------
|
109
|
+
|
110
|
+
BSD-3-Clause
|
111
|
+
|
112
|
+
Credits
|
113
|
+
----------------------------------
|
114
|
+
|
115
|
+
Aleksey Timin - original author
|
data/lib/rmodbus.rb
CHANGED
@@ -1,15 +1,3 @@
|
|
1
|
-
# RModBus - free implementation of ModBus protocol on Ruby.
|
2
|
-
# Copyright (C) 2008 - 2011 Timin Aleksey
|
3
|
-
# This program is free software: you can redistribute it and/or modify
|
4
|
-
# it under the terms of the GNU General Public License as published by
|
5
|
-
# the Free Software Foundation, either version 3 of the License, or
|
6
|
-
# (at your option) any later version.
|
7
|
-
#
|
8
|
-
# This program is distributed in the hope that it will be useful,
|
9
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
-
# GNU General Public License for more details.
|
12
|
-
|
13
1
|
require 'rmodbus/ext'
|
14
2
|
require 'rmodbus/proxy'
|
15
3
|
require 'rmodbus/version'
|
data/lib/rmodbus/client.rb
CHANGED
@@ -1,17 +1,3 @@
|
|
1
|
-
# RModBus - free implementation of ModBus protocol on Ruby.
|
2
|
-
#
|
3
|
-
# Copyright (C) 2008-2011 Timin Aleksey
|
4
|
-
#
|
5
|
-
# This program is free software: you can redistribute it and/or modify
|
6
|
-
# it under the terms of the GNU General Public License as published by
|
7
|
-
# the Free Software Foundation, either version 3 of the License, or
|
8
|
-
# (at your option) any later version.
|
9
|
-
#
|
10
|
-
# This program is distributed in the hope that it will be useful,
|
11
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
-
# GNU General Public License for more details.
|
14
|
-
|
15
1
|
module ModBus
|
16
2
|
# @abstract
|
17
3
|
class Client
|
@@ -28,7 +14,7 @@ module ModBus
|
|
28
14
|
# @yield return client object and close it before exit
|
29
15
|
# @return [Client] client object
|
30
16
|
def initialize(*args, &block)
|
31
|
-
# Defaults
|
17
|
+
# Defaults
|
32
18
|
@debug = false
|
33
19
|
@raise_exception_on_mismatch = false
|
34
20
|
@read_retry_timeout = 1
|
data/lib/rmodbus/debug.rb
CHANGED
@@ -1,22 +1,7 @@
|
|
1
|
-
# RModBus - free implementation of ModBus protocol in Ruby.
|
2
|
-
#
|
3
|
-
# Copyright (C) 2010-2011 Timin Aleksey
|
4
|
-
# Copyright (C) 2010 Kelley Reynolds
|
5
|
-
#
|
6
|
-
# This program is free software: you can redistribute it and/or modify
|
7
|
-
# it under the terms of the GNU General Public License as published by
|
8
|
-
# the Free Software Foundation, either version 3 of the License, or
|
9
|
-
# (at your option) any later version.
|
10
|
-
#
|
11
|
-
# This program is distributed in the hope that it will be useful,
|
12
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
-
# GNU General Public License for more details.
|
15
|
-
|
16
1
|
module ModBus
|
17
2
|
module Debug
|
18
|
-
attr_accessor :debug, :raise_exception_on_mismatch,
|
19
|
-
:read_retries, :read_retry_timeout
|
3
|
+
attr_accessor :debug, :raise_exception_on_mismatch,
|
4
|
+
:read_retries, :read_retry_timeout
|
20
5
|
|
21
6
|
|
22
7
|
private
|
@@ -45,4 +30,3 @@ module ModBus
|
|
45
30
|
end
|
46
31
|
end
|
47
32
|
end
|
48
|
-
|
data/lib/rmodbus/errors.rb
CHANGED
@@ -1,56 +1,42 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
class Acknowledge < ModBusException
|
36
|
-
end
|
37
|
-
|
38
|
-
class SlaveDeviceBus < ModBusException
|
39
|
-
end
|
40
|
-
|
41
|
-
class MemoryParityError < ModBusException
|
42
|
-
end
|
43
|
-
|
44
|
-
class ModBusTimeout < ModBusException
|
45
|
-
end
|
46
|
-
|
1
|
+
module ModBus
|
2
|
+
module Errors
|
3
|
+
class ProxyException < StandardError
|
4
|
+
end
|
5
|
+
|
6
|
+
class ModBusException < StandardError
|
7
|
+
end
|
8
|
+
|
9
|
+
class IllegalFunction < ModBusException
|
10
|
+
end
|
11
|
+
|
12
|
+
class IllegalDataAddress < ModBusException
|
13
|
+
end
|
14
|
+
|
15
|
+
class IllegalDataValue < ModBusException
|
16
|
+
end
|
17
|
+
|
18
|
+
class SlaveDeviceFailure < ModBusException
|
19
|
+
end
|
20
|
+
|
21
|
+
class Acknowledge < ModBusException
|
22
|
+
end
|
23
|
+
|
24
|
+
class SlaveDeviceBus < ModBusException
|
25
|
+
end
|
26
|
+
|
27
|
+
class MemoryParityError < ModBusException
|
28
|
+
end
|
29
|
+
|
30
|
+
class ModBusTimeout < ModBusException
|
31
|
+
end
|
32
|
+
|
47
33
|
class ResponseMismatch < ModBusException
|
48
34
|
attr_reader :request, :response
|
49
|
-
def initialize(msg, request, response)
|
35
|
+
def initialize(msg, request, response)
|
50
36
|
super(msg)
|
51
37
|
@request = request
|
52
38
|
@response = response
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/rmodbus/ext.rb
CHANGED
@@ -1,94 +1,79 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
if mask == 0x100
|
81
|
-
mask = 0x01
|
82
|
-
s << word.chr
|
83
|
-
word = 0
|
84
|
-
end
|
85
|
-
end
|
86
|
-
unless mask == 0x01
|
87
|
-
s << word.chr
|
88
|
-
else
|
89
|
-
s
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
end
|
94
|
-
|
1
|
+
class String
|
2
|
+
|
3
|
+
if RUBY_VERSION < "1.9"
|
4
|
+
def getbyte(index)
|
5
|
+
self[index].to_i
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def unpack_bits
|
10
|
+
array_bit = []
|
11
|
+
self.unpack('b*')[0].each_char do |c|
|
12
|
+
array_bit << c.to_i
|
13
|
+
end
|
14
|
+
array_bit
|
15
|
+
end
|
16
|
+
|
17
|
+
# Get word by index
|
18
|
+
# @param [Integer] i index first bytes of word
|
19
|
+
# @return unpacked word
|
20
|
+
def getword(i)
|
21
|
+
self[i,2].unpack('n')[0]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class Integer
|
26
|
+
|
27
|
+
# Shortcut or turning an integer into a word
|
28
|
+
def to_word
|
29
|
+
[self].pack('n')
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
class Array
|
35
|
+
|
36
|
+
# Given an array of 16bit Fixnum, we turn it into 32bit Int in big-endian order, halving the size
|
37
|
+
def to_32f
|
38
|
+
raise "Array requires an even number of elements to pack to 32bits: was #{self.size}" unless self.size.even?
|
39
|
+
self.each_slice(2).map { |(lsb, msb)| [msb, lsb].pack('n*').unpack('g')[0] }
|
40
|
+
end
|
41
|
+
|
42
|
+
# Given an array of 32bit Floats, we turn it into an array of 16bit Fixnums, doubling the size
|
43
|
+
def from_32f
|
44
|
+
self.pack('g*').unpack('n*').each_slice(2).map { |arr| arr.reverse }.flatten
|
45
|
+
end
|
46
|
+
|
47
|
+
# Given an array of 16bit Fixnum, we turn it into 32bit Float in big-endian order, halving the size
|
48
|
+
def to_32i
|
49
|
+
raise "Array requires an even number of elements to pack to 32bits: was #{self.size}" unless self.size.even?
|
50
|
+
self.each_slice(2).map { |(lsb, msb)| [msb, lsb].pack('n*').unpack('N')[0] }
|
51
|
+
end
|
52
|
+
|
53
|
+
# Given an array of 32bit Fixnum, we turn it into an array of 16bit fixnums, doubling the size
|
54
|
+
def from_32i
|
55
|
+
self.pack('N*').unpack('n*').each_slice(2).map { |arr| arr.reverse }.flatten
|
56
|
+
end
|
57
|
+
|
58
|
+
def pack_to_word
|
59
|
+
word = 0
|
60
|
+
s = ""
|
61
|
+
mask = 0x01
|
62
|
+
|
63
|
+
self.each do |bit|
|
64
|
+
word |= mask if bit > 0
|
65
|
+
mask <<= 1
|
66
|
+
if mask == 0x100
|
67
|
+
mask = 0x01
|
68
|
+
s << word.chr
|
69
|
+
word = 0
|
70
|
+
end
|
71
|
+
end
|
72
|
+
unless mask == 0x01
|
73
|
+
s << word.chr
|
74
|
+
else
|
75
|
+
s
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
data/lib/rmodbus/options.rb
CHANGED
@@ -1,21 +1,6 @@
|
|
1
|
-
# RModBus - free implementation of ModBus protocol in Ruby.
|
2
|
-
#
|
3
|
-
# Copyright (C) 2011 Timin Aleksey
|
4
|
-
#
|
5
|
-
# This program is free software: you can redistribute it and/or modify
|
6
|
-
# it under the terms of the GNU General Public License as published by
|
7
|
-
# the Free Software Foundation, either version 3 of the License, or
|
8
|
-
# (at your option) any later version.
|
9
|
-
#
|
10
|
-
# This program is distributed in the hope that it will be useful,
|
11
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
-
# GNU General Public License for more details.
|
14
|
-
|
15
1
|
module ModBus
|
16
2
|
module Options
|
17
|
-
attr_accessor :raise_exception_on_mismatch,
|
18
|
-
:read_retries, :read_retry_timeout
|
3
|
+
attr_accessor :raise_exception_on_mismatch,
|
4
|
+
:read_retries, :read_retry_timeout
|
19
5
|
end
|
20
6
|
end
|
21
|
-
|
data/lib/rmodbus/proxy.rb
CHANGED
@@ -1,16 +1,3 @@
|
|
1
|
-
# ReadOnly and ReadWrite hash interface for modbus registers and coils
|
2
|
-
#
|
3
|
-
# Copyright (C) 2010 Kelley Reynolds
|
4
|
-
#
|
5
|
-
# This program is free software: you can redistribute it and/or modify
|
6
|
-
# it under the terms of the GNU General Public License as published by
|
7
|
-
# the Free Software Foundation, either version 3 of the License, or
|
8
|
-
# (at your option) any later version.
|
9
|
-
#
|
10
|
-
# This program is distributed in the hope that it will be useful,
|
11
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
-
# GNU General Public License for more details.
|
14
1
|
module ModBus
|
15
2
|
# Given a slave and a type of operation, execute a single or multiple read using hash syntax
|
16
3
|
class ReadOnlyProxy
|
@@ -31,7 +18,7 @@ module ModBus
|
|
31
18
|
end
|
32
19
|
end
|
33
20
|
end
|
34
|
-
|
21
|
+
|
35
22
|
class ReadWriteProxy < ReadOnlyProxy
|
36
23
|
# Write single or multiple values to a modbus slave depending on whether a Fixnum or a Range was given.
|
37
24
|
# Note that in the case of multiples, a pluralized version of the method is sent to the slave. Also when
|
@@ -51,4 +38,4 @@ module ModBus
|
|
51
38
|
end
|
52
39
|
end
|
53
40
|
|
54
|
-
end
|
41
|
+
end
|
data/lib/rmodbus/rtu.rb
CHANGED
@@ -1,18 +1,3 @@
|
|
1
|
-
# RModBus - free implementation of ModBus protocol in Ruby.
|
2
|
-
#
|
3
|
-
# Copyright (C) 2010 - 2011 Timin Aleksey
|
4
|
-
# Copyright (C) 2010 Kelley Reynolds
|
5
|
-
#
|
6
|
-
# This program is free software: you can redistribute it and/or modify
|
7
|
-
# it under the terms of the GNU General Public License as published by
|
8
|
-
# the Free Software Foundation, either version 3 of the License, or
|
9
|
-
# (at your option) any later version.
|
10
|
-
#
|
11
|
-
# This program is distributed in the hope that it will be useful,
|
12
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
-
# GNU General Public License for more details.
|
15
|
-
|
16
1
|
module ModBus
|
17
2
|
module RTU
|
18
3
|
private
|
@@ -47,7 +32,7 @@ module ModBus
|
|
47
32
|
def clean_input_buff
|
48
33
|
# empty the input buffer
|
49
34
|
if @io.class.public_method_defined? :flush_input
|
50
|
-
@io.flush_input
|
35
|
+
@io.flush_input
|
51
36
|
else
|
52
37
|
@io.flush
|
53
38
|
end
|
@@ -56,8 +41,8 @@ module ModBus
|
|
56
41
|
def send_rtu_pdu(pdu)
|
57
42
|
msg = @uid.chr + pdu
|
58
43
|
msg << crc16(msg).to_word
|
59
|
-
|
60
|
-
clean_input_buff
|
44
|
+
|
45
|
+
clean_input_buff
|
61
46
|
@io.write msg
|
62
47
|
|
63
48
|
log "Tx (#{msg.size} bytes): " + logging_bytes(msg)
|
@@ -177,4 +162,3 @@ module ModBus
|
|
177
162
|
|
178
163
|
end
|
179
164
|
end
|
180
|
-
|
data/lib/rmodbus/rtu_client.rb
CHANGED
@@ -1,16 +1,3 @@
|
|
1
|
-
# RModBus - free implementation of ModBus protocol in Ruby.
|
2
|
-
#
|
3
|
-
# Copyright (C) 2009-2011 Timin Aleksey
|
4
|
-
#
|
5
|
-
# This program is free software: you can redistribute it and/or modify
|
6
|
-
# it under the terms of the GNU General Public License as published by
|
7
|
-
# the Free Software Foundation, either version 3 of the License, or
|
8
|
-
# (at your option) any later version.
|
9
|
-
#
|
10
|
-
# This program is distributed in the hope that it will be useful,
|
11
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
-
# GNU General Public License for more details.
|
14
1
|
module ModBus
|
15
2
|
# RTU client implementation
|
16
3
|
# @example
|
data/lib/rmodbus/rtu_server.rb
CHANGED
@@ -1,17 +1,3 @@
|
|
1
|
-
# RModBus - free implementation of ModBus protocol in Ruby.
|
2
|
-
#
|
3
|
-
# Copyright (C) 2010-2011 Timin Aleksey
|
4
|
-
#
|
5
|
-
# This program is free software: you can redistribute it and/or modify
|
6
|
-
# it under the terms of the GNU General Public License as published by
|
7
|
-
# the Free Software Foundation, either version 3 of the License, or
|
8
|
-
# (at your option) any later version.
|
9
|
-
#
|
10
|
-
# This program is distributed in the hope that it will be useful,
|
11
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
-
# GNU General Public License for more details.
|
14
|
-
#
|
15
1
|
module ModBus
|
16
2
|
# RTU server implementation
|
17
3
|
# @example
|
data/lib/rmodbus/rtu_slave.rb
CHANGED
@@ -1,16 +1,3 @@
|
|
1
|
-
# RModBus - free implementation of ModBus protocol in Ruby.
|
2
|
-
#
|
3
|
-
# Copyright (C) 2011 Timin Aleksey
|
4
|
-
#
|
5
|
-
# This program is free software: you can redistribute it and/or modify
|
6
|
-
# it under the terms of the GNU General Public License as published by
|
7
|
-
# the Free Software Foundation, either version 3 of the License, or
|
8
|
-
# (at your option) any later version.
|
9
|
-
#
|
10
|
-
# This program is distributed in the hope that it will be useful,
|
11
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
-
# GNU General Public License for more details.
|
14
1
|
module ModBus
|
15
2
|
# RTU slave implementation
|
16
3
|
# @example
|
@@ -1,17 +1,3 @@
|
|
1
|
-
# RModBus - free implementation of ModBus protocol in Ruby.
|
2
|
-
#
|
3
|
-
# Copyright (C) 2009-2011 Timin Aleksey
|
4
|
-
# Copyright (C) 2010 Kelley Reynolds
|
5
|
-
#
|
6
|
-
# This program is free software: you can redistribute it and/or modify
|
7
|
-
# it under the terms of the GNU General Public License as published by
|
8
|
-
# the Free Software Foundation, either version 3 of the License, or
|
9
|
-
# (at your option) any later version.
|
10
|
-
#
|
11
|
-
# This program is distributed in the hope that it will be useful,
|
12
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
-
# GNU General Public License for more details.
|
15
1
|
module ModBus
|
16
2
|
# RTU over TCP client implementation
|
17
3
|
# @example
|
@@ -1,19 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
# This program is free software: you can redistribute it and/or modify
|
7
|
-
# it under the terms of the GNU General Public License as published by
|
8
|
-
# the Free Software Foundation, either version 3 of the License, or
|
9
|
-
# (at your option) any later version.
|
10
|
-
#
|
11
|
-
# This program is distributed in the hope that it will be useful,
|
12
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
-
# GNU General Public License for more details.
|
15
|
-
|
16
|
-
require 'gserver'
|
1
|
+
begin
|
2
|
+
require 'gserver'
|
3
|
+
rescue
|
4
|
+
warn "[WARNING] Install `gserver` gem for use RTUViaTCPServer"
|
5
|
+
end
|
17
6
|
|
18
7
|
module ModBus
|
19
8
|
# RTU over TCP server implementation
|
@@ -33,14 +22,14 @@ module ModBus
|
|
33
22
|
# Init server
|
34
23
|
# @param [Integer] port listen port
|
35
24
|
# @param [Integer] uid slave device
|
36
|
-
# @param [Hash] opts options of server
|
25
|
+
# @param [Hash] opts options of server
|
37
26
|
# @option opts [String] :host host of server default '127.0.0.1'
|
38
27
|
# @option opts [Float, Integer] :max_connection max of TCP connection with server default 4
|
39
|
-
def initialize(port = 10002, uid = 1, opts = {})
|
40
|
-
@uid = uid
|
41
|
-
opts[:host] = DEFAULT_HOST unless opts[:host]
|
42
|
-
opts[:max_connection] = 4 unless opts[:max_connection]
|
43
|
-
super(port, host = opts[:host], maxConnection = opts[:max_connection])
|
28
|
+
def initialize(port = 10002, uid = 1, opts = {})
|
29
|
+
@uid = uid
|
30
|
+
opts[:host] = DEFAULT_HOST unless opts[:host]
|
31
|
+
opts[:max_connection] = 4 unless opts[:max_connection]
|
32
|
+
super(port, host = opts[:host], maxConnection = opts[:max_connection])
|
44
33
|
end
|
45
34
|
|
46
35
|
protected
|
@@ -1,16 +1,3 @@
|
|
1
|
-
# RModBus - free implementation of ModBus protocol in Ruby.
|
2
|
-
#
|
3
|
-
# Copyright (C) 2011 Timin Aleksey
|
4
|
-
#
|
5
|
-
# This program is free software: you can redistribute it and/or modify
|
6
|
-
# it under the terms of the GNU General Public License as published by
|
7
|
-
# the Free Software Foundation, either version 3 of the License, or
|
8
|
-
# (at your option) any later version.
|
9
|
-
#
|
10
|
-
# This program is distributed in the hope that it will be useful,
|
11
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
-
# GNU General Public License for more details.
|
14
1
|
module ModBus
|
15
2
|
# RTU over TCP slave implementation
|
16
3
|
# @example
|
data/lib/rmodbus/server.rb
CHANGED
@@ -1,18 +1,3 @@
|
|
1
|
-
# RModBus - free implementation of ModBus protocol in Ruby.
|
2
|
-
#
|
3
|
-
# Copyright (C) 2010 Timin Aleksey
|
4
|
-
# Copyright (C) 2010 Kelley Reynolds
|
5
|
-
#
|
6
|
-
# This program is free software: you can redistribute it and/or modify
|
7
|
-
# it under the terms of the GNU General Public License as published by
|
8
|
-
# the Free Software Foundation, either version 3 of the License, or
|
9
|
-
# (at your option) any later version.
|
10
|
-
#
|
11
|
-
# This program is distributed in the hope that it will be useful,
|
12
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
-
# GNU General Public License for more details.
|
15
|
-
|
16
1
|
module ModBus
|
17
2
|
# Module for implementation ModBus server
|
18
3
|
module Server
|
data/lib/rmodbus/slave.rb
CHANGED
@@ -1,18 +1,3 @@
|
|
1
|
-
# RModBus - free implementation of ModBus protocol on Ruby.
|
2
|
-
#
|
3
|
-
# Copyright (C) 2008-2011 Timin Aleksey
|
4
|
-
# Copyright (C) 2010 Kelley Reynolds
|
5
|
-
#
|
6
|
-
# This program is free software: you can redistribute it and/or modify
|
7
|
-
# it under the terms of the GNU General Public License as published by
|
8
|
-
# the Free Software Foundation, either version 3 of the License, or
|
9
|
-
# (at your option) any later version.
|
10
|
-
#
|
11
|
-
# This program is distributed in the hope that it will be useful,
|
12
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
-
# GNU General Public License for more details.
|
15
|
-
|
16
1
|
module ModBus
|
17
2
|
class Slave
|
18
3
|
include Errors
|
data/lib/rmodbus/sp.rb
CHANGED
@@ -1,17 +1,3 @@
|
|
1
|
-
# RModBus - free implementation of ModBus protocol in Ruby.
|
2
|
-
#
|
3
|
-
# Copyright (C) 2011 Timin Aleksey
|
4
|
-
#
|
5
|
-
# This program is free software: you can redistribute it and/or modify
|
6
|
-
# it under the terms of the GNU General Public License as published by
|
7
|
-
# the Free Software Foundation, either version 3 of the License, or
|
8
|
-
# (at your option) any later version.
|
9
|
-
#
|
10
|
-
# This program is distributed in the hope that it will be useful,
|
11
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
-
# GNU General Public License for more details.
|
14
|
-
|
15
1
|
begin
|
16
2
|
require 'serialport'
|
17
3
|
rescue Exception => e
|
data/lib/rmodbus/tcp.rb
CHANGED
@@ -1,16 +1,3 @@
|
|
1
|
-
# RModBus - free implementation of ModBus protocol on Ruby.
|
2
|
-
#
|
3
|
-
# Copyright (C) 2011 Timin Aleksey
|
4
|
-
#
|
5
|
-
# This program is free software: you can redistribute it and/or modify
|
6
|
-
# it under the terms of the GNU General Public License as published by
|
7
|
-
# the Free Software Foundation, either version 3 of the License, or
|
8
|
-
# (at your option) any later version.
|
9
|
-
#
|
10
|
-
# This program is distributed in the hope that it will be useful,
|
11
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
-
# GNU General Public License for more details.
|
14
1
|
require 'socket'
|
15
2
|
require 'timeout'
|
16
3
|
|
@@ -45,4 +32,4 @@ module ModBus
|
|
45
32
|
io
|
46
33
|
end
|
47
34
|
end
|
48
|
-
end
|
35
|
+
end
|
data/lib/rmodbus/tcp_client.rb
CHANGED
@@ -1,16 +1,3 @@
|
|
1
|
-
# RModBus - free implementation of ModBus protocol on Ruby.
|
2
|
-
#
|
3
|
-
# Copyright (C) 2008-2011 Timin Aleksey
|
4
|
-
#
|
5
|
-
# This program is free software: you can redistribute it and/or modify
|
6
|
-
# it under the terms of the GNU General Public License as published by
|
7
|
-
# the Free Software Foundation, either version 3 of the License, or
|
8
|
-
# (at your option) any later version.
|
9
|
-
#
|
10
|
-
# This program is distributed in the hope that it will be useful,
|
11
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
-
# GNU General Public License for more details.
|
14
1
|
module ModBus
|
15
2
|
# TCP client implementation
|
16
3
|
# @example
|
data/lib/rmodbus/tcp_server.rb
CHANGED
@@ -1,17 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
# it under the terms of the GNU General Public License as published by
|
7
|
-
# the Free Software Foundation, either version 3 of the License, or
|
8
|
-
# (at your option) any later version.
|
9
|
-
#
|
10
|
-
# This program is distributed in the hope that it will be useful,
|
11
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
-
# GNU General Public License for more details.
|
14
|
-
require 'gserver'
|
1
|
+
begin
|
2
|
+
require 'gserver'
|
3
|
+
rescue
|
4
|
+
warn "[WARNING] Install `gserver` gem for use TCPServer"
|
5
|
+
end
|
15
6
|
|
16
7
|
module ModBus
|
17
8
|
# TCP server implementation
|
data/lib/rmodbus/tcp_slave.rb
CHANGED
@@ -1,16 +1,3 @@
|
|
1
|
-
# RModBus - free implementation of ModBus protocol on Ruby.
|
2
|
-
#
|
3
|
-
# Copyright (C) 2011 Timin Aleksey
|
4
|
-
#
|
5
|
-
# This program is free software: you can redistribute it and/or modify
|
6
|
-
# it under the terms of the GNU General Public License as published by
|
7
|
-
# the Free Software Foundation, either version 3 of the License, or
|
8
|
-
# (at your option) any later version.
|
9
|
-
#
|
10
|
-
# This program is distributed in the hope that it will be useful,
|
11
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
-
# GNU General Public License for more details.
|
14
1
|
module ModBus
|
15
2
|
# TCP slave implementation
|
16
3
|
# @example
|
@@ -47,7 +34,7 @@ module ModBus
|
|
47
34
|
# overide method for RTU over TCP implamentaion
|
48
35
|
# @see Slave#query
|
49
36
|
def read_pdu
|
50
|
-
loop do
|
37
|
+
loop do
|
51
38
|
header = @io.read(7)
|
52
39
|
if header
|
53
40
|
trn = header[0,2].unpack('n')[0]
|
@@ -55,11 +42,11 @@ module ModBus
|
|
55
42
|
msg = @io.read(len-1)
|
56
43
|
|
57
44
|
log "Rx (#{(header + msg).size} bytes): " + logging_bytes(header + msg)
|
58
|
-
|
45
|
+
|
59
46
|
if trn == @transaction
|
60
47
|
return msg
|
61
48
|
else
|
62
|
-
log "Transaction number mismatch. A packet is ignored."
|
49
|
+
log "Transaction number mismatch. A packet is ignored."
|
63
50
|
end
|
64
51
|
end
|
65
52
|
end
|
data/lib/rmodbus/version.rb
CHANGED
@@ -1,17 +1,4 @@
|
|
1
|
-
# RModBus - free implementation of ModBus protocol on Ruby.
|
2
|
-
#
|
3
|
-
# Copyright (C) 2012-2015 Timin Aleksey
|
4
|
-
#
|
5
|
-
# This program is free software: you can redistribute it and/or modify
|
6
|
-
# it under the terms of the GNU General Public License as published by
|
7
|
-
# the Free Software Foundation, either version 3 of the License, or
|
8
|
-
# (at your option) any later version.
|
9
|
-
#
|
10
|
-
# This program is distributed in the hope that it will be useful,
|
11
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
-
# GNU General Public License for more details.
|
14
1
|
module ModBus
|
15
2
|
# Package version
|
16
|
-
VERSION = '1.3.
|
3
|
+
VERSION = '1.3.1'
|
17
4
|
end
|
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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- A.Timin, J. Sanders, K. Reynolds
|
7
|
+
- A.Timin, J. Sanders, K. Reynolds, F. Luizão
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-12-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -84,30 +84,30 @@ dependencies:
|
|
84
84
|
name: serialport
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - "
|
87
|
+
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
89
|
+
version: '1.3'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - "
|
94
|
+
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
96
|
+
version: '1.3'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: gserver
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- - "
|
101
|
+
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
103
|
+
version: '0.0'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- - "
|
108
|
+
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
110
|
+
version: '0.0'
|
111
111
|
description:
|
112
112
|
email: atimin@gmail.com
|
113
113
|
executables: []
|
@@ -162,9 +162,9 @@ files:
|
|
162
162
|
- spec/spec_helper.rb
|
163
163
|
- spec/tcp_client_spec.rb
|
164
164
|
- spec/tcp_server_spec.rb
|
165
|
-
homepage: http://
|
165
|
+
homepage: http://www.rubydoc.info/github/rmodbus/rmodbus
|
166
166
|
licenses:
|
167
|
-
-
|
167
|
+
- BSD-3-Clause
|
168
168
|
metadata: {}
|
169
169
|
post_install_message:
|
170
170
|
rdoc_options:
|