rmodbus 0.1.0 → 0.1.1

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.
data/AUTHORS CHANGED
@@ -1,2 +1,3 @@
1
1
  Timin Aleksey
2
+
2
3
  Dilshod Samatov
data/CHANGES ADDED
@@ -0,0 +1,2 @@
1
+ 2008-25-01 Release-0.1.1
2
+ - fixed bug in function "read discrete inputs (0x2)" of ModBus client
data/LICENSE CHANGED
@@ -1,4 +1,5 @@
1
1
  GNU GENERAL PUBLIC LICENSE
2
+
2
3
  Version 3, 29 June 2007
3
4
 
4
5
  Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
data/README CHANGED
@@ -5,7 +5,15 @@
5
5
  == Feature
6
6
 
7
7
  * Client ModBus-TCP
8
- * Support functions: 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0xf, 0x10
8
+ * Support functions:
9
+ * 01 (0x01) Read Coils
10
+ * 02 (0x02) Read Discrete Inputs
11
+ * 03 (0x03) Read Holding Registers
12
+ * 04 (0x04) Read Input Registers
13
+ * 05 (0x05) Write Single Coil
14
+ * 06 (0x06) Write Single Register
15
+ * 15 (0x0F) Write Multiple Coils
16
+ * 16 (0x10) Write Multiple registers
9
17
 
10
18
  == Installation
11
19
 
@@ -32,6 +40,12 @@ or
32
40
 
33
41
  $ svn checkout http://rubyforge.org/var/svn/rmodbus/trunk
34
42
 
43
+ == Reference
44
+
45
+ RModBus project: http://rubyforge.org/projects/rmodbus
46
+
47
+ ModBus community: http://www.modbus-ida.org
48
+
35
49
 
36
50
 
37
51
 
data/lib/rmodbus/adu.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  # RModBus - free implementation of ModBus protocol on Ruby.
2
+ #
2
3
  # Copyright (C) 2008 Timin Aleksey
4
+ #
3
5
  # This program is free software: you can redistribute it and/or modify
4
6
  # it under the terms of the GNU General Public License as published by
5
7
  # the Free Software Foundation, either version 3 of the License, or
@@ -1,5 +1,7 @@
1
1
  # RModBus - free implementation of ModBus protocol on Ruby.
2
+ #
2
3
  # Copyright (C) 2008 Timin Aleksey
4
+ #
3
5
  # This program is free software: you can redistribute it and/or modify
4
6
  # it under the terms of the GNU General Public License as published by
5
7
  # the Free Software Foundation, either version 3 of the License, or
@@ -58,22 +60,39 @@ module ModBus
58
60
 
59
61
  include Errors
60
62
 
61
- def read_coils(addr, nreg)
62
- query("\x1" + addr.to_bytes + nreg.to_bytes).to_array_bit[0..nreg-1]
63
+ # Read value *ncoils* coils starting with *addr*
64
+ #
65
+ # Return array of their values
66
+ def read_coils(addr, ncoils)
67
+ query("\x1" + addr.to_bytes + ncoils.to_bytes).to_array_bit[0..ncoils-1]
63
68
  end
64
69
 
65
- def read_discret_inputs(addr, nreg)
66
- query("\x2" + addr.to_bytes + nreg.to_bytes).to_array_bit
70
+ # Read value *ncoils* discrete inputs starting with *addr*
71
+ #
72
+ # Return array of their values
73
+ def read_discret_inputs(addr, ncoils)
74
+ query("\x2" + addr.to_bytes + ncoils.to_bytes).to_array_bit[0..ncoils-1]
67
75
  end
68
76
 
77
+ # Read value *nreg* holding registers starting with *addr*
78
+ #
79
+ # Return array of their values
69
80
  def read_holding_registers(addr, nreg)
70
81
  query("\x3" + addr.to_bytes + nreg.to_bytes).to_array_int16
71
82
  end
72
83
 
84
+ # Read value *nreg* input registers starting with *addr*
85
+ #
86
+ # Return array of their values
73
87
  def read_input_registers(addr, nreg)
74
88
  query("\x4" + addr.to_bytes + nreg.to_bytes).to_array_int16
75
89
  end
76
90
 
91
+ # Write *val* in *addr* coil
92
+ #
93
+ # if *val* lager 0 write 1
94
+ #
95
+ # Return self
77
96
  def write_single_coil(addr, val)
78
97
  if val == 0
79
98
  query("\x5" + addr.to_bytes + 0.to_bytes)
@@ -83,11 +102,19 @@ module ModBus
83
102
  self
84
103
  end
85
104
 
105
+ # Write *val* in *addr* register
106
+ #
107
+ # Return self
86
108
  def write_single_register(addr, val)
87
109
  query("\x6" + addr.to_bytes + val.to_bytes)
88
110
  self
89
111
  end
90
112
 
113
+ # Write *val* in coils starting with *addr*
114
+ #
115
+ # *val* it is array of bits
116
+ #
117
+ # Return self
91
118
  def write_multiple_coils(addr, val)
92
119
  nbyte = ((val.size-1) >> 3) + 1
93
120
  sum = 0
@@ -106,6 +133,11 @@ module ModBus
106
133
  self
107
134
  end
108
135
 
136
+ # Write *val* in registers starting with *addr*
137
+ #
138
+ # *val* it is array of integer
139
+ #
140
+ # Return self
109
141
  def write_multiple_registers(addr, val)
110
142
  s_val = ""
111
143
  val.each do |reg|
@@ -116,6 +148,13 @@ module ModBus
116
148
  self
117
149
  end
118
150
 
151
+ # Write *current value & and_mask | or mask in *addr* register
152
+ #
153
+ # Return self
154
+ def mask_write_register(addr, and_mask, or_mask)
155
+ query("\x16" + addr.to_bytes + and_mask.to_bytes + or_mask.to_bytes)
156
+ self
157
+ end
119
158
 
120
159
  def query(pdu)
121
160
  send_pdu(pdu)
@@ -146,12 +185,14 @@ module ModBus
146
185
  end
147
186
  pdu[2..-1]
148
187
  end
149
- end
150
188
 
151
- protected
152
- def send_pdu(pdu)
153
- end
189
+ protected
190
+ def send_pdu(pdu)
191
+ end
192
+
193
+ def read_pdu
194
+ end
154
195
 
155
- def read_pdu
156
196
  end
197
+
157
198
  end
@@ -1,5 +1,7 @@
1
1
  # RModBus - free implementation of ModBus protocol on Ruby.
2
+ #
2
3
  # Copyright (C) 2008 Timin Aleksey
4
+ #
3
5
  # This program is free software: you can redistribute it and/or modify
4
6
  # it under the terms of the GNU General Public License as published by
5
7
  # the Free Software Foundation, either version 3 of the License, or
@@ -1,5 +1,7 @@
1
1
  # RModBus - free implementation of ModBus protocol on Ruby.
2
+ #
2
3
  # Copyright (C) 2008 Timin Aleksey
4
+ #
3
5
  # This program is free software: you can redistribute it and/or modify
4
6
  # it under the terms of the GNU General Public License as published by
5
7
  # the Free Software Foundation, either version 3 of the License, or
@@ -17,10 +19,12 @@ require 'rmodbus/adu'
17
19
 
18
20
  module ModBus
19
21
 
22
+ # Implementation clients(master) ModBusTCP
20
23
  class TCPClient < Client
21
24
 
22
25
  include Timeout
23
26
 
27
+ # Connect with a ModBus server
24
28
  def initialize(ipaddr, port = 502, slaveaddr = 1)
25
29
  timeout(1) do
26
30
  @sock = TCPSocket.new(ipaddr, port)
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rmodbus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
- - A.Timin
7
+ - A.Timin, D.Samatov
8
8
  autorequire: rmodbus
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-01-11 00:00:00 +05:00
12
+ date: 2008-01-25 00:00:00 +05:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -23,6 +23,7 @@ extra_rdoc_files:
23
23
  - README
24
24
  - AUTHORS
25
25
  - LICENSE
26
+ - CHANGES
26
27
  files:
27
28
  - lib/rmodbus/exceptions.rb
28
29
  - lib/rmodbus/tcp_client.rb
@@ -32,6 +33,7 @@ files:
32
33
  - README
33
34
  - AUTHORS
34
35
  - LICENSE
36
+ - CHANGES
35
37
  has_rdoc: true
36
38
  homepage:
37
39
  post_install_message: