Setting up MTConnect C++ Agent

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:

AdapterTest::testAdapter : OK
AgentTest::testConstructor 2 ERROR [0] xml.parser: XML: I/O
2 ERROR [0] xml.parser: XML: warning :
2 ERROR [0] xml.parser: XML: failed to load external entity "../samples/badPath.xml"

2 FATAL [0] agent: Error loading xml configuration: ../samples/badPath.xml
2 FATAL [0] agent: Error detail: XML Error at /home/subho/work/github/cppagent_new/cppagent/agent/xml_parser.cpp(74): mDoc = xmlReadFile(aPath.c_str(), NULL, XML_PARSE_NOBLANKS)
XML Error at /home/subho/work/github/cppagent_new/cppagent/agent/xml_parser.cpp(74): mDoc = xmlReadFile(aPath.c_str(), NULL, XML_PARSE_NOBLANKS)
: OK
AgentTest::testBadPath : OK
AgentTest::testProbe : OK
AgentTest::testBadXPath 10 ERROR [0] xml.parser: XML: Invalid expression

10 ERROR [0] xml.parser: XML: Invalid expression

10 ERROR [0] xml.parser: XML: Invalid expression

10 ERROR [0] xml.parser: XML: Invalid predicate

10 ERROR [0] xml.parser: XML: Invalid expression

: OK
AgentTest::testXPath : OK
AgentTest::testBadCount : OK
AgentTest::testBadFreq : OK
AgentTest::testGoodPath : OK
AgentTest::testEmptyStream : OK
AgentTest::testBadDevices : OK
AgentTest::testAddAdapter : OK
AgentTest::testAddToBuffer : OK
AgentTest::testAdapter : OK
AgentTest::testCurrentAt : OK
AgentTest::testCurrentAt64 : OK
AgentTest::testCurrentAtOutOfRange : OK
AgentTest::testSampleAtNextSeq : OK
AgentTest::testAdapterCommands : OK
AgentTest::testFileDownload : OK
AgentTest::testFailedFileDownload 288 ERROR [0] agent: Cannot register file: ./BadFileName.xsd: Unable to find file ./BadFileName.xsd
: OK
AgentTest::testDuplicateCheck : OK
AgentTest::testAutoAvailable : OK
AgentTest::testIgnoreTimestamps : OK
AgentTest::testAssetStorage : OK
AgentTest::testAssetError : OK
AgentTest::testAssetBuffer : OK
AgentTest::testPut : OK
AgentTest::testPutBlocking : OK
AgentTest::testPutBlockingFrom : OK
AgentTest::testAdapterAddAsset : OK
AgentTest::testMultiLineAsset : OK
AgentTest::testAssetProbe : OK
AgentTest::testAssetStorageWithoutType : OK
AgentTest::testStreamData : OK
AgentTest::testSequenceNumberRollover : OK
AgentTest::testSampleCount : OK
AgentTest::testStreamDataObserver : OK
AgentTest::testFailWithDuplicateDeviceUUID 3461 ERROR [0] xml.parser: XML: I/O
3461 ERROR [0] xml.parser: XML: warning :
3461 ERROR [0] xml.parser: XML: failed to load external entity "../samples/dup_uuid.xml"

3461 FATAL [0] agent: Error loading xml configuration: ../samples/dup_uuid.xml
3461 FATAL [0] agent: Error detail: XML Error at /home/subho/work/github/cppagent_new/cppagent/agent/xml_parser.cpp(74): mDoc = xmlReadFile(aPath.c_str(), NULL, XML_PARSE_NOBLANKS)
XML Error at /home/subho/work/github/cppagent_new/cppagent/agent/xml_parser.cpp(74): mDoc = xmlReadFile(aPath.c_str(), NULL, XML_PARSE_NOBLANKS)
: OK
AgentTest::testMultipleDisconnect : OK
AgentTest::testRelativeTime : OK
AgentTest::testRelativeParsedTime : OK
AgentTest::testRelativeParsedTimeDetection : OK
AgentTest::testRelativeOffsetDetection : OK
AgentTest::testDynamicCalibration : OK
AgentTest::testInitialTimeSeriesValues : OK
AgentTest::testUUIDChange : OK
AgentTest::testFilterValues : OK
AgentTest::testReferences : OK
AgentTest::testDiscrete : OK
AgentTest::testUpcaseValues : OK
AgentTest::testConditionSequence : OK
AgentTest::testAssetRemoval : OK
AgentTest::testAssetRemovalByAdapter : OK
AgentTest::testAssetAdditionOfAssetChanged12 : OK
AgentTest::testAssetAdditionOfAssetRemoved13 : OK
AgentTest::testAssetPrependId : OK
AgentTest::testBadAsset 3520 ERROR [0] xml.parser: XML: file://111.xml:1:
3520 ERROR [0] xml.parser: XML: parser
3520 ERROR [0] xml.parser: XML: error :
3520 ERROR [0] xml.parser: XML: Opening and ending tag mismatch: CuttingItem line 1 and CuttingItmems

3520 ERROR [0] xml.parser: XML: <PointAngle code="SIG" nominal="0">0</PointAngle></Measurements></CuttingItmems>

3520 ERROR [0] xml.parser: XML: ^

3520 ERROR [0] xml.parser: XML: file://111.xml:1:
3520 ERROR [0] xml.parser: XML: parser
3520 ERROR [0] xml.parser: XML: error :
3520 ERROR [0] xml.parser: XML: Opening and ending tag mismatch: CuttingItem line 1 and CuttingToolLifeCycle

3520 ERROR [0] xml.parser: XML: nominal="0">0</PointAngle></Measurements></CuttingItmems></CuttingToolLifeCycle>

3520 ERROR [0] xml.parser: XML: ^

3520 ERROR [0] xml.parser: XML: file://111.xml:1:
3520 ERROR [0] xml.parser: XML: parser
3520 ERROR [0] xml.parser: XML: error :
3520 ERROR [0] xml.parser: XML: Opening and ending tag mismatch: CuttingItem line 1 and CuttingTool

3520 ERROR [0] xml.parser: XML: </PointAngle></Measurements></CuttingItmems></CuttingToolLifeCycle></CuttingTool

3520 ERROR [0] xml.parser: XML: ^

3520 ERROR [0] xml.parser: XML: file://111.xml:2:
3520 ERROR [0] xml.parser: XML: parser
3520 ERROR [0] xml.parser: XML: error :
3520 ERROR [0] xml.parser: XML: Premature end of data in tag CuttingItems line 1

3520 ERROR [0] xml.parser: XML:

3520 ERROR [0] xml.parser: XML: ^

3520 ERROR [0] xml.parser: XML: file://111.xml:2:
3520 ERROR [0] xml.parser: XML: parser
3520 ERROR [0] xml.parser: XML: error :
3520 ERROR [0] xml.parser: XML: Premature end of data in tag CuttingToolLifeCycle line 1

3520 ERROR [0] xml.parser: XML:

3520 ERROR [0] xml.parser: XML: ^

3520 ERROR [0] xml.parser: XML: file://111.xml:2:
3520 ERROR [0] xml.parser: XML: parser
3520 ERROR [0] xml.parser: XML: error :
3520 ERROR [0] xml.parser: XML: Premature end of data in tag CuttingTool line 1

3520 ERROR [0] xml.parser: XML:

3520 ERROR [0] xml.parser: XML: ^

3520 ERROR [0] xml.parser: Cannot parse asset XML, Unknown execption occurred
3520 ERROR [0] agent: addAssete: Error parsing asset
: OK
AgentTest::testAssetWithSimpleCuttingItems : OK
AgentTest::testRemoveLastAssetChanged : OK
AgentTest::testRemoveAllAssets : OK
AgentTest::testEmptyLastItemFromAdapter : OK
CheckpointTest::testAddComponentEvents : OK
CheckpointTest::testCopy : OK
CheckpointTest::testGetComponentEvents : OK
CheckpointTest::testFilter : OK
CheckpointTest::testCopyAndFilter : OK
CheckpointTest::testConditionChaining : OK
CheckpointTest::testLastConditionNormal : OK
ConfigTest::testBlankConfig : OK
ConfigTest::testBufferSize : OK
ConfigTest::testDevice : OK
ConfigTest::testAdapter : OK
ConfigTest::testDefaultPreserveUUID : OK
ConfigTest::testDefaultPreserveOverride : OK
ConfigTest::testDisablePut : OK
ConfigTest::testLimitPut : OK
ConfigTest::testLimitPutFromHosts : OK
ConfigTest::testNamespaces : OK
ConfigTest::testLegacyTimeout : OK
ConfigTest::testIgnoreTimestamps : OK
ConfigTest::testIgnoreTimestampsOverride : OK
ConfigTest::testSpecifyMTCNamespace : OK
ConfigTest::testSetSchemaVersion : OK
ConfigTest::testSchemaDirectory : OK
ConfigTest::testLogFileRollover : OK
ConfigTest::testMaxSize : OK
ComponentTest::testGetters : OK
ComponentTest::testGetAttributes : OK
ComponentTest::testDescription : OK
ComponentTest::testRelationships : OK
ComponentTest::testDataItems : OK
ComponentTest::testReferences : OK
ComponentEventTest::testConstructors : OK
ComponentEventTest::testGetAttributes : OK
ComponentEventTest::testConvertValue : OK
ComponentEventTest::testConvertSimpleUnits : OK
ComponentEventTest::testRefCounts : OK
ComponentEventTest::testStlLists : OK
ComponentEventTest::testEventChaining : OK
ComponentEventTest::testCondition : OK
ComponentEventTest::testTimeSeries : OK
ComponentEventTest::testDuration : OK
ComponentEventTest::testAssetChanged : OK
ConnectorTest::testConnection 3675 ERROR [1] input.connector: connect: Socket error, disconnecting
3675 ERROR [1] input.connector: connect: Connection exited with status: -3
: OK
ConnectorTest::testDataCapture 4676 ERROR [2] input.connector: connect: Socket error, disconnecting
4676 ERROR [2] input.connector: connect: Connection exited with status: -3
: OK
ConnectorTest::testDisconnect 5676 ERROR [3] input.connector: connect: Socket error, disconnecting
5676 ERROR [3] input.connector: connect: Connection exited with status: -3
: OK
ConnectorTest::testProtocolCommand 7677 ERROR [4] input.connector: connect: Socket error, disconnecting
7677 ERROR [4] input.connector: connect: Connection exited with status: -3
: OK
ConnectorTest::testHeartbeat 8677 ERROR [5] input.connector: connect: Socket error, disconnecting
8677 ERROR [5] input.connector: connect: Connection exited with status: 0
: OK
ConnectorTest::testHeartbeatPong13694 ERROR [6] input.connector: connect: Socket error, disconnecting
13694 ERROR [6] input.connector: connect: Connection exited with status: 0
: OK
ConnectorTest::testHeartbeatTimeout15696 ERROR [7] input.connector: connect: Did not receive heartbeat for over: 2000
15696 ERROR [7] input.connector: connect: Connection exited with status: -1
: OK
ConnectorTest::testParseBuffer : OK
ConnectorTest::testParseBufferFraming : OK
ConnectorTest::testSendCommand16795 ERROR [8] input.connector: connect: Socket error, disconnecting
16795 ERROR [8] input.connector: connect: Connection exited with status: 0
: OK
ConnectorTest::testLegacyTimeout21800 ERROR [9] input.connector: connect: Did not receive data for over: 5 seconds
21800 ERROR [9] input.connector: connect: Connection exited with status: -1
: OK
ConnectorTest::testIPV6Connection27896 ERROR [10] input.connector: connect: Socket error, disconnecting
27897 ERROR [10] input.connector: connect: Connection exited with status: -3
: OK
ConnectorTest::testStartHeartbeats27897 ERROR [0] input.connector: startHeartbeats: Bad heartbeat command * PONG , ignoring
27897 ERROR [0] input.connector: startHeartbeats: Bad heartbeat command * PONK , ignoring
27897 ERROR [0] input.connector: startHeartbeats: Bad heartbeat command * PONG , ignoring
27897 ERROR [0] input.connector: startHeartbeats: Bad heartbeat command * PONG FLAB, ignoring
: OK
DataItemTest::testGetters : OK
DataItemTest::testGetAttributes : OK
DataItemTest::testHasNameAndSource : OK
DataItemTest::testIsSample : OK
DataItemTest::testComponent : OK
DataItemTest::testGetCamel : OK
DataItemTest::testConversion : OK
DataItemTest::testCondition : OK
DataItemTest::testTimeSeries : OK
DataItemTest::testStatistic : OK
DataItemTest::testSampleRate : OK
DataItemTest::testDuplicates : OK
DataItemTest::testFilter : OK
DeviceTest::testGetters : OK
DeviceTest::testGetAttributes : OK
DeviceTest::testDescription : OK
DeviceTest::testRelationships : OK
DeviceTest::testDataItems : OK
DeviceTest::testDeviceDataItem : OK
DeviceTest::testGetDataItem : OK
GlobalsTest::testIntToString : OK
GlobalsTest::testFloatToString : OK
GlobalsTest::testToUpperCase : OK
GlobalsTest::testIsNonNegativeInteger : OK
GlobalsTest::testTime : OK
GlobalsTest::testIllegalCharacters : OK
GlobalsTest::testGetEnumerations : OK
GlobalsTest::testGetCurrentTime : OK
GlobalsTest::testAddNamespace : OK
GlobalsTest::testParseTimeMilli : OK
XmlParserTest::testConstructor31900 ERROR [0] xml.parser: XML: I/O
31900 ERROR [0] xml.parser: XML: warning :
31900 ERROR [0] xml.parser: XML: failed to load external entity "../samples/badPath.xml"

: OK
XmlParserTest::testGetDevices : OK
XmlParserTest::testCondition : OK
XmlParserTest::testGetDataItems31903 ERROR [0] xml.parser: XML: Invalid expression

31903 ERROR [0] xml.parser: XML: Invalid expression

: OK
XmlParserTest::testExtendedSchema : OK
XmlParserTest::testTimeSeries : OK
XmlParserTest::testGetDataItemsExt : OK
XmlParserTest::testConfiguration : OK
XmlParserTest::testParseAsset : OK
XmlParserTest::testUpdateAsset : OK
XmlParserTest::testNoNamespace : OK
XmlParserTest::testFilteredDataItem : OK
XmlParserTest::testReferences : OK
XmlParserTest::testExtendedAsset : OK
XmlParserTest::testExtendedAssetFragment : OK
XmlParserTest::testParseOtherAsset : OK
XmlParserTest::testParseRemovedAsset : OK
XmlParserTest::testBadAsset31919 ERROR [0] xml.parser: XML: file://XXX.xml:1:
31919 ERROR [0] xml.parser: XML: parser
31919 ERROR [0] xml.parser: XML: error :
31919 ERROR [0] xml.parser: XML: Opening and ending tag mismatch: CuttingItem line 1 and CuttingItmems

31919 ERROR [0] xml.parser: XML: <PointAngle code="SIG" nominal="0">0</PointAngle></Measurements></CuttingItmems>

31919 ERROR [0] xml.parser: XML: ^

31919 ERROR [0] xml.parser: XML: file://XXX.xml:1:
31919 ERROR [0] xml.parser: XML: parser
31919 ERROR [0] xml.parser: XML: error :
31919 ERROR [0] xml.parser: XML: Opening and ending tag mismatch: CuttingItem line 1 and CuttingToolLifeCycle

31919 ERROR [0] xml.parser: XML: nominal="0">0</PointAngle></Measurements></CuttingItmems></CuttingToolLifeCycle>

31919 ERROR [0] xml.parser: XML: ^

31919 ERROR [0] xml.parser: XML: file://XXX.xml:1:
31919 ERROR [0] xml.parser: XML: parser
31919 ERROR [0] xml.parser: XML: error :
31919 ERROR [0] xml.parser: XML: Opening and ending tag mismatch: CuttingItem line 1 and CuttingTool

31919 ERROR [0] xml.parser: XML: /PointAngle></Measurements></CuttingItmems></CuttingToolLifeCycle></CuttingTool>

31919 ERROR [0] xml.parser: XML: ^

31919 ERROR [0] xml.parser: XML: file://XXX.xml:1:
31919 ERROR [0] xml.parser: XML: parser
31919 ERROR [0] xml.parser: XML: error :
31919 ERROR [0] xml.parser: XML: Premature end of data in tag CuttingItems line 1

31919 ERROR [0] xml.parser: XML: /PointAngle></Measurements></CuttingItmems></CuttingToolLifeCycle></CuttingTool>

31919 ERROR [0] xml.parser: XML: ^

31919 ERROR [0] xml.parser: XML: file://XXX.xml:1:
31919 ERROR [0] xml.parser: XML: parser
31919 ERROR [0] xml.parser: XML: error :
31919 ERROR [0] xml.parser: XML: Premature end of data in tag CuttingToolLifeCycle line 1

31919 ERROR [0] xml.parser: XML: /PointAngle></Measurements></CuttingItmems></CuttingToolLifeCycle></CuttingTool>

31919 ERROR [0] xml.parser: XML: ^

31919 ERROR [0] xml.parser: XML: file://XXX.xml:1:
31919 ERROR [0] xml.parser: XML: parser
31919 ERROR [0] xml.parser: XML: error :
31919 ERROR [0] xml.parser: XML: Premature end of data in tag CuttingTool line 1

31919 ERROR [0] xml.parser: XML: /PointAngle></Measurements></CuttingItmems></CuttingToolLifeCycle></CuttingTool>

31919 ERROR [0] xml.parser: XML: ^
31919 ERROR [0] xml.parser: Cannot parse asset XML, Unknown execption occurred
 : OK
XmlPrinterTest::testPrintError : OK
XmlPrinterTest::testPrintProbe : OK
XmlPrinterTest::testPrintCurrent : OK
XmlPrinterTest::testPrintSample : OK
XmlPrinterTest::testCondition : OK
XmlPrinterTest::testVeryLargeSequence : OK
XmlPrinterTest::testChangeDeviceAttributes : OK
XmlPrinterTest::testChangeDevicesNamespace : OK
XmlPrinterTest::testChangeStreamsNamespace : OK
XmlPrinterTest::testChangeErrorNamespace : OK
XmlPrinterTest::testStatisticAndTimeSeriesProbe : OK
XmlPrinterTest::testTimeSeries : OK
XmlPrinterTest::testNonPrintableCharacters : OK
XmlPrinterTest::testPrintAsset : OK
XmlPrinterTest::testPrintAssetProbe : OK
XmlPrinterTest::testConfiguration : OK
XmlPrinterTest::testPrintCuttingTool : OK
XmlPrinterTest::testChangeVersion : OK
XmlPrinterTest::testChangeMTCLocation : OK
XmlPrinterTest::testProbeWithFilter : OK
XmlPrinterTest::testReferences : OK
XmlPrinterTest::testPrintExtendedCuttingTool : OK
XmlPrinterTest::testStreamsStyle : OK
XmlPrinterTest::testDevicesStyle : OK
XmlPrinterTest::testErrorStyle : OK
XmlPrinterTest::testAssetsStyle : OK
XmlPrinterTest::testPrintRemovedCuttingTool : OK
XmlPrinterTest::testEscapedXMLCharacters : OK
AssetTest::testAsset : OK
ChangeObserverTest::testAddObserver : OK
ChangeObserverTest::testSignalObserver : OK
ChangeObserverTest::testChangeSequence : OK
ChangeObserverTest::testChangeSequence2 : OK
ChangeObserverTest::testCleanup : OK
CuttingToolTest::testCuttingTool : OK
OK (200)

Setting up MTConnect C++ Agent

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s