0

Been searching the google and SO, but i seem to be unable to find the solution.

boost::shared_ptr<boost::asio::serial_port> port (new boost::asio::serial_port(*ioService, "/dev/ttyS1"));

This way the port is created and opened right away, and thats not what i want, i need to create it now, but set all the options and open it later. How can i do that?

I read in the manual and basic_serial_port seems to have a constructor that creates a port by just using the ioService, however, im not sure how to go about it and use it for my application.

user1651105
  • 1,727
  • 4
  • 25
  • 45

1 Answers1

2

One of the Right Things to do in C++ is RAII (Resource Acquisition is Initialisation), and it's the right thing to do for lots of good reasons - so I think you probably shouldn't do what you're trying to.

Could you pass around a nullptr / null smart pointer to the serial port until you're actually going to open it?

Community
  • 1
  • 1
James
  • 24,676
  • 13
  • 84
  • 130
  • While i cna't mark this as accepted answer because it doesn't really answer my direct question, i did rewrite the code of my app so that i get all the required data about port settings before creating the port. Thus, i create and open the port along with the object that owns it and close it when the objects is destroyed. – user1651105 Sep 19 '12 at 10:35