digital-transport 0.8.1 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/digital/transport/adapters/serial.rb +5 -19
- data/lib/digital/transport/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7af58d75f82ffdaf6870b242c530685e6285dc16
|
4
|
+
data.tar.gz: cefbffc637bc63cb05eeb4f5c162d5f558322693
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e1c1a80fefe85d91e10e925cf7e3dcf7202a84460513de4295a8f324d0659e7fd4126f57a2d3da797e37796025a06dbd9c02e3e025e061d992c34da5fe9e2e64
|
7
|
+
data.tar.gz: da4e1ba232ceabe3ace2fae5f576094e22249189cf9a55b4471fcc2aa8b3895767f1b3f0af1b2930f00054eb57b20ad7607a447004196319ebe13a310976f93b
|
@@ -6,17 +6,10 @@ module Digital
|
|
6
6
|
class Serial
|
7
7
|
include Digital::Transport::Errors
|
8
8
|
include Digital::Transport::Adapters::Interface
|
9
|
-
include CommPort
|
10
9
|
include Functional
|
10
|
+
include Rs232
|
11
11
|
|
12
|
-
DEFAULTS = {
|
13
|
-
timeout: 10,
|
14
|
-
baud_rate: CommPort::BAUD_115200,
|
15
|
-
data_bits: CommPort::DATA_BITS_8,
|
16
|
-
parity: CommPort::PAR_NONE,
|
17
|
-
stop_bits: CommPort::STOP_BITS_1,
|
18
|
-
flow_control: CommPort::FLOW_OFF
|
19
|
-
}.freeze
|
12
|
+
DEFAULTS = { timeout: 10 }.freeze
|
20
13
|
|
21
14
|
def initialize(port, opt = {})
|
22
15
|
@port = port.freeze
|
@@ -31,15 +24,7 @@ module Digital
|
|
31
24
|
# @see Adapters#new_serial_adapter
|
32
25
|
#
|
33
26
|
def connect
|
34
|
-
io =
|
35
|
-
io.connecting_timeout = @opts[:timeout].to_i if p.respond_to?(:connecting_timeout)
|
36
|
-
io.open
|
37
|
-
io.baud_rate = @opts[:baud_rate].to_i
|
38
|
-
io.data_bits = @opts[:data_bits].to_i
|
39
|
-
io.parity = @opts[:parity].to_i
|
40
|
-
io.stop_bits = @opts[:stop_bits].to_i
|
41
|
-
io.flow_control = @opts[:flow_control].to_i
|
42
|
-
@io = io
|
27
|
+
@io = new_serial_port(@port, @opts).tap(&:connect)
|
43
28
|
Either.right(self)
|
44
29
|
rescue Exception => ex
|
45
30
|
Either.left(ex)
|
@@ -64,7 +49,7 @@ module Digital
|
|
64
49
|
end
|
65
50
|
|
66
51
|
def open?
|
67
|
-
@io &&
|
52
|
+
@io && @io.open?
|
68
53
|
end
|
69
54
|
|
70
55
|
def read(count, blocking = false)
|
@@ -84,6 +69,7 @@ module Digital
|
|
84
69
|
end
|
85
70
|
Either.right(array.empty? ? nil : array.join)
|
86
71
|
rescue => ex
|
72
|
+
@io.close
|
87
73
|
Either.left(ex)
|
88
74
|
end
|
89
75
|
|