jUART/FireBreath 插件错误

jUART/FireBreath Plugin Errors

本文关键字:错误 插件 FireBreath jUART      更新时间:2023-10-16

我正在尝试对jUART(https://github.com/billhsu/jUART(中的sendmulti函数(循环将字符数组的一部分发送到串行端口(进行故障排除。

该特定函数未注册到存储库中已内置的.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 的明显相关函数:

SerialAPI.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);

串行接口.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(); 
} 

谢谢!

*

工作代码*

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);

串行接口.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)); 
}

这就是有效的。有什么建议可以优化我所拥有的吗?

谢谢!

它已经确切地告诉你发生了什么。 你把一个FB::JSObjectPtr&类型作为第一个参数,但随后你传入了该参数的字符串;它无法将字符串转换为 JavaScript 对象,因此会失败。

我真的不明白为什么sendMulti可能会做它正在做的事情;它期待一个字符数组中的字符串,['l','i','k','e',' ','t','h','i','s']。 你为什么要这样做? 这对我来说似乎有点奇怪。

相反,你为什么不直接将sendMulti的第一个参数更改为const std::string&并在传入时使用字符串呢?

我想为了完整起见,我应该说你可以通过这样称呼它来让它以当前的方式工作:

var strArray = "Sc48E".split('');
ser.sendmulti(strArray, strArray.length);

。请注意,这确实效率低下,因为它必须回调到 JavaScript 中才能获取每个字符,而不仅仅是在一个块中获取所有字符串。