plc_access 0.2.0 → 0.2.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.
- checksums.yaml +4 -4
- data/CHANGES.md +7 -0
- data/Gemfile.lock +2 -2
- data/README.md +11 -4
- data/lib/plc_access/act_as_type.rb +23 -5
- data/lib/plc_access/protocol/mitsubishi/fx_protocol.rb +4 -0
- data/lib/plc_access/protocol/mitsubishi/mc_protocol.rb +4 -0
- data/lib/plc_access/protocol/mitsubishi/qdevice.rb +4 -0
- data/lib/plc_access/protocol/plc_device.rb +8 -2
- data/lib/plc_access/protocol/plc_share/plc_share_protocol.rb +9 -0
- data/lib/plc_access/protocol/protocol.rb +7 -2
- data/lib/plc_access/version.rb +1 -1
- metadata +3 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c7944febc355a406f20d64952237fb1cb58d718c079d9b1743535ce495d5a153
|
|
4
|
+
data.tar.gz: d76735035b4e7749ef4beb234b5cad4392090fe892ae6321a3ae24e14a54cc25
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a8a256b8f7e4cf5d3a7e1cbf6d7d21168ceaccb0927279c1427f293bb603622b648ae1d660649262d10204f8146f926d9f7ec6cf8ec38a2ae6089c475b0f4d39
|
|
7
|
+
data.tar.gz: 7d5e7fc1ca634bb9397f4f752b91efa4eecdc3535db7915e01f3e3a0f9b06b57ec250f8d69c4eafba5afbc313d30d17b2f1db629eaef66b15348dbf3da9ea6fa
|
data/CHANGES.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# CHANGES
|
|
2
2
|
|
|
3
|
+
## 0.2.1
|
|
4
|
+
|
|
5
|
+
- Add byte order support for string/ushort conversion per PLC type (Mitsubishi: little-endian, Keyence/Omron: big-endian)
|
|
6
|
+
- Accept plc object in as_ushort/to_string to auto-detect byte order
|
|
7
|
+
- Allow Protocol#[]= to pad with zeros or truncate when array size differs from count
|
|
8
|
+
- Allow Protocol#[]= to accept arrays without specifying count
|
|
9
|
+
|
|
3
10
|
## 0.1.3
|
|
4
11
|
|
|
5
12
|
- Rename Array#as_string to Array#to_string
|
data/Gemfile.lock
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
plc_access (0.1
|
|
4
|
+
plc_access (0.2.1)
|
|
5
5
|
serialport (~> 1.3, >= 1.3.1)
|
|
6
6
|
|
|
7
7
|
GEM
|
|
8
8
|
remote: https://rubygems.org/
|
|
9
9
|
specs:
|
|
10
10
|
ast (2.4.2)
|
|
11
|
-
json (2.
|
|
11
|
+
json (2.18.1)
|
|
12
12
|
language_server-protocol (3.17.0.4)
|
|
13
13
|
lint_roller (1.1.0)
|
|
14
14
|
parallel (1.26.3)
|
data/README.md
CHANGED
|
@@ -73,10 +73,17 @@ plc["DM0", 10] = [0, 1, 2, 3, 4].as_int # => [0, 0, 1, 0, 2, 0, 3, 0, 4, 0]
|
|
|
73
73
|
|
|
74
74
|
plc["MR0", 10].to_int # => [0, 1, 2, 3, 4]
|
|
75
75
|
|
|
76
|
-
# Set string to data memory (ten
|
|
77
|
-
|
|
78
|
-
#
|
|
79
|
-
plc
|
|
76
|
+
# Set string to data memory (ten words from DM0) as ushort values.
|
|
77
|
+
# The byte order for string conversion differs by PLC type
|
|
78
|
+
# (e.g., Mitsubishi uses little-endian, Keyence/Omron use big-endian).
|
|
79
|
+
# Pass plc to automatically use the correct byte order.
|
|
80
|
+
plc["DM0", 10] = "PLC Access".as_ushort(plc)
|
|
81
|
+
# Get string from data memory (ten words from DM0).
|
|
82
|
+
plc["DM0", 10].to_string(plc)
|
|
83
|
+
|
|
84
|
+
# You can also specify the length and plc together.
|
|
85
|
+
plc["DM0", 5] = "PLC Access".as_ushort(10, plc)
|
|
86
|
+
plc["DM0", 5].to_string(10, plc)
|
|
80
87
|
|
|
81
88
|
```
|
|
82
89
|
|
|
@@ -43,8 +43,17 @@ module ActAsType
|
|
|
43
43
|
pack("f*").unpack("S*")
|
|
44
44
|
end
|
|
45
45
|
|
|
46
|
-
def to_string length=nil, encoding=Encoding::UTF_8
|
|
47
|
-
|
|
46
|
+
def to_string length=nil, encoding=Encoding::UTF_8, endian: :little
|
|
47
|
+
if length.respond_to?(:string_endian)
|
|
48
|
+
endian = length.string_endian
|
|
49
|
+
length = nil
|
|
50
|
+
end
|
|
51
|
+
if encoding.respond_to?(:string_endian)
|
|
52
|
+
endian = encoding.string_endian
|
|
53
|
+
encoding = Encoding::UTF_8
|
|
54
|
+
end
|
|
55
|
+
format = endian == :big ? "n*" : "v*"
|
|
56
|
+
s = pack(format)
|
|
48
57
|
if length
|
|
49
58
|
s = s[0, length].delete("\000")
|
|
50
59
|
end
|
|
@@ -55,10 +64,19 @@ module ActAsType
|
|
|
55
64
|
|
|
56
65
|
refine String do
|
|
57
66
|
|
|
58
|
-
def as_ushort length=nil, encoding=Encoding::UTF_8
|
|
59
|
-
|
|
67
|
+
def as_ushort length=nil, encoding=Encoding::UTF_8, endian: :little
|
|
68
|
+
if length.respond_to?(:string_endian)
|
|
69
|
+
endian = length.string_endian
|
|
70
|
+
length = nil
|
|
71
|
+
end
|
|
72
|
+
if encoding.respond_to?(:string_endian)
|
|
73
|
+
endian = encoding.string_endian
|
|
74
|
+
encoding = Encoding::UTF_8
|
|
75
|
+
end
|
|
76
|
+
format = endian == :big ? "n*" : "v*"
|
|
77
|
+
a = self.encode(encoding).unpack(format)
|
|
60
78
|
return a unless length
|
|
61
|
-
|
|
79
|
+
|
|
62
80
|
s = (length + 1) / 2
|
|
63
81
|
a += [0] * [s - a.length, 0].max
|
|
64
82
|
a[0, s]
|
|
@@ -147,6 +147,10 @@ module PlcAccess
|
|
|
147
147
|
alias word value
|
|
148
148
|
alias word= value=
|
|
149
149
|
|
|
150
|
+
def string_endian
|
|
151
|
+
:big
|
|
152
|
+
end
|
|
153
|
+
|
|
150
154
|
def text(len = 8)
|
|
151
155
|
n = (len + 1) / 2
|
|
152
156
|
d = self
|
|
@@ -155,14 +159,16 @@ module PlcAccess
|
|
|
155
159
|
a << d.value
|
|
156
160
|
d = d.next_device
|
|
157
161
|
end
|
|
158
|
-
|
|
162
|
+
format = string_endian == :big ? 'n*' : 'v*'
|
|
163
|
+
s = a.pack(format).split("\x00").first
|
|
159
164
|
s ? s[0, len] : ''
|
|
160
165
|
end
|
|
161
166
|
|
|
162
167
|
def set_text(value, len = 8)
|
|
163
168
|
value = value[0, len]
|
|
164
169
|
value << "\00" unless value.length.even?
|
|
165
|
-
|
|
170
|
+
format = string_endian == :big ? 'n*' : 'v*'
|
|
171
|
+
a = value.unpack(format)
|
|
166
172
|
d = self
|
|
167
173
|
a.each do |v|
|
|
168
174
|
d.value = v
|
|
@@ -58,6 +58,10 @@ module PlcAccess
|
|
|
58
58
|
|
|
59
59
|
TIMEOUT = 1.0
|
|
60
60
|
|
|
61
|
+
def string_endian
|
|
62
|
+
:big
|
|
63
|
+
end
|
|
64
|
+
|
|
61
65
|
# abstract methods
|
|
62
66
|
|
|
63
67
|
def open; end
|
|
@@ -169,7 +173,7 @@ module PlcAccess
|
|
|
169
173
|
v = [v] unless v.is_a? Array
|
|
170
174
|
case args[0]
|
|
171
175
|
when String
|
|
172
|
-
self[args[0],
|
|
176
|
+
self[args[0], v.size] = v
|
|
173
177
|
when Range
|
|
174
178
|
self[args[0].first, args[0].count] = v
|
|
175
179
|
else
|
|
@@ -181,7 +185,8 @@ module PlcAccess
|
|
|
181
185
|
c = args[1]
|
|
182
186
|
values = args[2]
|
|
183
187
|
values = [values] unless values.is_a? Array
|
|
184
|
-
|
|
188
|
+
values += [0] * (c - values.size) if values.size < c
|
|
189
|
+
values = values[0, c] if values.size > c
|
|
185
190
|
|
|
186
191
|
a = []
|
|
187
192
|
if d.bit_device?
|
data/lib/plc_access/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: plc_access
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Katsuyoshi Ito
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: exe
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 2026-02-14 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: serialport
|
|
@@ -78,7 +77,6 @@ metadata:
|
|
|
78
77
|
homepage_uri: https://github.com/ito-soft-design/plc_access
|
|
79
78
|
source_code_uri: https://github.com/ito-soft-design/plc_access
|
|
80
79
|
changelog_uri: https://github.com/ito-soft-design/plc_access/CHANGES.md
|
|
81
|
-
post_install_message:
|
|
82
80
|
rdoc_options: []
|
|
83
81
|
require_paths:
|
|
84
82
|
- lib
|
|
@@ -93,8 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
93
91
|
- !ruby/object:Gem::Version
|
|
94
92
|
version: '0'
|
|
95
93
|
requirements: []
|
|
96
|
-
rubygems_version: 3.
|
|
97
|
-
signing_key:
|
|
94
|
+
rubygems_version: 3.6.5
|
|
98
95
|
specification_version: 4
|
|
99
96
|
summary: The PlcAccess communicates with PLCs.
|
|
100
97
|
test_files: []
|