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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2f35c23c610072572e035350b54c7040e43a63a7fff03e6545975c479ee5a230
4
- data.tar.gz: f9077c4ded62f71b8531102099a826bb93866a08d6035bd8e96626e986f867a7
3
+ metadata.gz: 508b6323047d55f073eb5d46d05919284b5d09c9c5cdf417df67a60642d1c097
4
+ data.tar.gz: '017940d773f256fec40e4fd0ac70a6efe491354401a20c9b23a99a47fe0b66c8'
5
5
  SHA512:
6
- metadata.gz: 5934dfc5bf9a828ec264336a93bcd15289d7144032b6b054d3635c1dd218d718d442472673a2fc6b52c823786d16bea09771096d31a74bacaa18f53679276b67
7
- data.tar.gz: 2eb98b439a85c974a27aaf619fff06b0303bbcdf66e24c4fc870d2e37af1c0b995f18a1a67936079710bdbdba41a0ece4188acb0a3b1daf294195c6fd6fc0aae
6
+ metadata.gz: f73eca7c987f0ae58e02ff3e0b4526fce468c75d19cf16f45f0d80cff5655b5b7b6536a020fc69be177ac47e900df18737aef637d63a55a128b2b02ee63e7da0
7
+ data.tar.gz: 8595aa8ca039870ec747a1646a36923ee8558f98099ebc593dae70c9df435402fd749019a6b539e0017e4ed0d4879b3196aa38f1c384f55fc668cf10a09380e7
data/CHANGES.md ADDED
@@ -0,0 +1,7 @@
1
+ # CHANGES
2
+
3
+ ## 0.1.2
4
+
5
+ - Be able to access the type value that you want to get.
6
+ - Use to_xxx for reading from the PLC.
7
+ - Use as_xxx for writing to the PLC.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- plc_access (0.1.0)
4
+ plc_access (0.1.1)
5
5
  serialport (~> 1.3, >= 1.3.1)
6
6
 
7
7
  GEM
@@ -50,4 +50,4 @@ DEPENDENCIES
50
50
  test-unit-rr
51
51
 
52
52
  BUNDLED WITH
53
- 2.1.4
53
+ 2.4.22
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"] # => 123
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"] # => 123
53
+ plc["DM0"] # => 123
54
54
  plc["DM0", 10] = [0, 1, 2, ..., 9]
55
- plc["DM0".."DM9"] => [0, 1, 2, ..., 9]
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PlcAccess
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.2'
5
5
  end
data/lib/plc_access.rb CHANGED
@@ -28,3 +28,4 @@ $LOAD_PATH.unshift dir unless $LOAD_PATH.include? dir
28
28
 
29
29
  require 'plc_access/protocol/protocol'
30
30
  require 'plc_access/version'
31
+ require 'plc_access/act_as_type'
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.0
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-10-26 00:00:00.000000000 Z
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.3.26
92
+ rubygems_version: 3.4.22
91
93
  signing_key:
92
94
  specification_version: 4
93
95
  summary: The PlcAccess communicates with PLCs.