# Read data from array of robtargets

**URL:** <https://tech-community.robotics.abb.com/t/read-data-from-array-of-robtargets/7227>\
**Category:** RobotStudio\
**Tags:** array, socket, rapid, robtarget\
**Created:** [June 17, 2016, 4:27pm UTC](https://tech-community.robotics.abb.com/t/read-data-from-array-of-robtargets/7227 "2016-06-17T16:27:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![SteveMob](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/stevemob/32/1600_2.png) [@SteveMob](https://tech-community.robotics.abb.com/u/SteveMob)\
**Post date:** [June 17, 2016, 4:27pm UTC](https://tech-community.robotics.abb.com/t/read-data-from-array-of-robtargets/7227/1 "2016-06-17T16:27:19Z")

</div>

Hello,

I have an array of robtargets (Targets{6}). I am trying to read the position data from the targets and send those via Sockets.  
Here is a snippet of my code:  
**CONST robtarget Targets{6}:=[[…]]**  
**VAR num k:=1;**

**WHILE k\>=1 DO**  
**MoveJ Targets{k},v100,fine,ToolDataTest\WObj:=wobj0;**  
**sString:=ValToStr(Targets{k});**  
**SocketSend client\_socket\Str:=“\0A”+“\*”+sString;**  
**WaitTime 2;**  
**k:=k+1;**  
**ENDWHILE**

The problem I am having is first, it says the string is too large, because it is trying to read all the robtargets as 1 string. What I am wanting is for it to send the values for whatever value “k” is. So if the value is Targets{3}, it will send the declared values of Targets{3} only. If I use CPOS or CROBTT, it will read the actual robot values, but I want to read what the _commanded_ values are.  
Any ideas?

Thanks for any help,  
SM

---

<div class="post-metadata">

**Author:** ![PerSvensson](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/persvensson/32/1040_2.png) [@PerSvensson](https://tech-community.robotics.abb.com/u/PerSvensson)\
**Post date:** [June 18, 2016, 2:35pm UTC](https://tech-community.robotics.abb.com/t/read-data-from-array-of-robtargets/7227/2 "2016-06-18T14:35:15Z")

</div>

Be aware of that the string has a max length of 80 characters

---

<div class="post-metadata">

**Author:** ![John\_Verheij](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/john_verheij/32/1724_2.png) [@John\_Verheij](https://tech-community.robotics.abb.com/u/John_Verheij)\
**Post date:** [June 20, 2016, 6:48am UTC](https://tech-community.robotics.abb.com/t/read-data-from-array-of-robtargets/7227/3 "2016-06-20T06:48:59Z")

</div>

Besides the max length of a string, i do not know the consequence of sending “\0” through sockets. In some languages this act as string-terminator.

Another problem is your “while”-loop, it will never reach a stop-condition. Initial “k” is 1 and every iteration it will be increased with 1. So a better construction is the use of “Dim”.

```auto
FOR k FROM 1 TO Dim(Targets,1) DO
....
ENDFOR

```

---

<div class="post-metadata">

**Author:** ![SteveMob](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/stevemob/32/1600_2.png) [@SteveMob](https://tech-community.robotics.abb.com/u/SteveMob)\
**Post date:** [June 20, 2016, 4:16pm UTC](https://tech-community.robotics.abb.com/t/read-data-from-array-of-robtargets/7227/4 "2016-06-20T16:16:52Z")

</div>

Thanks for the reply guys!

John, like I said, this was only a snippet of my code. I had the “k” reset once it reached the end of the array. But I like the way you did it better, so I will change my code to use the “Dim” and FOR loop.

In the case that anyone else ever tries to do this, what I did was just grab the individual elements of the target, and packed those separately into raw bytes:

**sCommTrans:=“Commanded:”+" Position:“+ValToStr(Targets{k}.trans)+”,";**  
**PackRawBytes sCommTrans,message,(RawBytesLen(message)+1)\ASCII;**  
**sCommQuat:=" Quaternions:“+ValToStr(Targets{k}.rot)+”,";**  
**PackRawBytes sCommQuat,message,(RawBytesLen(message)+1)\ASCII;**  
**nComm\_anglex:=EulerZYX(\X,Targets{k}.rot);**  
**nComm\_angley:=EulerZYX(\Y,Targets{k}.rot);**  
**nComm\_anglez:=EulerZYX(\Z,Targets{k}.rot);**  
**sComm\_Rotationx:=NumToStr(nComm\_anglex,6);**  
**sComm\_Rotationy:=NumToStr(nComm\_angley,6);**  
**sComm\_Rotationz:=NumToStr(nComm\_anglez,6);**  
**sCommEuler:=" Euler:“+”[“+sComm\_Rotationx+”,“+sComm\_Rotationy+”,“+sComm\_Rotationz+”]“+”,";**  
**PackRawBytes sCommEuler,message,(RawBytesLen(message)+1)\ASCII;**  
**SocketSend client\_socket\RawData:=message;**

Thanks for the help everybody!

SM
