4. Using the ScreenPro Direct API
Last Modifed Date: 29 Nov, 2021 14:48
We recommend that you drive ScreenPro Direct via the C-compatible API.
Integrating the API
Windows
The ScreenProDirect_API folder, in the ScreenPro Direct release, contains the following:
ScreenProDirect_API.h
ScreenProDirect_API.dll
ScreenProDirect_API.lib
ScreenProDirect_API_Example\
api.example.cpp
ScreenProDirect_API_Example.exe
To access the API functionality, include the ScreenProDirect_API.h
header file in your source code:
#include "path/to/ScreenProDirect_API.h"
You may wish to add the ScreenProDirect_API folder to your include path.
Please link your code with ScreenProDirect_API.lib
and distribute ScreenProDirect_API.dll
with your binary. Please consult your build system documentation for more information on linking static libraries.
Linux
The ScreenProDirect_API directory, in the ScreenPro Direct release, contains the following:
ScreenProDirect_API.h
ScreenProDirect_API.so
ScreenProDirect_API_Example\
api.example.cpp
ScreenProDirect_API_Example
To access the API functionality, include the ScreenProDirect_API.h
header file in your source code:
#include "path/to/ScreenProDirect_API.h"
You may wish to add the ScreenProDirect_API directory to your include path.
Please link your code with ScreenProDirect_API.so
and distribute ScreenProDirect_API.so
with your binary. Please consult your build system documentation for more information on linking shared objects.
API summary
Unless otherwise noted, all API functions use the UNIX convention for return values: 0
on success and 1
on failure.
A list of functions that the ScreenPro Direct API provides follows. You can find these and additional information in the ScreenProDirect_API.h
file.
API function | Parameters | Summary |
---|---|---|
| ( | Aborts a print run. All jobs being processed are canceled. |
| ( | Cancels the job with ID |
|
| Checks if the ScreenPro Direct API has been initialized. A return value of |
| ( | Disables the product detect signal. |
| ( | Disconnects from the ScreenPro Direct instance with ID |
| ( | Enables the product detect signal. |
| ( | Ends a print run. Closes the print run to new job submissions. |
| ( | Frees memory allocated by the ScreenPro Direct API. |
| ( | Returns the variant of the license used to run ScreenPro Direct. If the password has not been successfully set yet, return 0. Return value:
|
| ( | Returns a string encoding the current pipeline status in |
| ( | Returns a structure summarizing the status of the currently active print run. |
| ( | Returns the total number of sheets ever printed by ScreenPro Direct in |
| ( | Gets the version number of the connected ScreenPro Direct instance. |
| ( | Returns ScreenPro Direct to idle state after ending a print run. |
| ( | Pauses a print run. |
| ( | Reconnects to the ScreenPro Direct instance with ID |
| ( | Registers |
| ( | Registers |
| ( | Registers |
| ( | Registers |
| ( | Resets the total number of sheets ever printed by ScreenPro Direct. |
| ( | Resumes a print run from paused. |
| ( | Sends an image to be used as a static background. Used in Variable Data Printing when a foreground is to be overlaid. |
| ( | Sends a blank image with the given dimensions to be screened. |
| ( | Sends a heartbeat signal to the ScreenPro Direct instance with ID |
| ( | Sends a TIFF or XML file for screening. The |
| ( | Sends an image to be preloaded. |
|
| Sets the value of a configuration parameter, overwriting the previous value if already set. Can only be called when no print run is active. |
| ( | Sets the offset on the web (in nozzles) where the image should be printed. |
| ( | Sets a hardware parameter. |
| ( | Sets a hardware parameter. |
| ( | Sends a signal to the hardware. |
| ( | Sets a custom job configuration option. Reserved. |
| ( | Starts a new job in ScreenProDirect with ID |
| ( | Sets the number of the last separation in the given job. |
| ( | Sets the |
spd_set_sheet_number_offset | (spdInstanceId id, uint64_t jobId, uint64_t offset) | Sets the sheet number offset for the given job. For use with the Sheet Numbering plugin when submitting a job with multiple copies. |
|
| Shuts down the ScreenPro Direct API. Make no further calls to API functions after this. |
| ( | Starts a print run. |
| ( | Initializes the ScreenPro Direct API:
|
| ( | Turns off power to the print heads. |
| ( | Turns on power to the print heads. |
spd_run_plugin_command | (spdInstanceId id, const char* pluginName, const char* command, char* result, uint64_t* pResultLength) | Populates |
Example code
The following code snippets showcase what you can do with the ScreenPro Direct API. There are more examples in the ScreenProDirect_API_Example.cpp
file that is provided with ScreenPro Direct. All code below assumes you have already launched a ScreenPro Direct instance.
The first code snippet demonstrates how to initialize the ScreenPro Direct API. A SocketConfiguration
object is required to connect to the running ScreenPro Direct instance. Notice how the client data passed to spd_startup
is passed back to and re-cast in the printRunEventHandler
function.
std::string screenProPassword;
struct LocalContext
{
// details omitted...
} localContext;
void printRunEventHandler(spdInstanceId id, SPD_PrintRunEventCode code, void* priv)
{
auto& context = *reinterpret_cast<LocalContext*>(priv)
// do stuff with the LocalContext and Event data
// details omitted...
}
auto socketConfigurations = std::vector<SocketConfiguration>
{
{
1, // ID to assign to the ScreenProDirect instance.
"127.0.0.1", // IP Address
9099, // Port number for command socket
9098, // Port number for status socket
1000, // Acknowledgment timeout in milliseconds
30000, // Result timeout in milliseconds
}
};
if (spd_startup(socketConfigurations.data(), socketConfigurations.size(), &printRunEventHandler, &localContext, screenProPassword.c_str()) != 0 || spd_check_init() != 0)
{
std::cout << "spd_startup() failed" << std::endl;
return 1;
}
The next example shows how to start a print run and send an image for screening. Note how both API methods require a ScreenPro Direct Instance ID.
if (spd_start_print_run(1) != 0)
{
std::cout << "spd_start_print_run() failed" << std::endl;
return 1;
}
auto const tiffFile = "MyTiffFile.tif"s;
auto constexpr copyCount = 1;
auto constexpr taskId_plane0 = SPD_TaskID{ 0, 0, 0 }; // Use all zeroes to get default numbering.
if (spd_send_image(1, tiffFile.c_str(), copyCount, &taskId_plane0) != 0)
{
std::cout << "spd_send_image() failed" << std::endl;
return 1;
}
Lastly, this code shows how to shutdown the API.
if (spd_shutdown() != 0)
{
std::cout << "spd_shutdown() failed" << std::endl;
return 1;
}