Reputation: 1460
I am sending data between an XBee transceiver and my PC.
The issue is that, initially (in my program) the data is random characters. Only after opening a serial connection in XCTU does it work.
So the serial data is being sent correctly, but XCTU does something to synchronise my pc to the XBee. Baud rates are set at 9600 both sides.
Does anybody know what XCTU is doing? Or how I can replicate it within my C++ program?
Hopefully the image below explain what is happening more clearly:
Upvotes: 1
Views: 109
Reputation: 1460
I found the issue. I was assuming default options with the boost serial_port object. After setting more of the options the serial communication works reliably. Here are the options that I ended up setting:
port.set_option(asio::serial_port_base::baud_rate(9600));
port.set_option(asio::serial_port_base::character_size(8));
port.set_option(asio::serial_port_base::flow_control(asio::serial_port_base::flow_control::none));
port.set_option(asio::serial_port_base::parity(asio::serial_port_base::parity::none));
port.set_option(asio::serial_port_base::stop_bits(asio::serial_port_base::stop_bits::one));
where port is an asio::serial_port object.
Upvotes: 0
Reputation: 10425
The serial port settings under Windows can be seen with GetCommState and set with SetCommState. Use the first one to see what the XCTU set. Your code can then use the same settings by calling SetCommState.
Upvotes: 2