Reference Design Content

Showing results for 
Search instead for 
Did you mean: 

Microsoft Visual C++ Client Reference Example for Simple Messaging (STM)


The attached file contains a client implementation of STM in Microsoft Visual Studio 2010 and an example of its use. This example does not implement a server for STM connections, although much of the code can be re-used for a server implementation.




The Visual C++ code was written in Microsoft Visual Studio 2010.  Much of the code can be converted to other MS VC++ versions with minimal effort.


Example Description


The attached example contains the following:


VC++ STM Client Folder

This folder contains the VC++ STM implementation as well as an example of its use.  


The following files are significant:

STMSession.h and STMSession.cpp

These files implement the STMSession Class, which implements the main STM communication.  This class is directly used to connect to the server, disconnect from the server, and send messages.  The class also provides messages via a STMDispatch object.


STMDispatch.h and STMDispatch.cpp

These files implement the STMDispatch Class, which provides notifications to the application when STM communication events occur.  To define handlers for these messages, inherit from this class and overload the associated functions.  This class allows you to receive notification of a successful connection, the loss of a connection, the receipt of meta data, the receipt of any data on the STM socket, the receipt of an STM message, a successfully transmitted message and/or a connection error.  To register for notifications, you should call the STMSession:: SetDispatch function and pass an object of a class that inherits from STMDispatch.


STMConvert.h and STMConvert.cpp

These files provide a number of functions which help you to encode and decode data into a format acceptable by LabVIEW.  This is called flattening and unflattening.  Note that not all possible data types are implemented. If you need a data type that isn't available, use the provided functions as a guide and the refer to Flattened Data for the data format.


STMExample.h, STMExample.cpp, STMExampleDlg.h, and STMExampleDlg.cpp

These files implement an example of using STMSession and STMDispatch to communicate with an STM server.


LV Server Folder

This folder contains a LabVIEW server designed to communicate with the C++ example client.  The example is a CompactRIO system that acts as a server for multiple STM clients.  The cRIO streams analog waveforms from a cRIO module, scans digital inputs, updates digital outputs, and transfers a cluster of system status information.  This example is a good test for the C++ implementation as it uses multiple data types, arrays, and clusters in its STM messages.




Please submit your feedback and questions on this example in the STM discussion forum. General product support questions should be directed to NI Technical Support.

authored by
Christian L, CLA
Systems Engineering Manager - Automotive and Transportation
NI - Austin, TX