• Home
  • Raspberry Pi
  • Codesys eCockpit
  • Python
  • Docker
  • Embedded Programming
Brighter Side Tech
  • Home
  • Raspberry Pi
  • Codesys eCockpit
  • Python
  • Docker
  • Embedded Programming
No Result
View All Result
  • Home
  • Raspberry Pi
  • Codesys eCockpit
  • Python
  • Docker
  • Embedded Programming
No Result
View All Result
Brighter Side Tech
No Result
View All Result
Home Codesys eCockpit

Codesys / e!Cockpit Modbus TCP Master Implementation

Mwesigwa Peter by Mwesigwa Peter
April 22, 2023
in Codesys eCockpit
0
Codesys / e!Cockpit Modbus TCP Master Implementation

Codesys / e!Cockpit Modbus TCP Master Implementation

0
SHARES
988
VIEWS
Share on FacebookShare on Twitter

MODBUS TCP/IP is a communication implementation under the MODBUS family. The protocol makes use of MODBUS messaging in an Internet like type of environment using the TCP/IP protocols. The implementation below is a Modbus TCP communication using the Ethernet Frame.

Introduction

Install the Modbus Library in the codesys or e!Cockpit Library Environment

We use the FbMbMasterTCP function to implement the Modbus TCP on the Master Device

Declare the function input and output variables and create the Modbus Object

PROGRAM Modbus
VAR
	// INPUTS
	ModbusTCPMaster : FbMbMasterTCP;
	xConnect : BOOL := TRUE;
	Host : STRING := '10.1.3.8'; // IP OF the remote server
	Port : WORD := 2000; // port at the remote server
	KeepAlive : typKeepAlive ;
	FrameType : eMbFrameType:= eMbFrameType.ETHERNET;
	TimeOut : TIME := T#1S;
	Query : typMbQuery;
	xTrigger : BOOL; (* Set this variable once for start a job.
                                           This variable will be automaticly reset            by the master
                                           if the job is done.
                                        *)

	Response : typMbResponse; (* After the job is done you can find at this structure
                                           the result.
                                        *)
	
	// OUTPUTS
	Open : BOOL;
	xError : BOOL;
	Status : FbResult;
	
	// supporting variables
	Blink : FbBlinker;
	ConfigBlinker: typConfigBlinker;
END_VAR

Object definition

// KEEP ALIVE
KeepAlive.xEnable:= TRUE; // use keep alive
KeepAlive.tMaxIdleTime := T#5S;  //  Maximum time of inactivity
KeepAlive.tInterval := T#2S; //  Interval between two successive KA-Packets
KeepAlive.udiProbes := 5; //  Number of KA retry before giving up


// QUERY
Query.bUnitId := 1; // Slave address
Query.bFunctionCode := 16#03; // read holding registers
Query.uiReadAddress := 0; // Start address
Query.uiReadQuantity := 10; // Quantity of wanted registers
Query.uiWriteAddress := 0;
Query.uiWriteQuantity := 0;


// blinker
ConfigBlinker.tTimeHigh := T#1S;
ConfigBlinker.tTimeLow := T#3S;
Blink(xEnable := TRUE, typConfigParameters :=ConfigBlinker, xOutput => xTrigger);


// define modbus object
ModbusTCPMaster(  
		xConnect    := xConnect,
                sHost       := Host,  // IP of the remote server
                wPort       := Port,             // port at the remote server
		utKeepAlive := KeepAlive,
		eFrameType  := FrameType,
                tTimeOut    := TimeOut,
		utQuery     := Query,
                xTrigger    := xTrigger,
                utResponse  := Response, 
		xIsOpen     => Open, 
		xError 	    => xError, 
		oStatus     => Status
              );

e!Cockpit

Previous Post

Remote desktop control not working with xrdp Linux

Next Post

Introduction to GitHub – Git Commands

Mwesigwa Peter

Mwesigwa Peter

Related Posts

Parsing JSON Data in Codesys
Automation

Parsing JSON Data in Codesys

Parsing JSON Data in Codesys is quite an important operation especially when exchanging data over the REST API. The data...

by Mwesigwa Peter
January 25, 2025
TCP Socket Client Implementation in Codesys
Codesys eCockpit

TCP Socket Client Implementation in Codesys

This is a TCP socket client implementation in codesys to run on your PLC and connect to any TCP Socket...

by Mwesigwa Peter
January 11, 2024
Next Post
Introduction to GitHub - Git Commands

Introduction to GitHub - Git Commands

Parsing JSON Data in Codesys
Automation

Parsing JSON Data in Codesys

by Mwesigwa Peter
January 25, 2025
0

Parsing JSON Data in Codesys is quite an important operation especially when exchanging data over the REST API. The data...

Read moreDetails
Configure Raspberry Pi Serial ports as COM ports for Codesys Runtime

Configure Raspberry Pi Serial ports as COM ports for Codesys Runtime

October 7, 2024
ARM error: no member named ‘IP’ in ‘NVIC_Type’ Solved

ARM error: no member named ‘IP’ in ‘NVIC_Type’ Solved

July 18, 2024
TCP Socket Client Implementation in Codesys

TCP Socket Client Implementation in Codesys

January 11, 2024
Modbus TCP Master Simulator

Modbus TCP Master Simulator Tool – Free Download

October 14, 2023
Parsing JSON Data in Codesys

Parsing JSON Data in Codesys

by Mwesigwa Peter
January 25, 2025
0

Parsing JSON Data in Codesys is quite an important operation especially when exchanging data over the REST API. The data...

Configure Raspberry Pi Serial ports as COM ports for Codesys Runtime

Configure Raspberry Pi Serial ports as COM ports for Codesys Runtime

by Mwesigwa Peter
October 7, 2024
0

Introduction Codesys Runtime for Linux ARM SL allows you to program your Raspberry Pi according t the IEC 61131-6 standard...

ARM error: no member named ‘IP’ in ‘NVIC_Type’ Solved

ARM error: no member named ‘IP’ in ‘NVIC_Type’ Solved

by Mwesigwa Peter
July 18, 2024
0

This is how to solve the error: no member named 'IP' in 'NVIC_Type' Open the misc.c file : AppData\Local\Arm\Packs\Keil\STM32F1xx_DFP\2.4.1\Device\StdPeriph_Driver\src\misc.c, if you are...

TCP Socket Client Implementation in Codesys

TCP Socket Client Implementation in Codesys

by Mwesigwa Peter
January 11, 2024
0

This is a TCP socket client implementation in codesys to run on your PLC and connect to any TCP Socket...

About Brighterside Tech

Brighter Side Tech

As a hobbyist Engineer and Programmer , i love to share my learnings and solutions to technical challenges that i face during work and studying. My website gives me the ability to express my ideas and such solutions to the wider audience

Contact: admin@brightersidetech.com

Browse by Category

  • Automation
  • Codesys eCockpit
  • Docker
  • Embedded Programming
  • Python
  • Raspberry Pi
https://youtu.be/Lkrma5f60rs

Recent News

Parsing JSON Data in Codesys

Parsing JSON Data in Codesys

January 25, 2025
Configure Raspberry Pi Serial ports as COM ports for Codesys Runtime

Configure Raspberry Pi Serial ports as COM ports for Codesys Runtime

October 7, 2024
ARM error: no member named ‘IP’ in ‘NVIC_Type’ Solved

ARM error: no member named ‘IP’ in ‘NVIC_Type’ Solved

July 18, 2024
  • Home
  • Raspberry Pi
  • Codesys eCockpit
  • Python
  • Docker
  • Embedded Programming

© 2024 Brighterside Tech.

No Result
View All Result
  • Home
  • Raspberry Pi
  • Codesys eCockpit
  • Python
  • Docker
  • Embedded Programming

© 2024 Brighterside Tech.