Send robot position from a semi-static background task through socket communication
Hello,
I am trying to send robot position data [X,Y,Z] only through socket communication from a background task.
My procedure for setting up socket communication is as follows: (This is inside main() module)
I am trying to reference "server_socket" defined in main module of foreground task in background "robPos: task. I am getting a syntax error. Server_socket variable is not visible in scope of robPos task. How can i solve this?
I am trying to send robot position data [X,Y,Z] only through socket communication from a background task.
My procedure for setting up socket communication is as follows: (This is inside main() module)
PERS bool socketActive := FALSE; PROC Setup_Socket_Comm() ! WaitTime to delay start of client ! Sever application should start first WaitTime 5; SocketCreate server_socket; ! IP address of server/slave (PLC) is xxx.xxx.xxx.xxx SocketConnect server_socket,"xxx.xxx.xxx.xxx",1025; ! Communication start SocketSend server_socket\Str:="Hello PLC#"; SocketReceive server_socket\Str:=received_string; TPWrite "Server wrote - "+received_string; ! Set socket active flag socketActive:=TRUE; ! Error handler to make it possible to handle power fail ERROR IF ERRNO=ERR_SOCK_TIMEOUT THEN RETRY; ELSEIF ERRNO=ERR_SOCK_CLOSED THEN SocketClose server_socket; ! WaitTime to delay start of client. ! Server application should start first. WaitTime 10; SocketCreate server_socket; SocketConnect server_socket,"xxx.xxx.xxx.xxx",1025; RETRY; ELSE TPWrite "ERRNO = "\Num:=ERRNO; Stop; ENDIF ENDPROCI have created a new semi-static task called "robPos". Is it possible to reference a socket variable created in foreground task by a background semi-static task? My "robPos" task has following content:
MODULE robotPos ! Shared Global Persistant variables with tasks PERS bool socketActive:=FALSE; VAR num xpos; VAR num ypos; VAR num zpos; ! Socket comm VAR string received_string:=""; PROC main() sendRobPos; ENDPROC PROC sendRobPos() VAR pos currPos; VAR string str_x:=""; VAR string str_y:=""; VAR string str_z:=""; WHILE (socketActive := TRUE) DO ! Get current robot position currPos:=CPos(\Tool:=tool0\WObj:=wObj0); xpos:=currPos.x; ypos:=currPos.y; zpos:=currPos.z; !Dont forgetaddition of termination character (#) str_x:="x"+NumToStr(xpos,4)+"#"; str_y:="y"+NumToStr(ypos,4)+"#"; str_z:="z"+NumToStr(zpos,4)+"#"; SocketSend server_socket\Str:=str_x; SocketReceive server_socket\Str:=received_string;<br> IF (received_string="ack") THEN ! Ack recieved SocketSend server_socket\Str:=str_y;<br> SocketReceive server_socket\Str:=received_string;<br> IF (received_string="ack") THEN ! Ack recieved SocketSend server_socket\Str:=str_z;<br> SocketReceive server_socket\Str:=received_string;<br> IF (received_string="ack") THEN ! Ack recieved ! All good ENDIF ENDIF ENDIF ENDWHILE ENDPROC
I am trying to reference "server_socket" defined in main module of foreground task in background "robPos: task. I am getting a syntax error. Server_socket variable is not visible in scope of robPos task. How can i solve this?
Tagged:
0
Comments
-
I am curious as to the construction of the beginning of your WHILE instruction:
WHILE (socketActive := TRUE) DO
It is my understanding := means assign.
Are you sure you don't mean
WHILE socketActive=TRUE DO
?1 -
SomeTekk said:I am curious as to the construction of the beginning of your WHILE instruction:
WHILE (socketActive := TRUE) DO
It is my understanding := means assign.
Are you sure you don't mean
WHILE socketActive=TRUE DO
?
Can socket variables declared in another task used in a background task?0 -
Ought to be if they have the same name and are declared as PERS.Lee Justice0
-
lemster68 said:Ought to be if they have the same name and are declared as PERS.
This gives me an error when added to background task:PERS socketdev server_socket
it looks like it can only be declared as a variable
VAR socketdev server_socket
The manual says that socketdev is a non-value datatype
0 -
Oops! But anyway, why would you also need it in your main task if the background task is doing the job?Lee Justice0
-
lemster68 said:Oops! But anyway, why would you also need it in your main task if the background task is doing the job?
Is it possible to have two socket connections to same server (PLC) with same IP address but different ports? That might solve the problem
0 -
I think, just different socketdevs.Lee Justice0
-
lemster68 said:I think, just different socketdevs.
Manual says it is possible to have a max of 32 simultaneous socket devices at a time0
Categories
- All Categories
- 5.5K RobotStudio
- 394 UpFeed
- 18 Tutorials
- 13 RobotApps
- 297 PowerPacs
- 405 RobotStudio S4
- 1.8K Developer Tools
- 249 ScreenMaker
- 2.7K Robot Controller
- 309 IRC5
- 59 OmniCore
- 7 RCS (Realistic Controller Simulation)
- 785 RAPID Programming
- AppStudio
- 3 RobotStudio AR Viewer
- 18 Wizard Easy Programming
- 105 Collaborative Robots
- 4 Job listings