Indexing arrays
SteveMob
✭
Hello,
I am sending a bunch of rawbytes via sockets. I am trying to get the number of bytes (i.e. length of message in bytes) and send them at the beginning of the data. This is a snippet of my code:
VAR rawbytes message;
ClearRawBytes message\FromIndex:=1;
PackRawBytes sync,message,(RawBytesLen(message)+1)\INTX:=UDINT;
PackRawBytes messagenum,message,(RawBytesLen(message)+1)\INTX:=UDINT;
.......
lengthmsg:=RawBytesLen(message)+4;
Slengthmsg:=" Message length,"+ValToStr(lengthmessage);
PackRawBytes slengthmessage,message,(RawBytesLen(message)+1)\ASCII;
SocketSend client_socket\RawData:=message;
How can I index the array (message) such that the length of the data is at the beginning of the message instead of at the end?
Thanks for any help,
SM
I am sending a bunch of rawbytes via sockets. I am trying to get the number of bytes (i.e. length of message in bytes) and send them at the beginning of the data. This is a snippet of my code:
VAR rawbytes message;
ClearRawBytes message\FromIndex:=1;
PackRawBytes sync,message,(RawBytesLen(message)+1)\INTX:=UDINT;
PackRawBytes messagenum,message,(RawBytesLen(message)+1)\INTX:=UDINT;
.......
lengthmsg:=RawBytesLen(message)+4;
Slengthmsg:=" Message length,"+ValToStr(lengthmessage);
PackRawBytes slengthmessage,message,(RawBytesLen(message)+1)\ASCII;
SocketSend client_socket\RawData:=message;
How can I index the array (message) such that the length of the data is at the beginning of the message instead of at the end?
Thanks for any help,
SM
Tagged:
0
Best Answer
-
A possible workaround is to define a second "VAR rawbytes...". After you have filled the first one, you know the length of the first one. You can pack the length in the second rawbytes and then use the function "CopyRawBytes" to copy the first rawbytes into the second. In this case you have probably to the use the "ToIndex" argument to not overwrite the length...5
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)
- 798 RAPID Programming
- AppStudio
- 3 RobotStudio AR Viewer
- 18 Wizard Easy Programming
- 105 Collaborative Robots
- 5 Job listings