我正在尝试对 jUART ( https://github.com/billhsu/jUART )中的 sendmulti 函数(通过将 char 数组的一部分发送到串行端口进行循环)进行故障排除。
该特定功能未在存储库中已构建的 .dll 中注册。我下载并重建而没有改变任何东西,用 regsvr32 注册新的 .dll 并用新重建的替换旧的 .dll。
现在该函数已注册并且可以调用,但是根据我提供的输入,我遇到了一些错误。
第一个错误:
ser.sendmulti("Sc48E");
Error in event handler: Error: Error calling method on NPObject.
ser.getLastException();
"Error: Argument 2is not optional."
所以我添加了第二个参数,现在我得到:
ser.sendmulti("Sc48E", 2);
Error: Error calling method on NPObject.
ser.getLastException();
"Invalid argument conversion from class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > to class boost::shared_ptr<class FB::JSAPI> at index 1"
不太确定从那里去哪里(根本不是经验丰富的开发人员),所以我正在转向社区,看看下一步应该研究什么,或者是否有人可以和我一起潜入 jUART 以找到修复。
我可以找到的 sendmulti 明显相关的功能:
串行API.h
void sendmulti(const FB::JSObjectPtr& msg, int length)
{
unsigned char *message = new unsigned char[length];
FB::variant v;
for(int i = 0; i < length; i++)
{
v = msg->GetProperty(i);
message[i] = v.convert_cast<unsigned char>();
}
io.post(boost::bind(&SerialAPI::do_multi_send, this, (char *)message, length));
void do_multi_send(const char msg[], int length);
void send_multi_start(int length);
串行API.cpp
void SerialAPI::do_multi_send(const char msg[], const int length)
{
bool write_in_progress = !send_msg.empty(); // is there anything currently being written?
for(int i = 0; i < length; i++)
{
send_msg.push_back(msg[i]); // store in write buffer
}
if (!write_in_progress) // if nothing is currently being written, then start
send_multi_start(length);
}
void SerialAPI::send_multi_start(int length)
{
boost::asio::async_write(serial,
boost::asio::buffer(&send_msg.front(), length),
boost::bind(&SerialAPI::send_multi_complete,
this,
boost::asio::placeholders::error));
}
我认为这些是直接相关的函数,但值得注意的是 send() 函数(仅发送一个字节)与第一个 .dll 一起工作正常,并且与新建的 .dll 给出相同的错误:
void SerialAPI::do_send(const char msg)
{
bool write_in_progress = !send_msg.empty(); // is there anything currently being written?
send_msg.push_back(msg); // store in write buffer
if (!write_in_progress) // if nothing is currently being written, then start
send_start();
}
谢谢!
*工作代码*
串行API.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);
串行API.cpp
void SerialAPI::do_multi_send(const std::string& msg)
{
bool write_in_progress = !send_msg.empty(); // is there anything currently being written?
const int sLength = msg.length();
for(int i = 0; i < sLength; i++) {
const char cMsg = msg[i];
send_msg.push_back(cMsg); // store in write buffer
if (!write_in_progress) // if nothing is currently being written, then start
send_multi_start(sLength);
}
void SerialAPI::send_multi_start(int sLength)
{
boost::asio::async_write(serial,
boost::asio::buffer(&send_msg.front(), sLength),
boost::bind(&SerialAPI::send_multi_complete,
this,
boost::asio::placeholders::error));
}
这就是有效的。有什么建议可以优化我所拥有的吗?
谢谢!