What is wrong with this attempt of sending a break-signal?
Posted
by
Jook
on Stack Overflow
See other posts from Stack Overflow
or by Jook
Published on 2012-10-22T13:13:04Z
Indexed on
2012/10/23
11:01 UTC
Read the original article
Hit count: 193
I have quite a headache about this seemingly easy task: send a break signal to my device, like the wxTerm (or any similar Terminal application) does.
This signal has to be 125ms long, according to my tests and the devices specification.
It should result in a specific response, but what I get is a longer response than expected, and the transmitted date is false.
e.g.:
what it should respond 08 00 81 00 00 01 07 00
what it does respond 08 01 0A 0C 10 40 40 07 00 7F
What really boggles me is, that after I have used wxTerm to look at my available com-ports (without connecting or sending anything), my code starts to work! I can send then as many breaks as I like, I get my response right from then on. I have to reset my PC in order to try it again.
What the heck is going on here?!
Here is my code for a reset through a break-signal:
minicom_client(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;
}
boost::asio::serial_port_base::flow_control FLOW( boost::asio::serial_port_base::flow_control::hardware );
boost::asio::serial_port_base::baud_rate baud_option(baud);
serialPort.set_option(FLOW);
serialPort.set_option(baud_option);
read_start();
std::cout << SetCommBreak(serialPort.native_handle()) << std::endl;
std::cout << GetLastError() << std::endl;
boost::posix_time::ptime mst1 = boost::posix_time::microsec_clock::local_time();
boost::this_thread::sleep(boost::posix_time::millisec(125));
boost::posix_time::ptime mst2 = boost::posix_time::microsec_clock::local_time();
std::cout << ClearCommBreak(serialPort.native_handle()) << std::endl;
std::cout << GetLastError() << std::endl;
boost::posix_time::time_duration msdiff = mst2 - mst1;
std::cout << msdiff.total_milliseconds() << std::endl;
}
Edit:
It was only necessary to look at the combo-box selection of com-ports of wxTerm - no active connection was needed to be established in order to make my code work.
I am guessing, that there is some sort of initialisation missing, which is done, when wxTerm is creating the list for the serial-port combo-box.
© Stack Overflow or respective owner