In WinCC flexible PC Runtime you cannot explicitly specify printers for printouts. All printouts from the WinCC flexible PC Runtime are always output on the default printer set in Windows.
To have printouts from WinCC flexible PC Runtime output on different printers, the printers concerned must be installed as default printers in Windows. You can do this manually before each printout using the Printer dialog in Windows (Start > Settings > Printers and Faxes > Define as default), but this is inconvenient. Alternatively the default printer can be changed with a VB script while WinCC flexible Runtime is running. You can link this script to a button, for example, which sets a specific printer as default printer in Windows and then starts the printout. The script is structured so that you can use it repeatedly and the printer to be activated is transferred to the script as a parameter.
Please proceed as follows to create the script.
Create a new script
Navigate in the project tree to the "Scripts" area and create a new script with "Add Script". The new script is opened automatically in the working area.
Make the basic settings of the script
After the empty script has been opened, you can make the basic settings in the inspector window. Here you specify a unique name for the script, for example "fSet_DefaultPrinter" and select "Function" as type. Create a new parameter, for example "sPrinterName", and add this to the interface of the script using "Add".
Create a new tag
In WinCC flexible you create a new tag of the "Bool" type, for example "RETVAL_fSet_PrinterDefault". This tag later contains the return value of the "fSet_DefaultPrinter" function; if the function is executed without an error, the value is "1", otherwise "0". Configure the tag as below.
Program the script
Now program the script for changing the default printer in Windows. The complete script is given at the end of this entry or as a text file in the download of the FAQ entry.
||Buttons for printer change|
Configure a separate button in a picture for each of the printers to be used. The figure shows a switch between the two printers "MA11193D" and "Adobe PDF".
The return value "RETVAL" of the "fSet_DefaultPrinter" function is shown in an IO field. Link the "RETVAL_fSet_DefaultPrinter" tag to the IO field.
Determine the printer name in Windows
Proceed as follows to determine the printer name for the script in WinCC flexible.
Open this path in Windows: "Start" > "Settings" > "Printers and Faxes".
There you will find a list of all the printers available and their names. Use a unique (sub)string from a name in the list as the "sPrinterName" parameter of the script. For example "Adobe PDF" and "MA11193D" as in the screenshot shown.
Script call with the buttons
Open the Properties of one of the two buttons and configure a call of the "fSet_DefaultPrinter" script in the function list under "Events > Click".
Assign the call as shown. Provide the return value with the "RETVAL_fSet_DefaultPrinter" tag created in Step 3. Use the printer name as created in Windows as parameter for the printer name "sPrinterName". Repeat this step for each printer and each button you have created in your picture. You can use the same tag each time as return value, because it is always the same script that is executed. However, the printer name must be changed for each separate call.
Complete VB script
The complete script is in the PDF file below.
WinCC_flexible_RT_changing_printer_Skript_e.pdf ( 9 KB )
Output device, Switch, Redirect, Change, Default printer, DefaultPrinter