【发布时间】:2017-08-01 16:06:47
【问题描述】:
我开始使用 C#,并尝试测试 dds 应用程序的代码。我取自:http://www.laas.fr/files/SLides-A_Corsaro.pdf
using System;
/**********************************************************
* Definition for the TempSensorType
**********************************************************/
enum TemperatureScale{
CELSIUS,
KELVIN,
FAHRENHEIT
};
struct TempSensorType{
short id;
float temp;
float hum;
TemperatureScale scale;
};
#pragma keylist TempSensor id
/**********************************************************
* Main
**********************************************************/
static public void Main(string[] args){
dds::Topic<TempSensorType> tsTopic(TempSensorTopic);
dds::DataWriter<TempSensorType> dw(tsTopic);
dds::DataReader<TempSensorType> dr(tsTopic);
dds::SampleInfoSeq info;
TempSensorSeq data;
TempSensorType ts;
ts = new TempSensorType { 1, 25.0F, 65.0F, CELSIUS };
dw.write(ts);
ts = new TempSensorType { 2, 26.0F, 70.0F, CELSIUS };
dw.write(ts);
ts = new TempSensorType { 3, 27.0F, 75.0F, CELSIUS };
dw.write(ts);
sleep(10);
while (true){
dr.read(data, info);
for (int i = 0; i < data.length(); ++i)
std::cout << data[i] << std::endl;
sleep(1);
}
Console.WriteLine("Bonjour");
}
我开始理解每段代码的用途。但我有疑问 关于主要的 4 行,以“dds::”开头的那些,我认为它们是错误的 - 我得到的是“预期的标识符”。如果您能提供帮助,将不胜感激。
【问题讨论】:
-
这到底有什么问题?你有例外吗?
-
是的,我在所有这些中都注意到“预期标识符”。我想这是因为语法。
-
这是 C++,不是 C#。
#pragma keylist....不是有效的 C# 代码,但它是有效的 C++。与std::cout << data[i] << std::endl;相同 -
我没有看到包含 DDS 命名空间的任何内容。还有你用的是哪个库?
-
是的,你是对的!我会重新从底部开始。
标签: c++ communication publish-subscribe data-distribution-service opensplice