# IRC5 to B&R CPU - TCP IP data transfer

**URL:** <https://tech-community.robotics.abb.com/t/irc5-to-b-r-cpu-tcp-ip-data-transfer/10860>\
**Category:** RobotStudio\
**Tags:** socket-communication, array, tcp-ip, communication, help\
**Created:** [September 5, 2022, 12:46pm UTC](https://tech-community.robotics.abb.com/t/irc5-to-b-r-cpu-tcp-ip-data-transfer/10860 "2022-09-05T12:46:00Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![JVDK\_DBM](https://avatars.discourse-cdn.com/v4/letter/j/a87d85/32.png) [@JVDK\_DBM](https://tech-community.robotics.abb.com/u/JVDK_DBM)\
**Post date:** [September 5, 2022, 12:46pm UTC](https://tech-community.robotics.abb.com/t/irc5-to-b-r-cpu-tcp-ip-data-transfer/10860/1 "2022-09-05T12:46:00Z")

</div>

I have a question regarding the TCP IP communication between a IRC5 (Client) and a B&R CPU (Server).

The B&R Server is sending an UDINT array containing some cordinates and status bits. This being my first TCP IP and kind of my first real Robotstudio program, I’m having a hard time working out the details.

Is receiving an UDINT array in Robotstudio as simple as just converting the rawdata to udint array?

Following code is what I have setup right now regarding the TCP Client.  
//-------------------------------------------------------------

MODULE TCP\_Client

PERS dnum TransferData\_ToRobot {24};  
PERS dnum TransferData\_FromRobot {47};

VAR socketdev ClientSocket;  
VAR socketstatus SocketStat;  
VAR rawbytes raw\_send;  
VAR rawbytes raw\_receive;

VAR bool diComms\_Alive;  
VAR num diForceStop;  
VAR num doCommsError;

PROC Main()  
VAR signaldi PLCAlive;  
AliasIO diComms\_Alive, PLCAlive;

!wait for plc to run  
WHILE PLCAlive = 0 DO  
WaitTime 5;  
set doCommsError;  
IF (diForceStop = 1) Stop; !force stop prog execution from pendant. diforcestop is on virtual\_1 unit  
ENDWHILE

!reset error  
Reset doCommsError;

!clear raw data  
ClearRawBytes raw\_send;  
ClearRawBytes raw\_receive;

SocketClose ClientSocket;

!get client socket status  
SocketStat := SocketGetStatus(ClientSocket);  
WHILE NOT (SocketStat = SOCKET\_CONNECTED) DO

WaitTime 2; !wait time before closing socket  
SocketClose ClientSocket;  
WaitTime 2; ! wait time before opening socket

IF (PLCAlive = 0) ExitCycle; !plc not running - wait for plc to come online

ConnectToServer “10.30.1.11”, 1025; !connect to server addr and port no  
SocketStat := SocketGetStatus(ClientSocket); !update client socket status

ENDWHILE

WHILE (SocketStat = SOCKET\_CONNECTED) DO

IF (PLCAlive = 0) ExitCycle; !plc not running - wait for plc to come online

SendData;  
ReceiveData;

ENDWHILE  
ENDPROC

PROC ConnectToServer(string IPAddress, num PortNo)

VAR num RetryNo := 0;

SocketCreate ClientSocket; !create client socket  
SocketConnect ClientSocket, IPAddress, PortNo; !connect to server with ip addr and portno supplied  
TPErase;  
TPWrite “Connection succesfull”;

ERROR  
IF ERRNO = ERR\_SOCK\_TIMEOUT THEN  
WaitTime 1;  
RetryNo := RetryNo + 1;  
IF RetryNo \>= 3 THEN  
ErrWrite\I, “Connection failed”, "Trying to connect to server failed. " \RL2 := "PP Goed to Main to check if PLC Alive. " \RL3 := “Retries is reset.”;  
TPWrite “Socket connection failed after 3 retries”;  
RetryNo := 0;  
WaitTime 5;  
ExitCycle;  
ELSE  
RETRY;  
ENDIF

ELSEIF ERRNO = ERR\_SOCK\_CLOSED THEN  
WaitTime 5;  
ExitCycle;  
ELSE  
TPWrite "ERRNO = " \Num:=ERRNO;  
Stop;  
ENDIF  
ENDPROC

PROC SendData()

ClearRawBytes raw\_send; !clear raw data

!prep data to send  
packet\_send.x := packet\_receive.x;  
packet\_send.y := packet\_receive.y;  
packet\_send.z := packet\_receive.z;  
!etc etc

!pack pieces of data in the packet into raw\_send  
PackRawBytes packet\_send.x, raw\_send, (RawBytesLen(raw\_send)+1)\Float4;  
PackRawBytes packet\_send.y, raw\_send, (RawBytesLen(raw\_send)+1)\Float4;  
PackRawBytes packet\_send.z, raw\_send, (RawBytesLen(raw\_send)+1)\Float4;

SocketSend ClientSocket \RawData := raw\_send;

ERROR  
IF ERRNO = ERR\_SOCK\_CLOSED THEN  
TPWrite “Socket closed during sending data”;  
ExitCycle;  
ENDIF  
ENDPROC

PROC ReceiveData()  
ClearRawBytes raw\_receive; !clear raw data

SocketReceive ClientSocket \RawData := raw\_receive\Time := 10;

!unpack raw\_receive and save individual values in packet\_receive  
UnpackRawBytes raw\_receive, 1, packet\_receive.x \Float4;  
UnpackRawBytes raw\_receive, 5, packet\_receive.y \Float4;  
UnpackRawBytes raw\_receive, 9, packet\_receive.z \Float4;

SocketStat := SocketGetStatus(ClientSocket); !update status of client socket

ERROR  
IF ERRNO = ERR\_SOCK\_TIMEOUT OR ERRNO = ERR\_SOCK\_CLOSED THEN  
WaitTime 5; !wait to make sure server is started first  
TPWrite “Comms time out during receiving data”;  
ExitCycle;  
ENDIF  
ENDPROC

ENDMODULE

//-------------------------------------------------------------  
Any help would be appreciated!

---

<div class="post-metadata">

**Author:** ![graemepaulin](https://avatars.discourse-cdn.com/v4/letter/g/258eb7/32.png) [@graemepaulin](https://tech-community.robotics.abb.com/u/graemepaulin)\
**Post date:** [September 5, 2022, 7:38pm UTC](https://tech-community.robotics.abb.com/t/irc5-to-b-r-cpu-tcp-ip-data-transfer/10860/2 "2022-09-05T19:38:40Z")

</div>

So you have the TCP-IP communications established between between the controller and the B&R?

From there you can send individual bytes for the X, Y, Z values - these are setup at the controller end a a group input (or output) of the appropriate length.  
This is setup in the EIO configuration file - the system parameters help in RobotStudio will give all the details you need.  
The status bits are setup as individual signals.

This way the values are updated automatically with no send and receive code required at the robot end…

---

<div class="post-metadata">

**Author:** ![JVDK\_DBM](https://avatars.discourse-cdn.com/v4/letter/j/a87d85/32.png) [@JVDK\_DBM](https://tech-community.robotics.abb.com/u/JVDK_DBM)\
**Post date:** [September 6, 2022, 2:10pm UTC](https://tech-community.robotics.abb.com/t/irc5-to-b-r-cpu-tcp-ip-data-transfer/10860/3 "2022-09-06T14:10:44Z")

</div>

Thanks for your reply @graemepaulin!

I have a working connection with the B&R CPU.

The datatypes still aren’t completly clear to me;  
Are the X,Y,Z send individually or as packets combined with the status bits?  
Also, do I need to reprogram the send packets (B&R end) to the individual bytes as well or can I unpack the UDINT array in the rapid code?

By “updated automatically with no send and receive code” do you mean I only have to open the socket connection and the values will be collected automatically by the controller it self?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![graemepaulin](https://avatars.discourse-cdn.com/v4/letter/g/258eb7/32.png) [@graemepaulin](https://tech-community.robotics.abb.com/u/graemepaulin)\
**Post date:** [September 7, 2022, 10:24pm UTC](https://tech-community.robotics.abb.com/t/irc5-to-b-r-cpu-tcp-ip-data-transfer/10860/4 "2022-09-07T22:24:51Z")

</div>

If the B&R updates the byte or bit of information it is ‘sent’ directly to the controller and the new value is immediately available for use in the controller.  
You setup individual bytes (8, 16, 32, etc bits long to suit the data being sent) for the x, y, z.  
The status bits are just single bits.

Yes you will need to change your B&R program to update the individual bytes & bits.  
It should be more flexible code as you only update the information required when required…

---

<div class="post-metadata">

**Author:** ![JVDK\_DBM](https://avatars.discourse-cdn.com/v4/letter/j/a87d85/32.png) [@JVDK\_DBM](https://tech-community.robotics.abb.com/u/JVDK_DBM)\
**Post date:** [September 14, 2022, 8:16am UTC](https://tech-community.robotics.abb.com/t/irc5-to-b-r-cpu-tcp-ip-data-transfer/10860/5 "2022-09-14T08:16:13Z")

</div>

> [@graemepaulin](#):
>
> If the B&R updates the byte or bit of information it is ‘sent’ directly to the controller and the new value is immediately available for use in the controller.  
> You setup individual bytes (8, 16, 32, etc bits long to suit the data being sent) for the x, y, z.  
> The status bits are just single bits.
> 
> Yes you will need to change your B&R program to update the individual bytes & bits.  
> It should be more flexible code as you only update the information required when required…

The B&R updates the internal values everytime there is new data sent to it from one of the clients. If I’m understanding you correctly, the following code won’t be necessary as the controller will retrieve the values automatically; _PackRawBytes FromRobot1.ActualPos.X, raw\_send, (RawBytesLen(raw\_send)+1)\Float4;_

---

<div class="post-metadata">

**Author:** ![JVDK\_DBM](https://avatars.discourse-cdn.com/v4/letter/j/a87d85/32.png) [@JVDK\_DBM](https://tech-community.robotics.abb.com/u/JVDK_DBM)\
**Post date:** [September 14, 2022, 8:30am UTC](https://tech-community.robotics.abb.com/t/irc5-to-b-r-cpu-tcp-ip-data-transfer/10860/6 "2022-09-14T08:30:59Z")

</div>

It’s still quite unclear to me how this whole structure and code would need to be set up. It’s kind of my first robotstudio program so bear with me please :smile:

Preferably I would like to just send and receive whole packets like the records I’ve made seeing they are quite big;  
_RECORD ToRob_  
_num AliveCounter;_  
_num FoundPiece;_  
_ResultPointType ResultPoint1; !\*-----x,y,z,alpha,beta,gamma  
 ResultPointType ResultPoint2;  
\*CommandType Command; !-----_ _16 booleans_  
_SpareInt9Type SpareInt; !\*\*-----_ _9 int’s_  
_ENDRECORD_

_RECORD FromRob_  
_num AliveCounter;_  
_Rob\_ActivePosType Rob1\_ActivePos; !----- x,y,z_  
_Rob\_ActivePosType Rob2\_ActivePos;_  
_Rob\_StatusType Rob1\_Status;_ _!\*\*-----_ _1 num & 31 error booleans_  
_Rob\_StatusType Rob2\_Status;_  
_StatusType Status; !\*\*-----_ _2 int’s_  
_SpareInt8Type SpareInt; !\*\*-----_ _8 int’s_  
_ENDRECORD_

---

<div class="post-metadata">

**Author:** ![graemepaulin](https://avatars.discourse-cdn.com/v4/letter/g/258eb7/32.png) [@graemepaulin](https://tech-community.robotics.abb.com/u/graemepaulin)\
**Post date:** [September 14, 2022, 10:02am UTC](https://tech-community.robotics.abb.com/t/irc5-to-b-r-cpu-tcp-ip-data-transfer/10860/7 "2022-09-14T10:02:25Z")

</div>

Correct if you setup a byte for each no code necessary for the data transmission, only to use the data.

---

<div class="post-metadata">

**Author:** ![JVDK\_DBM](https://avatars.discourse-cdn.com/v4/letter/j/a87d85/32.png) [@JVDK\_DBM](https://tech-community.robotics.abb.com/u/JVDK_DBM)\
**Post date:** [September 14, 2022, 11:20am UTC](https://tech-community.robotics.abb.com/t/irc5-to-b-r-cpu-tcp-ip-data-transfer/10860/8 "2022-09-14T11:20:08Z")

</div>

> [@graemepaulin](#):
>
> Correct if you setup a byte for each no code necessary for the data transmission, only to use the data.

Could you show me an example of a correctly setup byte. I reckon it should be connected to a TCP IP IO Device??

---

<div class="post-metadata">

**Author:** ![graemepaulin](https://avatars.discourse-cdn.com/v4/letter/g/258eb7/32.png) [@graemepaulin](https://tech-community.robotics.abb.com/u/graemepaulin)\
**Post date:** [September 15, 2022, 6:06am UTC](https://tech-community.robotics.abb.com/t/irc5-to-b-r-cpu-tcp-ip-data-transfer/10860/9 "2022-09-15T06:06:37Z")

</div>

![image.jpg](https://europe1.discourse-cdn.com/flex005/uploads/robotics1/original/2X/7/703ba25c9d372df939d8b30c4adfc471351e4ec2.jpeg)  
This is for a Fronius welder.  
You do not need to have the Category.
