In this post i’ll be discussing on how to setup cppagent (MTConnect c++ Agent) and run tests on it.
To start with we first need to git clone the repository from Github from here.
The current cloned version hash is 6d57d38cffff4b368f3ec003c2d8868d4f41a988.
Once you have cloned the repo enter the root folder of the repository. Now lets first build MTConnect.
For this we will create a folder named build in the root folder.
$ cd cppagent $ mkdir build $ cd build $ cmake .. $ make
After the make process is complete we will see MTConnect c++ agent in action. For this we will need to run the simulator.
We need to copy certain files to successfully run it. From the build/agent folder, copy VMC-3Axis.xml from the simulator folder into the current folder.
$cd agent
$ cp ../../simulator/VMC-3Axis.xml .
Now copy the agent configuration file
$ cp ../../agent/agent.cfg .
Next edit the copied agent.cfg file and make the following changes to it:
Devices = VMC-3Axis.xml
Host = 127.0.0.1
Open three terminals. In one of the terminals, start the ‘agent’
$ ./agent
Expected o/p:
MTConnect Agent Version 1.3.0.7 - built on Sun Oct 12 22:20:32 2014
In the second terminal run the adapter simulator. For that you need to go inside the simulator folder in the repository root directory then type the following command.
$ ruby run_scenario.rb -l -p 7878 --scenario -v simple_scenario_1.txt
Expected o/p:
run_scenario.rb:41: warning: toplevel constant String referenced by OptionParser::String Waiting on 0.0.0.0 7878 Client connected Received * PING, responding with pong 2014-10-26T18:14:04.512751|execution|INTERRUPTED 2014-10-26T18:14:06.513296|tool_id|1 2014-10-26T18:14:08.513635|execution|ACTIVE 2014-10-26T18:14:10.514086|execution|READY 2014-10-26T18:14:12.514512|program|Tap|execution|READY Received * PING, responding with pong 2014-10-26T18:14:14.514799|tool_id|2 2014-10-26T18:14:16.515056|execution|ACTIVE 2014-10-26T18:14:18.515424|execution|READY 2014-10-26T18:14:20.515717|tool_id|3 2014-10-26T18:14:22.516117|program|Countersink|execution|ACTIVE
In the third terminal type the following:
$ curl localhost:5000/current
This will give a XML output every time. Each XML output is different. You can check that by piping the output to a file and then doing a diff of the two files
$ curl localhost:5000/current > 1.xml $ curl localhost:5000/current > 2.xml $ diff 1.xml 2.xml
The output will be something like:
4c4 < <Header creationTime="2014-10-26T18:19:10Z" sender="localhost.localdomain" instanceId="1414347216" version="1.3.0.7" bufferSize="131072" nextSequence="227" firstSequence="1" lastSequence="226"/> --- > <Header creationTime="2014-10-26T18:19:16Z" sender="localhost.localdomain" instanceId="1414347216" version="1.3.0.7" bufferSize="131072" nextSequence="229" firstSequence="1" lastSequence="228"/> 70,71c70,71 < <Execution dataItemId="cn6" timestamp="2014-10-26T18:19:10.560074" name="execution" sequence="226">ACTIVE</Execution> < <ToolId dataItemId="cnt1" timestamp="2014-10-26T18:19:08.559795" name="tool_id" sequence="224">3</ToolId> --- > <Execution dataItemId="cn6" timestamp="2014-10-26T18:19:14.560666" name="execution" sequence="228">READY</Execution> > <ToolId dataItemId="cnt1" timestamp="2014-10-26T18:19:12.560338" name="tool_id" sequence="227">2</ToolId>
Great!! now we have a working version of cppagent.
Next we will build tests. Follow the steps below to build test. We assume we are outside the repository root. So we need to enter the root first.
$ cd cppagent $ cmake .
Now we will enter the test directory in the root folder and build tests.
$ cd test
$ make
Now to run the tests, run the agent in one terminal and the following command in another.
$ ./agent_test
Expected Output: