Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
usa-m authored Apr 8, 2023
1 parent 28e1ecc commit ba205b7
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,83 @@
 


## Sample application

Sample use of the library is done in following simple application:

```cpp
#include <iostream>
#include <string>
#include <exception>

#include <stdio.h>

#include "ddsconnector.h"

using namespace std;
using namespace dds::net::connector;


void wait_for_exit_key();
void my_double_consumer(std::string& variableName, double variableValue);


int main()
{
string appName = "DDS.Net C++ Connected App";
string serverIP = "127.0.0.1";
unsigned short serverPort = 44556;

cout << appName << endl;
cout << "-----" << endl;
cout << "Press Ctrl+C / input 'C' to exit." << endl << endl;

try
{
DdsConnector connector(
appName,
serverIP, serverPort,
new ConsoleLogger());

connector.registerDoubleConsumer("TESTX", my_double_consumer, ON_CHANGE);
connector.registerDoubleConsumer("TESTY", my_double_consumer, ON_CHANGE);

connector.start();

wait_for_exit_key();

connector.stop();
}
catch (exception& ex)
{
cout << "Error! " << ex.what() << endl;
}

cout << endl << endl << endl;
}


void wait_for_exit_key()
{
char ch;
while ((ch = getc(stdin)) != 'C');
}


static double x, y;

void my_double_consumer(std::string& variableName, double variableValue)
{
if (variableName == "TESTX")
{
x = variableValue;
}
else if (variableName == "TESTY")
{
y = variableValue;

cout << x << ", " << y << endl;
}
}

```

0 comments on commit ba205b7

Please sign in to comment.