我有一个用于处理数据的python脚本(作为更大框架的一部分),以及一个用于从仪器收集数据的c ++脚本。 c ++代码不断收集,然后通过cout发出数据。
程序需要彼此交谈:
我在最后一步挣扎,我觉得中断是最好的方法,但我可能错了?这就是我现在所拥有的:
(Python)
p = Popen("C++Script.exe", stdin=PIPE, stdout=PIPE, bufsize=1, shell=True)
# Wait for stuff to happen
# Send command to change read_flag to False in c++ script
for line in iter(p.stdout.readline, ''):
line = str(line) # Contains data to be parsed, obtained from cout
# Do stuff..
(c ++ main)
...
BOOL read_flag = TRUE;
thread t1{ interrupt, &read_flag };
float Temp;
vector <float> OutData;
//Data read and stored in vector
for (int i = 1; read_flag == TRUE; i++)
{
Temp = Get_Single_Measurement();
OutData.push_back(Temp);
}
//Data read out in one go
for (int i = 0; i < OutData.size(); i++)
{
cout << OutData[i] << endl; //Picked up by python code
}
t1.join();
...
(c ++中断)
void interrupt(BOOL *read_flag)
{
// Listen for Python command to interrupt reading
*read_flag = FALSE;
}
如果有人能指出我在写作轨道上,它真的很有帮助,很高兴采用任何有效的解决方案。
谢谢!