Class: SerialProtocol::LineBased
- Inherits:
-
Object
- Object
- SerialProtocol::LineBased
- Defined in:
- lib/serial_interface.rb
Instance Method Summary collapse
- #add_char_to_packet(char) ⇒ Object
-
#initialize(send_callback, receive_callback, options = {}) ⇒ LineBased
constructor
A new instance of LineBased.
- #send_packet(data, options = {}) ⇒ Object
Constructor Details
#initialize(send_callback, receive_callback, options = {}) ⇒ LineBased
Returns a new instance of LineBased.
205 206 207 208 |
# File 'lib/serial_interface.rb', line 205 def initialize(send_callback, receive_callback, = {}) @send_callback, @receive_callback = send_callback, receive_callback @packet_buffer = "" end |
Instance Method Details
#add_char_to_packet(char) ⇒ Object
210 211 212 213 214 215 216 217 |
# File 'lib/serial_interface.rb', line 210 def add_char_to_packet(char) if /\n/ === char.chr @receive_callback.call(@receive_buffer) @packet_buffer = "" else @packet_buffer << char end end |
#send_packet(data, options = {}) ⇒ Object
219 220 221 |
# File 'lib/serial_interface.rb', line 219 def send_packet(data, = {}) @send_callback.call(data + "\n") end |