Class: OpenC3::SerialInterface
- Inherits:
-
StreamInterface
- Object
- Interface
- StreamInterface
- OpenC3::SerialInterface
- Defined in:
- lib/openc3/interfaces/serial_interface.rb
Overview
Provides a base class for interfaces that use serial ports
Constant Summary
Constants included from Api
Api::DELAY_METRICS, Api::DURATION_METRICS, Api::SUBSCRIPTION_DELIMITER, Api::SUM_METRICS
Constants included from ApiShared
ApiShared::DEFAULT_TLM_POLLING_RATE
Constants included from Extract
Extract::SCANNING_REGULAR_EXPRESSION
Instance Attribute Summary
Attributes inherited from StreamInterface
Attributes inherited from Interface
#auto_reconnect, #bytes_read, #bytes_written, #cmd_target_enabled, #cmd_target_names, #config_params, #connect_on_startup, #disable_disconnect, #interfaces, #name, #num_clients, #options, #protocol_info, #read_count, #read_protocols, #read_queue_size, #read_raw_data, #read_raw_data_time, #reconnect_delay, #routers, #save_raw_data, #scheduler, #secrets, #state, #stream_log_pair, #target_names, #tlm_target_enabled, #tlm_target_names, #write_count, #write_protocols, #write_queue_size, #written_raw_data, #written_raw_data_time
Instance Method Summary collapse
-
#connect ⇒ Object
Creates a new SerialStream using the parameters passed in the constructor.
- #connection_string ⇒ Object
- #details ⇒ Object
-
#initialize(write_port_name, read_port_name, baud_rate, parity, stop_bits, write_timeout, read_timeout, protocol_type = nil, *protocol_args) ⇒ SerialInterface
constructor
Creates a serial interface which uses the specified stream protocol.
-
#set_option(option_name, option_values) ⇒ Object
Supported Options FLOW_CONTROL - Flow control method NONE or RTSCTS.
Methods inherited from StreamInterface
#connected?, #disconnect, #read_interface, #write_interface
Methods inherited from Interface
#_write, #add_protocol, #as_json, #connected?, #convert_data_to_packet, #convert_packet_to_data, #copy_to, #disconnect, #interface_cmd, #post_connect, #protocol_cmd, #read, #read_allowed?, #read_interface, #read_interface_base, #start_raw_logging, #stop_raw_logging, #write, #write_allowed?, #write_interface, #write_interface_base, #write_raw, #write_raw_allowed?
Methods included from Api
#_cmd_implementation, #_extract_target_command_names, #_extract_target_command_parameter_names, #_extract_target_packet_item_names, #_extract_target_packet_names, #_get_and_set_cmd, #_get_item, #_limits_group, #_set_tlm_process_args, #_tlm_process_args, #_validate_tlm_type, #build_cmd, #cmd, #cmd_no_checks, #cmd_no_hazardous_check, #cmd_no_range_check, #cmd_raw, #cmd_raw_no_checks, #cmd_raw_no_hazardous_check, #cmd_raw_no_range_check, #config_tool_names, #connect_interface, #connect_router, #delete_config, #disable_cmd, #disable_limits, #disable_limits_group, #disconnect_interface, #disconnect_router, #enable_cmd, #enable_limits, #enable_limits_group, #get_all_cmd_names, #get_all_cmds, #get_all_interface_info, #get_all_router_info, #get_all_settings, #get_all_tlm, #get_all_tlm_item_names, #get_all_tlm_names, #get_cmd, #get_cmd_buffer, #get_cmd_cnt, #get_cmd_cnts, #get_cmd_hazardous, #get_cmd_time, #get_cmd_value, #get_interface, #get_interface_names, #get_item, #get_limits, #get_limits_events, #get_limits_groups, #get_limits_set, #get_limits_sets, #get_metrics, #get_out_of_limits, #get_overall_limits_state, #get_overrides, #get_packet_derived_items, #get_packets, #get_param, #get_router, #get_router_names, #get_setting, #get_settings, #get_target, #get_target_interfaces, #get_target_names, #get_tlm, #get_tlm_available, #get_tlm_buffer, #get_tlm_cnt, #get_tlm_cnts, #get_tlm_packet, #get_tlm_values, #inject_tlm, #interface_cmd, #interface_details, #interface_protocol_cmd, #interface_target_disable, #interface_target_enable, #limits_enabled?, #list_configs, #list_settings, #load_config, #map_target_to_interface, #map_target_to_router, #normalize_tlm, #offline_access_needed, #override_tlm, #router_cmd, #router_details, #router_protocol_cmd, #router_target_disable, #router_target_enable, #save_config, #send_raw, #set_limits, #set_limits_set, #set_offline_access, #set_setting, #set_tlm, #start_raw_logging_interface, #start_raw_logging_router, #stash_all, #stash_delete, #stash_get, #stash_keys, #stash_set, #stop_raw_logging_interface, #stop_raw_logging_router, #subscribe_packets, #tlm, #tlm_formatted, #tlm_raw, #tlm_with_units, #unmap_target_from_interface, #unmap_target_from_router, #update_news, #update_plugin_store
Methods included from CmdLog
Constructor Details
#initialize(write_port_name, read_port_name, baud_rate, parity, stop_bits, write_timeout, read_timeout, protocol_type = nil, *protocol_args) ⇒ SerialInterface
Creates a serial interface which uses the specified stream protocol.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/openc3/interfaces/serial_interface.rb', line 38 def initialize(write_port_name, read_port_name, baud_rate, parity, stop_bits, write_timeout, read_timeout, protocol_type = nil, *protocol_args) super(protocol_type, protocol_args) @write_port_name = ConfigParser.handle_nil(write_port_name) @read_port_name = ConfigParser.handle_nil(read_port_name) @baud_rate = baud_rate @parity = parity.to_s.intern @stop_bits = stop_bits @write_timeout = write_timeout @read_timeout = read_timeout @write_allowed = false unless @write_port_name @write_raw_allowed = false unless @write_port_name @read_allowed = false unless @read_port_name @flow_control = :NONE @data_bits = 8 end |
Instance Method Details
#connect ⇒ Object
Creates a new OpenC3::SerialStream using the parameters passed in the constructor
79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/openc3/interfaces/serial_interface.rb', line 79 def connect @stream = SerialStream.new( @write_port_name, @read_port_name, @baud_rate, @parity, @stop_bits, @write_timeout, @read_timeout, @flow_control, @data_bits ) super() end |
#connection_string ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/openc3/interfaces/serial_interface.rb', line 63 def connection_string type = '' if @write_port_name and @read_port_name port = @write_port_name type = 'R/W' elsif @write_port_name port = @write_port_name type = 'write only' else port = @read_port_name type = 'read only' end return "#{port} (#{type}) #{@baud_rate} #{@parity} #{@stop_bits}" end |
#details ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/openc3/interfaces/serial_interface.rb', line 107 def details result = super() result['write_port_name'] = @write_port_name result['read_port_name'] = @read_port_name result['baud_rate'] = @baud_rate result['parity'] = @parity result['stop_bits'] = @stop_bits result['write_timeout'] = @write_timeout result['read_timeout'] = @read_timeout result['flow_control'] = @flow_control result['data_bits'] = @data_bits return result end |
#set_option(option_name, option_values) ⇒ Object
Supported Options FLOW_CONTROL - Flow control method NONE or RTSCTS. Defaults to NONE DATA_BITS - Number of data bits 5, 6, 7, or 8. Defaults to 8
97 98 99 100 101 102 103 104 105 |
# File 'lib/openc3/interfaces/serial_interface.rb', line 97 def set_option(option_name, option_values) super(option_name, option_values) case option_name.upcase when 'FLOW_CONTROL' @flow_control = option_values[0] when 'DATA_BITS' @data_bits = option_values[0].to_i end end |