0
在使用boost :: asio創建應用程序時,我爲我的目的調整了一個示例。如何在boost :: asio應用程序的這個示例中使用send_break重置?
但是,使其工作後,我現在試圖讓它工作得更好。爲了這樣做,我需要以某種方式重置我的串行設備。在類似的應用中,這是通過發送break
信號完成的。
出於某種原因,我似乎無法做到這一點,沒有得到例外。
我正在使用void send_break()
函數,也許這是問題,因爲它似乎總會拋出一個錯誤。
這是升壓代碼:
/// Send a break sequence to the serial port.
/**
* This function causes a break sequence of platform-specific duration to be
* sent out the serial port.
*
* @throws boost::system::system_error Thrown on failure.
*/
void send_break()
{
boost::system::error_code ec;
this->get_service().send_break(this->get_implementation(), ec);
boost::asio::detail::throw_error(ec, "send_break");
}
/// Send a break sequence to the serial port.
/**
* This function causes a break sequence of platform-specific duration to be
* sent out the serial port.
*
* @param ec Set to indicate what error occurred, if any.
*/
boost::system::error_code send_break(boost::system::error_code& ec)
{
return this->get_service().send_break(this->get_implementation(), ec);
}
這是我試圖調用從函數的代碼:
class minicom_client
{
public:
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::baud_rate baud_option(baud);
serialPort.set_option(baud_option); // set the baud rate after the port has been opened
serialPort.send_break();
read_start();
}
編輯:
玩這個後有一段時間,我發現我得到的錯誤代碼是boost::asio::error::operation_not_supported;
- 但是,如果這是一個函數構建?
從* win_iocp_serial_port_service.hpp *:
// Send a break sequence to the serial port.
boost::system::error_code send_break(implementation_type&,
boost::system::error_code& ec)
{
ec = boost::asio::error::operation_not_supported;
return ec;
}
現在我真的失去了這裏。
是的,這將清除它幾乎 - 然而,爲什麼它是這樣實現的,我不明白這一點O_O你有什麼想法,我怎麼可以創建一個破葛,它被指定爲*的RX輸入非空閒狀態(0v)超過125ms *。 – Jook
@llonesmiz - 你爲什麼刪除你的答案?你基本上解決了我的問題,通過指向我的一些正確的來源。我必須使用SetCommBreak | Sleep | ClearCommBreak和我的串行端口的正確設置,現在我的設備重置工作 - 所以謝謝!如果你應該取消刪除你的答案,你會得到一個接受。 – Jook