Beispiel #1
0
	void Configure(SerialSettings& arSettings, boost::asio::serial_port& arPort, error_code& ec) 
	{ 	
		//Set all the various options
		arPort.set_option(ConvertBaud(arSettings.mBaud), ec); if(ec) return;
		arPort.set_option(ConvertDataBits(arSettings.mDataBits), ec); if(ec) return;
		arPort.set_option(ConvertParity(arSettings.mParity), ec); if(ec) return;
		arPort.set_option(ConvertStopBits(arSettings.mStopBits), ec); if(ec) return;
		arPort.set_option(ConvertFlow(arSettings.mFlowType), ec); if(ec) return;
	}
Beispiel #2
0
  serial(const char* dev_name):ios(),port(ios,dev_name)
  {
    port.set_option(boost::asio::serial_port_base::baud_rate(9600));
    port.set_option(boost::asio::serial_port_base::character_size(8));
    port.set_option(boost::asio::serial_port_base::stop_bits(serial_port_base::stop_bits::one));
    port.set_option(boost::asio::serial_port_base::parity(serial_port_base::parity::none));
    port.set_option(boost::asio::serial_port_base::flow_control(serial_port_base::flow_control::none));

    read_some();
    boost::thread td(boost::bind(&boost::asio::io_service::run,&ios));
  }
	ComClient(boost::asio::io_service& io_service, unsigned int baud, const string& device)
		: active_(true), io_service_(io_service), serialPort(io_service, device)
	{
		if (!serialPort.is_open())
		{
			cerr << "Failed to open serial port\n";
			return;
		}
		cout << "Open " << device << " successfully.\n";
		boost::asio::serial_port_base::baud_rate baud_option(baud);
		serialPort.set_option(baud_option); // set the baud rate after the port has been opened
		read_start();
	}
Beispiel #4
0
void Gps::initialize(boost::asio::serial_port& serial_port, boost::asio::io_service& io_service)
{
  if (worker_) return;
  initialize(boost::shared_ptr<Worker>(new AsyncWorker<boost::asio::serial_port>(serial_port, io_service)));

  configured_ = false;

  boost::asio::serial_port_base::baud_rate current_baudrate;

  serial_port.set_option(boost::asio::serial_port_base::baud_rate(4800));
  boost::this_thread::sleep(boost::posix_time::milliseconds(500));
  if (debug) { serial_port.get_option(current_baudrate); std::cout << "Set baudrate " << current_baudrate.value() << std::endl; }
  configured_ = setBaudrate(baudrate_);
  if (configured_) return;

  serial_port.set_option(boost::asio::serial_port_base::baud_rate(9600));
  boost::this_thread::sleep(boost::posix_time::milliseconds(500));
  if (debug) { serial_port.get_option(current_baudrate); std::cout << "Set baudrate " << current_baudrate.value() << std::endl; }
  configured_ = setBaudrate(baudrate_);
  if (configured_) return;

  serial_port.set_option(boost::asio::serial_port_base::baud_rate(19200));
  boost::this_thread::sleep(boost::posix_time::milliseconds(500));
  if (debug) { serial_port.get_option(current_baudrate); std::cout << "Set baudrate " << current_baudrate.value() << std::endl; }
  configured_ = setBaudrate(baudrate_);
  if (configured_) return;

  serial_port.set_option(boost::asio::serial_port_base::baud_rate(38400));
  boost::this_thread::sleep(boost::posix_time::milliseconds(500));
  if (debug) { serial_port.get_option(current_baudrate); std::cout << "Set baudrate " << current_baudrate.value() << std::endl; }
  configured_ = setBaudrate(baudrate_);
  if (configured_) return;

  serial_port.set_option(boost::asio::serial_port_base::baud_rate(baudrate_));
  boost::this_thread::sleep(boost::posix_time::milliseconds(500));
  if (debug) { serial_port.get_option(current_baudrate); std::cout << "Set baudrate " << current_baudrate.value() << std::endl; }
  configured_ = setBaudrate(baudrate_);
  if (configured_) return;
}
Beispiel #5
0
 /*
   Attempts to close and reopen the serial port
   Sleeps for one second before returning if an exception is caught
 */
 void open()
 {
   try
   {
     p.close();
     p.open(port);
     p.set_option(boost::asio::serial_port::baud_rate(baudrate));
     return;
   }
   catch (const std::exception &exc)
   {
     ROS_ERROR("DVL: error on open(port=%s): %s; reopening after delay", port.c_str(), exc.what());
     boost::this_thread::sleep(boost::posix_time::seconds(1));
   }
 }
Beispiel #6
0
	void SetOption(boost::asio::serial_port& arPort, const T& arOption)
	{
		error_code ec;
		arPort.set_option(arOption, ec);
		if(ec) throw Exception(LOCATION, ec.message());
	}