我正试图尽可能地从JavaScript->Fire气相->Serial项目中筛选出最佳性能。本质上,我的JavaScript代码非常快地将字符串传递给火一口气插件(每个命令之间有40-100 my ),然后将这些字符串转发到串行端口。
虽然一切正常,但偶尔会遗漏一个字符串,或者串行端口冻结,并且必须重新设置。我已经证实这不是我正在使用的硬件设备,并怀疑这些功能中可能存在这个问题。对于优化从Sc48E接收字符串(类似于“JavaScript”)的速度,将其解析为一个字符(不幸的是这是必需的)并将其发送到串口,有什么建议吗?
谢谢你的意见!
使用jUART:https://github.com/billhsu/jUART
C++代码:
SerialAPI.h
void sendmulti(const std::string& msg)
{
io.post(boost::bind(&SerialAPI::do_multi_send, this, msg));
}
void do_multi_send(const std::string& msg);SerialAPI.cpp
void SerialAPI::do_multi_send(const std::string& msg)
{
bool write_in_progress = !send_msg.empty(); // is there anything currently being written?
char cMsg[5]; // max length of incoming packets
for(int i = 0; i < sLength; i++) {
cMsg[i] = msg[i];
send_msg.push_back(cMsg[i]); // store in write buffer; this function requires a char
}
if (!write_in_progress) // if nothing is currently being written, then start
send_multi_start();
}
void SerialAPI::send_multi_start(void)
{
boost::asio::async_write(serial,
boost::asio::buffer(&send_msg.front(), 5),
boost::bind(&SerialAPI::send_multi_complete,
this,
boost::asio::placeholders::error));
}测井信息
我在SerialAPI.h中添加了日志:
void sendmulti(const std::string& msg)
{
io.post(boost::bind(&SerialAPI::do_multi_send, this, msg));
FBLOG_TRACE("sendmulti()", "SerialAPI.h--sendmulti() works");
}...and in SerialAPI.cpp:
void SerialAPI::do_multi_send(const std::string& msg)
{
bool write_in_progress = !send_msg.empty(); // is there anything currently being written?
const char *cMsg = msg.c_str();
// logging
FBLOG_TRACE("do_multi_send()", "debug cMsg: " << cMsg);
for(int i = 0; i < 5; i++) {
send_msg.push_back(cMsg[i]); // store in write buffer
}
if (!write_in_progress) // if nothing is currently being written, then start
send_multi_start();
}这是我得到的最小输出:
31 [2756] INFO FireBreath <> - ..\..\..\..\src\PluginAuto\Win\np_winmain.cpp:29 - NP_Initialize - Initialization done
34 [2756] INFO FireBreath <> - ..\..\src\NpapiCore\NpapiPluginModule_NPP.cpp:150 - FB::Npapi::NpapiPluginModule::NPP_New - NPP_New: 02F60E30
37 [2756] INFO FireBreath <> - ..\..\src\PluginCore\PluginCore.cpp:40 - FB::PluginCore::setPlatform - os: 00D2E8B0; browser: NPAPI
85 [2756] INFO FireBreath <> - ..\..\src\NpapiCore\NpapiPluginModule_NPP.cpp:208 - FB::Npapi::NpapiPluginModule::NPP_Destroy - NPP_Destroy: 02F60E30
15338 [2756] INFO FireBreath <> - ..\..\src\NpapiCore\NpapiPluginModule_NPP.cpp:150 - FB::Npapi::NpapiPluginModule::NPP_New - NPP_New: 02F60EB0
15340 [2756] INFO FireBreath <> - ..\..\src\PluginCore\PluginCore.cpp:40 - FB::PluginCore::setPlatform - os: 00D2E8B0; browser: NPAPI我好像把一切都安排好了吗?
另外,我不能在我的生活中调试这个应用程序。我遵循了在Windows上调试Chrome的所有步骤,选择了正确的进程,设置了断点,它们实际上是在VS2010中活动的,但是当我运行应用程序或发送函数时,它们不会命中。
谢谢!
发布于 2013-09-29 06:32:20
首先,没有理由将std::string复制到char*,只需使用已经存在的.c_str()。
void SerialAPI::do_multi_send(const std::string& msg)
{
bool write_in_progress = !send_msg.empty(); // is there anything currently being written?
char *cMsg = msg.c_str();
for(int i = 0; i < sLength; i++) {
send_msg.push_back(cMsg[i]); // store in write buffer; this function requires a char
}
if (!write_in_progress) // if nothing is currently being written, then start
send_multi_start();
}
void SerialAPI::send_multi_start(void)
{
boost::asio::async_write(serial,
boost::asio::buffer(&send_msg.front(), 5),
boost::bind(&SerialAPI::send_multi_complete,
this,
boost::asio::placeholders::error));
}除此之外,我不知道该提出什么建议,不过,我不认为这是问题所在。每隔40毫秒并不是很经常,你应该能够在这段时间内做很多这样的事情。我会添加一些日志记录(请参阅在消防网站上的日志页面),看看您是否能够跟踪事情发生的顺序和实际运行的情况。这将使你对正在发生的事情有更多的可见度。
发布于 2013-09-30 10:21:28
这是典型的生产者-消费者设计模式,这是广泛使用的这些插件。
问题
https://stackoverflow.com/questions/19072863
复制相似问题