Hello,
I am pretty new to programming in karel, but for the most part my program works. My socket connects and I am able to both read and write through it. My issue comes when I receive a message larger then 254 bytes. Without going into too many details my program receives a list of points in xml format that I am trying to store. This message can contain anywhere from 2 to 15 points. My issue is with storing the message when the number of points I am trying to store is on the later half of that range. Below I will include a bare bones version of where I am having my issue:
file_var :FILE
i :INTEGER
status :INTEGER
msg :ARRAY[10] OF STRING[127]
arrays :INTEGER
step :INTEGER
WRITE file_var('*Message asking for points*')
WRITE('Before read',CR)
WHILE i = 0 DO
DELAY 500
BYTES_AHEAD(file_var, i, status)
ENDWHILE
arrays = (i DIV 127)+1
WRITE('about to get message',CR)
FOR step = 1 TO arrays+1 DO
READ file_var(msg[step]::127)
ENDFOR
WRITE('got message',CR)
For the above 'i' always equals 0 by the time it gets to the while loop and file_var is the socket that I have setup and am connected to. For the current issue that I am having 'i' equals 530 when the complete message is read into the buffer. I read in fanuc documentaion that socket messaging can only send 127 bytes over the connection at a time so that is where my msg array of size 127 is coming from. Now when I read in this message the first 4 arrays are filled out no problem, however the remaining 22 characters are nowhere to be found and nothing is put into the 5th array to end the message. At first I thought this was an issue with my string formatting so instead of "msg[step]::127" I tried changing it to i or even something smaller, like 5, to ensure that the READ is not hung up waiting for a full message to be in the buffer before passing it on. I also changed my msg array to be "msg :array[1000] of string[1]" to try and brute force my message out of the buffer. Even with 1000 arrays of size 1 only the first 4 of my arrays are filled with data. While looking at the karel vars of my program I can see that the amount of arrays I am trying to use is the correct amount (5 in the above example, or 530 in the case of 1000 arrays of size 1), but it never goes past that 4th array. I always get the "about to get message" message printed out the the TP, but "got message" is never printed.
I've been stuck on this for a week now and can't seem to find a solution in the docs or already on the forum so any help pointing me in the right direction or to the correct documentation would be greatly appreciated.
Thanks!