因此,我一直试图弄清楚如何等待来自 C++ stringstream 的数据(例如),而不需要不断检查数据是否存在,这非常消耗 CPU。
例如,我完全能够从串行设备读取数据,并在没有数据到达时锁定进程,但不幸的是我无法弄清楚如何使用 C++ 流来做到这一点。
我确信我错过了一些东西,因为 cin 正是这样做的,即等待返回键从 istream 读取中退出,但它是如何做到的呢?
预先感谢您对这个主题的任何了解。
我已经在我的一些 XBee 的小项目上工作了很长时间。到目前为止,所有代码都已经过测试并在 UBUNTU-SERVER 10.04 LTS 上运行,利用libftdi库进行串行 USB 模拟/转换。
本周初,我尝试在带有 kubuntu 12.04 的笔记本电脑上使用完全相同的代码,使用相同的libftdi库版本。
问题是,在我的 Satellite L755 - 18K 笔记本电脑中,每次我现在尝试在/dev/ttyUSB0打开我的 XBee 设备时,它都会给我“错误的文件描述符”。从dmesg的日志消息中,设备注册非常正常,似乎无法让我指指点点。
这是用于打开设备的代码部分:
cfmakeraw(&tio);
cfsetospeed(&tio,B9600); // 9600 baud
cfsetispeed(&tio,B9600); // 9600 baud
tio.c_cc[VMIN]=0;
tio.c_cc[VTIME]=10;
serial_fd=open("/dev/ttyUSB0", O_RDWR);
tcsetattr(serial_fd,TCSANOW,&tio);
if (serial_fd < 0){
cout << "Error while opening device... " << "errno = " << errno << endl;
printf("Something went wrong with open()! %s\n", strerror(errno));
exit(1);
}
Run Code Online (Sandbox Code Playgroud)
对这个主题的任何想法将不胜感激。
问候
我正在尝试编译以下XERCES站点提供的示例代码:
#include <xercesc/util/PlatformUtils.hpp>
// Other include files, declarations, and non-Xerces-C++ initializations.
XERCES_CPP_NAMESPACE_USE
int main(int argc, char* argv[])
{
try {
XMLPlatformUtils::Initialize();
}
catch (const XMLException& toCatch) {
// Do your failure processing here
return 1;
}
// Do your actual work with Xerces-C++ here.
XMLPlatformUtils::Terminate();
// Other terminations and cleanup.
return 0;
}
Run Code Online (Sandbox Code Playgroud)
用,
g++ -g -Wall -pedantic -L/usr/lib -lxerces-c -o xercesTest xercesTest.cpp
Run Code Online (Sandbox Code Playgroud)
给我以下链接错误:
/tmp/ccYIHCfR.o: In function `main':
/home/cjmv/temp/xercesTest.cpp:8: undefined reference to `xercesc_2_8::XMLUni::fgXercescDefaultLocale'
/home/cjmv/temp/xercesTest.cpp:8: undefined reference to `xercesc_2_8::XMLPlatformUtils::Initialize(char const*, char …Run Code Online (Sandbox Code Playgroud) c++ ×3
c ×1
istream ×1
serial-port ×1
stringstream ×1
ubuntu ×1
usbserial ×1
xbee ×1
xerces ×1
xerces-c ×1