RobotStudio communication with TiaPortal via socket
in RobotStudio
Hello.
I need some help with project.
I have to make communication between Tiaportal V14 and RobotStudio using TCP/IP. Does anybody some experiences with this?
Thanks for help.
I need some help with project.
I have to make communication between Tiaportal V14 and RobotStudio using TCP/IP. Does anybody some experiences with this?
Thanks for help.
Tagged:
0
Comments
-
Hi,
I have done socket connection with Rockwell PLC once and below is how I did it (in a separate SemiStatic task). I reckon it should be the same since it's the same protocol. I am not sure on the TIAPortal side but I believe you have to have the GSD file for IRC5 to recognise the controller on the network.MODULE MainModuleVAR socketdev clientSocket;VAR socketstatus socketStat;VAR rawbytes raw_send;VAR rawbytes raw_receive;PROC main()VAR signaldi plcAlive;AliasIO diComms_Alive,plcAlive;! Eternal loop to wait until PLC is ONWHILE plcAlive=0 DOWaitTime 5;Set doCommsError;IF (diForceStop=1) Stop; ! Force stop prog execution from pendant. diForceStop is on Virtual_1 unitENDWHILE! Reset errorReset doCommsError;! Clear raw bytesClearRawBytes raw_send; ! Clear raw data firstClearRawBytes raw_receive; ! Clear raw data firstSocketClose clientSocket;socketStat:=SocketGetStatus(clientSocket); ! Get status of client socket & act accordinglyWHILE NOT(socketStat=SOCKET_CONNECTED) DOWaitTime 2; ! Recommended wait time before closing a socketSocketClose clientSocket;WaitTime 2; ! Recommended wait time between closing & opening a socketIF (plcAlive=0) ExitCycle; ! Go to eternal loop to wait until PLC is back ONconnectToServer "192.168.1.1",1025; ! Connect to server by address and port no. in argumentssocketStat:=SocketGetStatus(clientSocket); ! Update status of client socketENDWHILEWHILE (socketStat=SOCKET_CONNECTED) DOIF (plcAlive=0) ExitCycle; ! Go to eternal loop to wait until PLC is back ON!WaitTime 1;sendData;!WaitTime 1;receiveData;ENDWHILEENDPROCPROC connectToServer(string IPAddress,num portNo)VAR num retryNo:=0;SocketCreate clientSocket; ! Create client socketSocketConnect clientSocket,IPAddress,portNo; ! Connect to server with IPAddress and portNo suppliedTPErase;TPWrite "Connection successful";ERRORIF ERRNO=ERR_SOCK_TIMEOUT THENWaitTime 1;retryNo:=retryNo+1;IF retryNo>=3 THENErrWrite\I, "Connection failed", "Trying to connect to server (PLC) failed."\RL2:="PP goes to Main to check if PLC alive."\RL3:="Retries is reset.";TPWrite "Socket connection failed after 3 retries";retryNo:=0;WaitTime 5;ExitCycle;ELSERETRY;ENDIFELSEIF ERRNO=ERR_SOCK_CLOSED THENWaitTime 5;ExitCycle;ELSETPWrite "ERRNo = "\Num:=ERRNO;Stop;ENDIFENDPROCPROC sendData()ClearRawBytes raw_send; ! Clear raw data first! Prep data to sendpacket_send.x:=packet_receive.x;packet_send.y:=packet_receive.y;packet_send.z:=packet_receive.z;packet_send.Rx:=packet_receive.Rx;packet_send.Ry:=packet_receive.Ry;packet_send.Rz:=packet_receive.Rz;packet_send.Status:=packet_receive.Status;! Pack pieces of data in the packet into raw_sendPackRawBytes 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;PackRawBytes packet_send.Rx,raw_send,(RawBytesLen(raw_send)+1)\Float4;PackRawBytes packet_send.Ry,raw_send,(RawBytesLen(raw_send)+1)\Float4;PackRawBytes packet_send.Rz,raw_send,(RawBytesLen(raw_send)+1)\Float4;PackRawBytes packet_send.Status,raw_send,(RawBytesLen(raw_send)+1)\IntX:=1;SocketSend clientSocket \RawData:=raw_send;ERRORIF ERRNO=ERR_SOCK_CLOSED THENTPWrite "Socket closed during sending data";ExitCycle;ENDIFENDPROCPROC receiveData()ClearRawBytes raw_receive; ! Clear raw data firstSocketReceive clientSocket \RawData:=raw_receive\Time:=10;! Unpack raw_receive and save individual values in packet_receiveUnpackRawBytes raw_receive,1,packet_receive.x\Float4;UnpackRawBytes raw_receive,5,packet_receive.y\Float4;UnpackRawBytes raw_receive,9,packet_receive.z\Float4;UnpackRawBytes raw_receive,13,packet_receive.Rx\Float4;UnpackRawBytes raw_receive,17,packet_receive.Ry\Float4;UnpackRawBytes raw_receive,21,packet_receive.Rz\Float4;UnpackRawBytes raw_receive,25,packet_receive.Status\IntX:=1;socketStat:=SocketGetStatus(clientSocket); ! Update status of client socketERRORIF ERRNO = ERR_SOCK_TIMEOUT OR ERRNO=ERR_SOCK_CLOSED THENWaitTime 5; ! Wait so server application starts firstTPWrite "Comms time out during receiving data";ExitCycle;ENDIFENDPROCENDMODULE
0 -
Hello,
For SIEMENS, You've got RSConnectGIOToSnap7 and RSConnectDIOToSnap7
https://robotapps.robotstudio.com/#/viewApp/2cab7b4f-754c-415b-a32c-cbe4da9353e9
https://robotapps.robotstudio.com/#/viewApp/8f0eb633-db8c-4155-85f5-4910b894c520
☑️2024 - RobotStudio® User Group0
Categories
- All Categories
- 5.5K RobotStudio
- 396 UpFeed
- 18 Tutorials
- 13 RobotApps
- 297 PowerPacs
- 405 RobotStudio S4
- 1.8K Developer Tools
- 250 ScreenMaker
- 2.8K Robot Controller
- 316 IRC5
- 61 OmniCore
- 7 RCS (Realistic Controller Simulation)
- 800 RAPID Programming
- AppStudio
- 3 RobotStudio AR Viewer
- 18 Wizard Easy Programming
- 105 Collaborative Robots
- 5 Job listings