Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8603015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:13:30+00:00 2026-06-12T02:13:30+00:00

I am configuring serial port using boost asio. but why below code is giving

  • 0

I am configuring serial port using boost asio.
but why below code is giving error?
If I comment set_option it works fine.

below code gives error

serial_config.cpp:13: error: expected unqualified-id before numeric
constant In file included from
/home/chirag/boost_install/include/boost/asio/serial_port_service.hpp:25,
from /home/chirag/boost_install/include/boost/asio/basic_serial_port.hpp:30,
from /home/chirag/boost_install/include/boost/asio.hpp:25,
from serial_config.cpp:1: /home/chirag/boost_install/include/boost/asio/detail/reactive_serial_port_service.hpp:
In static member function âstatic boost::system::error_code
boost::asio::detail::reactive_serial_port_service::store_option(const
void*, termios&, boost::system::error_code&) [with
SettableSerialPortOption = int]â:
/home/chirag/boost_install/include/boost/asio/detail/reactive_serial_port_service.hpp:126:
instantiated from âboost::system::error_code
boost::asio::detail::reactive_serial_port_service::set_option(boost::asio::detail::reactive_descriptor_service::implementation_type&,
const SettableSerialPortOption&, boost::system::error_code&) [with
SettableSerialPortOption = int]â
/home/chirag/boost_install/include/boost/asio/serial_port_service.hpp:167:
instantiated from âboost::system::error_code
boost::asio::serial_port_service::set_option(boost::asio::detail::reactive_descriptor_service::implementation_type&,
const SettableSerialPortOption&, boost::system::error_code&) [with
SettableSerialPortOption = int]â
/home/chirag/boost_install/include/boost/asio/basic_serial_port.hpp:390:
instantiated from âvoid
boost::asio::basic_serial_port::set_option(const
SettableSerialPortOption&) [with SettableSerialPortOption = int,
SerialPortService = boost::asio::serial_port_service]â
serial_config.cpp:31: instantiated from here
/home/chirag/boost_install/include/boost/asio/detail/reactive_serial_port_service.hpp:194:
error: request for member âstoreâ in â*(const int*)optionâ, which is
of non-class type âconst intâ

#include <boost/asio.hpp> // include boost
using namespace::boost::asio;  // save tons of typing
#include <iostream>
using std::cin;

// These are the values our port needs to connect
#ifdef _WIN32
// windows uses com ports, this depends on what com port your cable is plugged in to.
    const char *PORT = "COM3";
#else
// *nix com ports
    const char *PORT = "dev/ttyS3";
#endif
// Note: all the following except BAUD are the exact same as the default values

// what baud rate do we communicate at
serial_port_base::baud_rate BAUD(19200);
// how big is each "packet" of data (default is 8 bits)
serial_port_base::character_size CSIZE( 8 );
// what flow control is used (default is none)
serial_port_base::flow_control FLOW( serial_port_base::flow_control::none );
// what parity is used (default is none)
serial_port_base::parity PARITY( serial_port_base::parity::none );
// how many stop bits are used (default is one)
serial_port_base::stop_bits STOP( serial_port_base::stop_bits::one );

int main()
{
    // create the I/O service that talks to the serial device
    io_service io;
    // create the serial device, note it takes the io service and the port name
    serial_port port( io, PORT );

    // go through and set all the options as we need them
    // all of them are listed, but the default values work for most cases
    port.set_option( BAUD );
    port.set_option( CSIZE );
    port.set_option( FLOW );
    port.set_option( PARITY );
    port.set_option( STOP );

    // buffer to store commands
    // this device reads 8 bits, meaning an unsigned char, as instructions
    // varies with the device, check the manual first
    unsigned char command[1] = {0};

    // read in user value to be sent to device
    int input;
    cin >> input;

    // Simple loop, since the only good values are [0,255]
    //  break when a negative number is entered.
    // The cast will convert too big numbers into range.
    while( input >= 0 )
    {
        // convert our read in number into the target data type
        command[0] = static_cast<unsigned char>( input );

        // this is the command that sends the actual bits over the wire
        // note it takes a stream and a asio::buffer
        // the stream is our serial_port
        // the buffer is constructed using our command buffer and
        //  the number of instructions to send
        write( port, buffer( command, 1 ) );

        // read in the next input value
        cin >> input;
    }

    // all done sending commands
    return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T02:13:31+00:00Added an answer on June 12, 2026 at 2:13 am

    If you change character_size variable name to C_SIZE from CSIZE then it shall work…..

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Comm32 (an activeX control) to get data coming through serial port using
For configuring my ASP.Net Application I'm using Custom Configuration Sections in my web.config. But
I´m configuring Redmine for the first time. Everything works fine except for the incoming
Configuring NHibernate to display executed SQL does what it's supposed to, but whenever a
I am configuring django for using django admin tool, following steps in webpage http://www.ibm.com/developerworks/linux/library/l-django/?S_TACT=105AGX52&S_CMP=cn-a-l
Configuring the PHP debuggers was so hard that I can't even imagine myself using
When configuring uwsgi django application for first time i had weird error. NGIX (configured
I'm configuring my build server using TeamCity with Mercurial and I don't know what
While configuring FLOW3, I get the following error #1315561483: It seems like the PHP
we're configuring parts of an application at runtime: ConfigurationManager.AppSettings[someKey] = someValue; This code is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.