Getting Started
###############

This guide walks through setting up a Siemens PLC project using the SDK.

Getting the SDK
***************
The SDK is packaged as a downloadable .zip archive found on the `help.graco.com website <https://help.graco.com>`_. The latest version (as of writing) is GracoPD2K_Rockwell_SDK_v\ |version|\ .zip.

Using the example project as a template
***************************************
The SDK comes with a Siemens example project providing some basic functionality right out of the box. For many users, using this project as a starting point is a good way to get to a working system quickly. 

The example project can be found in GracoPd2kInt_Example/GracoPd2kInt_Example.ap17. Make sure you have Siemens TIA Portal V17 installed on your PC.

Configure the PLC
=================
The example project comes pre-loaded with programs created for both a 1211C and a 315-2 CPU:

.. image:: ../assets/project-tree-cpus.png

These can be downloaded directly to a matching physical PLC, or changed to a different model by right-clicking on the CPU and selecting "change device". 

All of the FBs, FCs, and UDTs are included in the program under a "GracoPd2kInt" group folder:

.. image:: ../assets/project-tree-blocks.png

Configure the PD2K
==================

In the network view of the example project, a default PD2K device is connected to each PLC:

.. image:: ../assets/network-view.png

Make sure to set the Profinet settings to match the actual device - these are in Device view -> General -> PROFINET interface -> Ethernet addresses:

.. image:: ../assets/pd2k-pn-settings.png

Once the network configuration is setup to match your real device network, the project can be downloaded to your physical PLC.

Running the PD2K
================
Once you have downloaded the example project to a PLC, you can starting running the PD2K using the provided code. The Globals DB contains variables for controlling the system:

.. image:: ../assets/global-vars.png

You can use the PD2K1_PUMP_CTRL variable to access the PD2K system mode commands:

.. image:: ../assets/globals-pump-ctrl.png

The PD2K1_GUN_CTRL variable provides access to the gun section of the system:

.. image:: ../assets/globals-gun-ctrl.png

These variables can be added to a watch table and modified directly:

.. image:: ../assets/globals-watch-table.png

Where to go from here
=====================
Now that you have explored using the SDK code through the example project, you should have a better understanding of how to use the SDK in your own larger applications. For example, you could take the variables provided in the Globals DB and connect these to an HMI for touchscreen control of the system. You could also write additional code blocks that automate writing the system mode commands, spray triggers, etc. You could even expand this to control multiple different PD2K systems from the same PLC - all of the code is written with modularity and simplicity in mind.

For more information about all the available program blocks, see the :ref:`api-doc`.


Adding the SDK to an existing project
*************************************
Besides using the example project, the contents of the SDK can be pulled into an existing TIA Portal project as well. There are two methods - using the Siemens version control interface (recommended) and using the global library.