Raw bytes reading error
egor
✭
Can't understand why I'm getting the following error: "End of file was found before all bytes were read in ReadRawBytes".
I tried a plenty of examples from manuals and there is always the same error... How it is possible to reach the EOF and not read all bytes in the text file?
PROC rawbytes_test()
VAR iodev io_device;
VAR rawbytes raw_data_in;
VAR rawbytes raw_data_out;
VAR num float:=15.2;
VAR num answer;
ClearRawBytes raw_data_out;
ClearRawBytes raw_data_in;
PackRawBytes float,raw_data_out,(RawBytesLen(raw_data_out)+1)\Float4;
Open "HOME:"\File:="Test.txt",io_device\Bin;
WriteRawBytes io_device,raw_data_out;
!Error appears on this line
!Error appears on this line
ReadRawBytes io_device,raw_data_in\Time:=1;
Close io_device;
UnpackRawBytes raw_data_in,1,answer\Float4;
ENDPROC
Tagged:
0
Best Answer
-
Hello,
if you open a file in binary mode the file pointer is at the end of the file. Please use the instruction "Rewind" before you do the reading.
See the following abstract from the documentation:The file or I/O device is opened in a binary mode. If none of the arguments \Read, \Write or \Append are specified then the instruction opens a binary file or I/O device for both reading and writing, with the file pointer at the end of the file.
The Rewind instruction can be used to set the file pointer to the beginning of the file if desirable./BR
Micky
5
Answers
-
Is this just an ascii text file? I never used ReadRawBytes but I have read and written to files using Open instruction, default is ascii.Lee Justice0
Categories
- All Categories
- 5.5K RobotStudio
- 395 UpFeed
- 18 Tutorials
- 13 RobotApps
- 297 PowerPacs
- 405 RobotStudio S4
- 1.8K Developer Tools
- 249 ScreenMaker
- 2.7K Robot Controller
- 310 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