Question

I am using RedHawk 1.9. I have an out port which I plan to send string data across it. In the overview panel in the IDE I add a port with BULKIO dataChar type. When I try the following:

   std::string cmd = "testCmd";
   this->dataChar->pushPacket( cmd.str(), bulkio::time::utils::now(), 
       false, this->ar8200CmdStream_id);

I am getting a error message that indicates pushPacket is wanting std::vector versus char *. This looks like the approach taken in the manual.

Did I pick the wrong BULKIO type for string? I thought about using dataXML, but I expected that was expecting XML format.

PS: I noticed the manual does not include a time in the pushPacket call.

Was it helpful?

Solution

You are correct. The BULKIO data port for char takes a vector of chars. Below you'll find a code snippet that uses a bulkio char output port to send a string and a bulkio char input port to receive the data.


From a pushString component's service function:

std::string str = "hello_world";
data = std::vector<char>(str.begin(), str.end());

stringOut->pushPacket(this->data, tstamp, false, this->stream_id);

From a receiveString component's service function:

bulkio::InCharPort::dataTransfer *tmp = stringIn->getPacket(-1);

if (not tmp) { // No data is available
    return NOOP;
}

std::string outputString(tmp->dataBuffer.begin(), tmp->dataBuffer.end());
std::cout << outputString << std::endl;
fflush(stdout);

However, the bulkio port types are generally used for streaming data transfer. If you intend to use the string as a means of command and control, you may want to reconsider your choice of the bulkio char port in favor of the messaging API (http://redhawksdr.github.io/Documentation/mainch17.html).

Using the messaging API also allows you to take advantage of the IDE's Event Viewer: http://redhawksdr.github.io/Documentation/mainch19.html#x21-32900019.4.7

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top