rs_232 3.0.0.pre2 → 3.0.0.pre3

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
  SHA1:
3
- metadata.gz: 5bcb80fd72cfb4f47935134fbe73abc7594b289c
4
- data.tar.gz: 949a14cb21434e5a3af56701e265f44c06a50966
3
+ metadata.gz: 5840e52db6045e90f747a253b5ffac3e35451982
4
+ data.tar.gz: 4ab12360c4459dc9559d2b49edbb211cce7a54e5
5
5
  SHA512:
6
- metadata.gz: 01e9454ede82eb0905af93a07e30783917e003f552e99f5bf5cedb1d253ab8e85c17bc5c684e46c5221bd25c91bd983ef13162d538ca4e3a94428b94f09ae07c
7
- data.tar.gz: ae532ffee6ab6490641e6cbb32568ce0a357b30135980f6ddebe962a9751f19f4563ddccb4049a7c188bb1a6a6b6195d5516302e993bee28facda3203830ef49
6
+ metadata.gz: 3e44d1e9b4f2b54140b051a3faa776d3b677332b416a865e8b485d5cb992682b720bb16329848ea958f1780b43e8d6dc3ba59a0f361f947647ac81b8f7dd2390
7
+ data.tar.gz: 9bb919bdf5c099e25bd5b5711a7d9af244c1ddf3b01c6b833eabbc115b68e255cc8c1e6807af8b21a640a162bbbc5b2da679afecb4f8bc3bc1163e6ccae1f150
@@ -291,7 +291,7 @@ VALUE openIO(VALUE self)
291
291
  } else
292
292
  {
293
293
  port->status = PORT_CLOSED;
294
- rb_raise(rb_eRuntimeError, "Unable to open comport: `%s`", port->settings.ComPort);
294
+ rb_raise(rb_eIOError, "Unable to open comport: `%s`", port->settings.ComPort);
295
295
  }
296
296
 
297
297
  return self;
@@ -77,7 +77,7 @@ void updateSettings(PortDescriptor *port)
77
77
  {
78
78
 
79
79
  if (PORT_OPEN != port->status)
80
- rb_raise(rb_eRuntimeError, "Can not set due to comport is not open, status: %d\n", port->status);
80
+ rb_raise(rb_eIOError, "Can not set due to comport is not open, status: %d\n", port->status);
81
81
 
82
82
 
83
83
  if (port->toBeUpdated & T_BaudRate)
@@ -230,7 +230,7 @@ VALUE openIO(VALUE self)
230
230
  {
231
231
 
232
232
  port->status = PORT_CLOSED;
233
- rb_raise(rb_eRuntimeError, "Unable to open comport: `%s`", port->settings.ComPort);
233
+ rb_raise(rb_eIOError, "Unable to open comport: `%s`", port->settings.ComPort);
234
234
 
235
235
  } else
236
236
  {
data/lib/rs_232.rb CHANGED
@@ -7,17 +7,27 @@ module Rs232
7
7
  #
8
8
  # @example
9
9
  #
10
- # > port = Rs232.new('/dev/tty.ACM0', baud_rate: 9600)
11
- # #=> <#Rs232::Impl @port='/dev/tty.ACM0'>
10
+ # > include Rs232
11
+ # > port = new_serial_port('/dev/tty.ACM0', baud_rate: 9600)
12
+ # #=> #<Rs232::Impl @port='/dev/tty.ACM0'>
12
13
  # > port.open?
13
14
  # #=> false
14
- # > port.connect
15
- # #=> <#Rs232::Impl @port='/dev/tty.ACM0'>
16
- # port.pending_bytes
15
+ # > port.connect # rasing IOError in case of port couldn't be opened.
16
+ # #=> #<Rs232::Impl @port='/dev/tty.ACM0'>
17
+ # > port.pending_bytes
17
18
  # #=> 15
18
- # port.read(15)
19
+ # > port.read(15)
19
20
  # #=> 'Hello, World!!!'
21
+ # > port.write("Hi")
22
+ # #=> 2
23
+ # > port.close
24
+ # #=> true
25
+ # > port.open?
26
+ # #=> false
20
27
  #
28
+ # @param [String] port name
29
+ # @param [Hash] opts with such keys as: baud_rate, parity, data_bits, stop_bits, flow_control, timeout
30
+ # @param [Proc] block is a function to apply on constructor finish
21
31
  def new_serial_port(port, opts = {}, &block)
22
32
  Impl.new(port, opts, &block)
23
33
  end
@@ -46,7 +56,6 @@ module Rs232
46
56
  :read,
47
57
  :write,
48
58
  :flush,
49
- :close,
50
59
  :open?,
51
60
  :set_rts,
52
61
  :set_dtr
@@ -58,7 +67,8 @@ module Rs232
58
67
  yield self if block_given?
59
68
  end
60
69
 
61
- # @raise RuntimeError in case of open error
70
+ # @raise IOError in case of port was not open.
71
+ # @return [Impl] instance
62
72
  def connect
63
73
  return self if open?
64
74
  @impl.open.tap do |io|
@@ -72,6 +82,18 @@ module Rs232
72
82
  self
73
83
  end
74
84
 
85
+ # @return [Boolean]
86
+ def close
87
+ return !open? unless open?
88
+ 0 == @impl.close
89
+ end
90
+
91
+ # @return [Fixnum] representing count of bytes in the buffer
92
+ def pending_bytes
93
+ @impl.available?
94
+ end
95
+
96
+ # @return [Hash] of configurations on the OS side.
75
97
  def settings
76
98
  {}.tap do |o|
77
99
  o[:baud_rate] = @impl.baud_rate
@@ -83,15 +105,6 @@ module Rs232
83
105
  o[:line_status] = @impl.line_status
84
106
  end.freeze
85
107
  end
86
-
87
- def open?
88
- @impl.open?
89
- end
90
-
91
- def close
92
- return !open unless open?
93
- 0 == @impl.close
94
- end
95
108
  end
96
109
 
97
110
  private_constant :Impl
@@ -1,3 +1,3 @@
1
1
  module Rs232
2
- VERSION = '3.0.0.pre2'.freeze
2
+ VERSION = '3.0.0.pre3'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rs_232
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0.pre2
4
+ version: 3.0.0.pre3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roman Lishtaba
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-22 00:00:00.000000000 Z
11
+ date: 2016-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler