我正在尝试对jUART (https://github.com/billhsu/jUART)中的sendmulti (通过向串口发送char数组的部分循环)进行故障排除。
这个特定的函数没有注册到已经构建在存储库中的.dll中。我下载并重新生成了任何内容,用regsvr32注册了新的.dll,用新重建的.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);SerialAPI.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();
} 谢谢!
* Code*工作
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?
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));
}这才是可行的。对优化我所拥有的有什么建议吗?
谢谢!
发布于 2013-09-28 17:51:09
它已经告诉你到底发生了什么。您将FB::JSObjectPtr& type作为第一个参数,但随后传入该参数的字符串;它不能将字符串转换为javascript对象,因此失败。
我真的不明白为什么sendMulti会做它正在做的事情;它期望在一个字符数组中包含一个字符串,['l','i','k','e',' ','t','h','i','s']。你为什么要这么做?我觉得有点奇怪。
相反,为什么不直接将sendMulti的第一个参数更改为const::string &并在传入字符串时使用它呢?
我想,为了完整起见,我应该说,通过这样调用它,您很可能可以让它按照当前的方式工作:
var strArray = "Sc48E".split('');
ser.sendmulti(strArray, strArray.length);..。请注意,这是非常低效的,因为它必须调用javascript来获取每个字符,而不是将字符串全部放在一个块中。
https://stackoverflow.com/questions/19063447
复制相似问题