plc_access 0.1.0 → 0.1.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/CHANGES.md +7 -0
- data/Gemfile.lock +2 -2
- data/README.md +29 -4
- data/lib/plc_access/act_as_type.rb +70 -0
- data/lib/plc_access/version.rb +1 -1
- data/lib/plc_access.rb +1 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 508b6323047d55f073eb5d46d05919284b5d09c9c5cdf417df67a60642d1c097
|
4
|
+
data.tar.gz: '017940d773f256fec40e4fd0ac70a6efe491354401a20c9b23a99a47fe0b66c8'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f73eca7c987f0ae58e02ff3e0b4526fce468c75d19cf16f45f0d80cff5655b5b7b6536a020fc69be177ac47e900df18737aef637d63a55a128b2b02ee63e7da0
|
7
|
+
data.tar.gz: 8595aa8ca039870ec747a1646a36923ee8558f98099ebc593dae70c9df435402fd749019a6b539e0017e4ed0d4879b3196aa38f1c384f55fc668cf10a09380e7
|
data/CHANGES.md
ADDED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -33,9 +33,9 @@ plc["M0"] # => true
|
|
33
33
|
plc["M0", 10] # => [true, false, ..., false]
|
34
34
|
|
35
35
|
plc["D0"] = 123
|
36
|
-
plc["D0"]
|
36
|
+
plc["D0"] # => 123
|
37
37
|
plc["D0", 10] = [0, 1, 2, ..., 9]
|
38
|
-
plc["D0".."D9"] => [0, 1, 2, ..., 9]
|
38
|
+
plc["D0".."D9"] # => [0, 1, 2, ..., 9]
|
39
39
|
```
|
40
40
|
|
41
41
|
Keyence PLCs:
|
@@ -50,9 +50,34 @@ plc["MR0"] # => true
|
|
50
50
|
plc["MR0", 10] # => [true, false, ..., false]
|
51
51
|
|
52
52
|
plc["DM0"] = 123
|
53
|
-
plc["DM0"]
|
53
|
+
plc["DM0"] # => 123
|
54
54
|
plc["DM0", 10] = [0, 1, 2, ..., 9]
|
55
|
-
plc["DM0".."DM9"]
|
55
|
+
plc["DM0".."DM9"] # => [0, 1, 2, ..., 9]
|
56
|
+
```
|
57
|
+
|
58
|
+
### Types
|
59
|
+
|
60
|
+
If you want to read or write the value as a specified type, use to_ushort, to_short, to_uint, to_int, and to_float for reading and as_ushort, as_short, as_uint, as_int, and as_float for writing.
|
61
|
+
And don't forget to put the line ```using PlcAccess::ActAsType``` before using it.
|
62
|
+
|
63
|
+
```
|
64
|
+
using PlcAccess::ActAsType
|
65
|
+
|
66
|
+
# [0, 1, 2, 3, 4] is treated as five int elements.
|
67
|
+
# #as_int converts int to two ushort elements. So it gets the total as ten ushort elements.
|
68
|
+
|
69
|
+
plc["DM0", 10] = [0, 1, 2, 3, 4].as_int # => [0, 0, 1, 0, 2, 0, 3, 0, 4, 0]
|
70
|
+
|
71
|
+
# plc["MR0", 10] returns as ten ushort elements.
|
72
|
+
# #to_int converts two ushort values to one int value. So it gets the total as five int elements.
|
73
|
+
|
74
|
+
plc["MR0", 10].to_int # => [0, 1, 2, 3, 4]
|
75
|
+
|
76
|
+
# Set string to data memory (ten wors from DM0) as ushort values.
|
77
|
+
plc["DM0", 10] = "PLC Access".as_ushort()
|
78
|
+
# Get string from data memory (ten wors from DM0).
|
79
|
+
plc["DM0", 10].to_string()
|
80
|
+
|
56
81
|
```
|
57
82
|
|
58
83
|
## Contributing
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module PlcAccess
|
2
|
+
|
3
|
+
module ActAsType
|
4
|
+
refine Array do
|
5
|
+
|
6
|
+
def to_ushort
|
7
|
+
pack("S*").unpack("S*")
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_short
|
11
|
+
pack("S*").unpack("s*")
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_uint
|
15
|
+
pack("S*").unpack("L*")
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_int
|
19
|
+
pack("S*").unpack("l*")
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_float
|
23
|
+
pack("S*").unpack("f*")
|
24
|
+
end
|
25
|
+
|
26
|
+
def as_ushort
|
27
|
+
pack("S*").unpack("S*")
|
28
|
+
end
|
29
|
+
|
30
|
+
def as_short
|
31
|
+
pack("s*").unpack("S*")
|
32
|
+
end
|
33
|
+
|
34
|
+
def as_uint
|
35
|
+
pack("L*").unpack("S*")
|
36
|
+
end
|
37
|
+
|
38
|
+
def as_int
|
39
|
+
pack("l*").unpack("S*")
|
40
|
+
end
|
41
|
+
|
42
|
+
def as_float
|
43
|
+
pack("f*").unpack("S*")
|
44
|
+
end
|
45
|
+
|
46
|
+
def as_string length=nil, encoding=Encoding::UTF_8
|
47
|
+
s = pack("v*")
|
48
|
+
if length
|
49
|
+
s = s[0, length].delete("\000")
|
50
|
+
end
|
51
|
+
s.force_encoding(encoding).encode(Encoding::UTF_8)
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
refine String do
|
57
|
+
|
58
|
+
def to_ushort length=nil, encoding=Encoding::UTF_8
|
59
|
+
a = self.encode(encoding).unpack("v*")
|
60
|
+
return a unless length
|
61
|
+
|
62
|
+
s = (length + 1) / 2
|
63
|
+
a += [0] * [s - a.length, 0].max
|
64
|
+
a[0, s]
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
data/lib/plc_access/version.rb
CHANGED
data/lib/plc_access.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: plc_access
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Katsuyoshi Ito
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-12-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: serialport
|
@@ -40,6 +40,7 @@ extra_rdoc_files: []
|
|
40
40
|
files:
|
41
41
|
- ".gitignore"
|
42
42
|
- ".travis.yml"
|
43
|
+
- CHANGES.md
|
43
44
|
- CODE_OF_CONDUCT.md
|
44
45
|
- Gemfile
|
45
46
|
- Gemfile.lock
|
@@ -49,6 +50,7 @@ files:
|
|
49
50
|
- bin/console
|
50
51
|
- bin/setup
|
51
52
|
- lib/plc_access.rb
|
53
|
+
- lib/plc_access/act_as_type.rb
|
52
54
|
- lib/plc_access/protocol/keyence/keyence.rb
|
53
55
|
- lib/plc_access/protocol/keyence/kv_device.rb
|
54
56
|
- lib/plc_access/protocol/keyence/kv_protocol.rb
|
@@ -87,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
87
89
|
- !ruby/object:Gem::Version
|
88
90
|
version: '0'
|
89
91
|
requirements: []
|
90
|
-
rubygems_version: 3.
|
92
|
+
rubygems_version: 3.4.22
|
91
93
|
signing_key:
|
92
94
|
specification_version: 4
|
93
95
|
summary: The PlcAccess communicates with PLCs.
|