blobWrite()

The function blobWrite writes the content of a blob variable into a file.

Synopsis

int blobWrite(blob source, file fd)

Parameters

Parameter Description
source The blob variable whose content is written into a file.
fd The file the content is written to.

Return Value

The amount of data that was written into the file.

Errors

Missing or wrong parameters.

Note that you have to open all files (for reading and writing) in the Binary Mode. See the example below.

Description

The function writes the content of a blob variable into a file.

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

CTRL