<< to CrossControl homepage

Support & Service Center

Data Engine access from CoDeSys

Printer-friendly versionPrinter-friendly versionPDF versionPDF version

To connect your CoDeSys application to Data Engine, the CCSAP library must be installed from CoDeSys _linx_sdk.projectarchive in your IDE.

The included example at the bottom of this page is default compiled for an arm (XA/XS/VC) device. To be able to run on x86 (XM/XM2) you need to change the device descriptor file in the project accordingly.

Add the following code to your application (see the included CoDeSys_DataEngine_Example):

// SAP DataEngine Connection and Signal Setup //
 
IF connect THEN
 
	// Connect to DataEngineServer
	// Submit our clientName and ip address with 
	// port to the device running Data Engine
	sapConnect ( name:='t_CoDeSys', 
                host:='10.131.16.94', 
                port:=4661);
 
	// Subscribe to sync signal
	// Syncsignals swaps between 1 and 0 every 
	// 1s indicating an alive connection.
	sapSubscribe ( name := clientName, 
            dataType := DATATYPE_SYNC, 
            signalType := SIGNAL_CONSUMER,
            persist := FALSE,
            valuePointer := ADR (CoDeSys) );
 
	// Subscribe to boolean "signal1" as consumer. 
	// Value not stored in dB. Add value to our 
	//Global Variable (SAP_Variables) signal1.	
	sapSubscribe ( name := 'signal1',
            dataType := DATATYPE_BOOL,
            signalType := SIGNAL_CONSUMER,
            persist := FALSE,
            valuePointer := ADR ( signal1 ) );
 
	// Subscribe to char variable "signal2" as one 
	// of many producer.
	// Value not stored in dB. Add value to our 
	// Global Variable (SAP_Variables) signal2.				 
	sapSubscribe ( name:='signal2',
            dataType := DATATYPE_CHAR,
            signalType := SIGNAL_MANYPRODUCER,
            persist := FALSE,
            valuePointer := ADR (signal2) );
 
	connect := FALSE;
END_IF
 
IF disconnect THEN
	sapDisconnect ();
	disconnect := FALSE;
	//CoDeSys := 0;
END_IF
After this initialisation, you can access the different signals as normal variables. Any updates in the Data Engine will directly change the variable value, and any change of the variables will be transmitted to the data engine. Example:
signal2 := BOOL_TO_DINT(signal1)*2+CoDeSys*3;
Environment and Versions: 

CoDeSys Version 3.5.x and higher
Data Engine Version 2.0.9 and higher


whatever