blobRead()

The function blobRead() reads the content of a file into a blob variable.

Synopsis

int blobRead( blob & target, int len, file fd)

Parameters

Parameter Description
target The variable in which the read content is saved.
len The amount of data that should be read.
fd The file whose content should be read.

Return Value

The amount of data that was read.

Errors

Missing or wrong parameters.

Description

The function reads the content of a file into a blob variable. If the file is smaller than the stated length, the whole file will be read and the number of read bytes will be returned.

Example

First the file pvss_scripts.lst is opened in the binary mode (rb). The content of the pvss_scripts.lst file is read and saved in the variable "cont". The second example creates the file pvss_scriptsCopy.lst and writes the content of the blob variable "cont2" into the file "pvss_scriptsCopy.lst". Create two buttons ("Read" and "Write") using the graphics editor and use the first code (see below) for the "Read" button and the second code for the "Write" button.

main()
{
  file f;
  blob cont;
  int read;
  f = fopen("C:/Siemens/Automation/WinCC_OA/3.15/scripts/pvss_scripts.lst", "rb");

//opens a file for reading in the binary mode rb
  read = blobRead(cont, 80000, f);
//the file is read and the content is written into the variable "cont"
  fclose(f);
  DebugN("file","C:/Siemens/Automation/WinCC_OA/3.15/scripts/pvss_scripts.lst", "was read", "Amount of data read:",read);

/* shows that the file was read as well as the amount of data that was read */
}
main()
{
  file f, f2;
  int read;
  blob cont, cont2;
  int write;
  f2 = fopen("C:/Siemens/Automation/WinCC_OA/3.15/scripts/pvss_scripts.lst", "rb");

//opens a file for reading in the binary mode rb
  read = blobRead(cont2, 80000, f2);
  //the file is read and the content is written into the variable "cont2"

  f = fopen("C:/Temp/pvss_scriptsCopy.lst", "wb");

/* creates the file the content is written to. The file is opened in the binary mode */

  write = blobWrite(cont2, f);

/* writes the content of the variable "cont2" into the file pvss_scriptsCopy.lst */
  DebugN("file","C:/Temp/pvss_scriptsCopy.lst", "was written", "Amount of data written:", write);
  fclose(f);
  fclose(f2);
}

Assignment

Blob functions

Availability

UI, CTRL, DP