Shift Export/Import

How to Export and Import Ignition MES Schedules Between Gateways

Introduction: Streamlining Schedule Migration

Migrating Manufacturing Execution System (MES) schedules between Ignition Gateways is a critical task for maintaining consistency and operational integrity across different environments. This process is essential for synchronizing development and production systems, creating reliable backups of complex scheduling configurations, or deploying standardized schedules to new gateways. By scripting the export and import procedures, you can ensure a repeatable, efficient, and error-free transfer of vital operational data.

This KB article provides a comprehensive walkthrough of a proven four-stage process for migrating your MES schedules. We will cover the essential Prerequisites to prepare your environments, the Export script to extract schedules from your source gateway, the Import script to load them onto your target gateway, and the Finalization step required to activate them. Adhering to these steps will ensure a smooth and successful migration.



Prerequisites: Preparing Your Gateways for Migration

Completing these prerequisite steps is essential to prevent file system errors and data conflicts during the migration process. Careful preparation on both the source and target gateways lays the foundation for a successful transfer.

On the Source Gateway: Sanitize Shift Names

Before running the export script, you must review all schedules within the Ignition Shift Manager on your source gateway. Any shift times that contain a colon (:) must be manually updated to use a hyphen (-) instead.

Example: A shift time of 06:00-06:55 must be updated to 06-00-06-55.

This manual update is a critical data governance step. While the export script includes a function to replace colons when creating filenames, modifying the schedule name at the source ensures that the data is consistent within the MES database itself. Relying solely on the script's file-level replacement can lead to mismatches between the schedule's name on the gateway and its corresponding backup filename.



On the Target Gateway: Remove Default Schedules

On the target gateway, navigate to the Shift Manager and delete the built-in "Always" and "Example Schedule" configurations. This action is a crucial housekeeping step that prevents potential conflicts or duplication when your custom schedules are imported.

With these preparations complete, you are ready to proceed with the export script.

Step 1: Exporting Schedules from the Source Gateway

The export script automates the process of extracting schedule configurations. It programmatically iterates through all available MES schedules on the source gateway, serializes each one into a Java object, and saves it as an individual file in a specified directory on the local file system.

Export Script

Python
from java.io import FileOutputStream, ObjectOutputStream

path = 'C:\\Temp\\Schedules\\'

schedules = system.user.getSchedules()

for schedule in schedules:

# You may need to .replace() any characters in the schedule.name to create a valid file name
schedule.name = schedule.name.replace(':',"-")

print schedule.name
filePath = path + schedule.name

fos = FileOutputStream(filePath)
oos = ObjectOutputStream(fos)
oos.writeObject(schedule)

fos.close()
oos.close()

Executing the Script

Open the Script Console in the Ignition Designer connected to your source gateway. Copy and paste the entire export script into the console and execute it. The script will create a file for each schedule in the C:\Temp\Schedules\ directory.

Analysis of the Export Script

The script performs several key operations to properly extract and save the schedule data:
  • Path Definition: The script saves files to a hardcoded path (C:\\Temp\\Schedules\\). You may need to modify this path to a directory that exists and is accessible on your source gateway machine.
  • Schedule Retrieval: The system.user.getSchedules() function is used to fetch a list of all schedule objects currently configured on the gateway.
  • Filename Sanitization: The line schedule.name = schedule.name.replace(':',"-") acts as a programmatic safeguard to ensure any remaining colons are replaced with hyphens, creating a valid filename for the Windows file system.
  • Object Serialization: The script uses Java's FileOutputStream and ObjectOutputStream to write the complete schedule object to its own binary file. This process, known as serialization, preserves the entire state and structure of the object for later use.
Once the script has finished running and all files have been created, you can proceed with importing them onto the target gateway.

Step 2: Importing Schedules to the Target Gateway

The import script effectively reverses the export process. It reads the serialized schedule files from the specified directory, reconstructs the schedule objects, and uses a system function to add each schedule to the target gateway's configuration.

Import Script

Python
from java.io import FileInputStream, ObjectInputStream
import os

path = 'C:\\Temp\\Schedules\\'

for f in os.listdir(path):

fis = FileInputStream(path + f)
ois = ObjectInputStream(fis)
schedule = ois.readObject()

fis.close()
ois.close()

system.user.addSchedule(schedule)

Executing the Script

First, ensure the schedule files exported from the source gateway are present in the directory specified in the script (C:\\Temp\\Schedules\\) on the target gateway machine. Next, open the Script Console in the Ignition Designer connected to your target gateway. Copy and paste the import script into the console and execute it.

Analysis of the Import Script

The logic of the import script is straightforward and complementary to the export script:
  • File Iteration: The os.listdir(path) function iterates through every file found in the specified path.
  • Object Deserialization: The script uses Java's FileInputStream and ObjectInputStream to read the binary data from each file and reconstruct (deserialize) it back into a fully functional schedule object in memory.
  • Schedule Creation: The system.user.addSchedule(schedule) function is the core of the import process. It takes the deserialized schedule object and adds it to the target gateway's user source, making it visible in the Shift Manager.
After the script completes, the schedules will appear in your target gateway's configuration, but one final, critical step is required to make them active.

Step 3: Finalizing the Migration

At this stage, the schedule data exists on the target gateway, but it is not yet active or applied to the equipment it is associated with. The system requires a full restart to load the new configurations and apply them to the relevant production assets.

Skipping this step will result in a failed migration; the imported shifts will not take hold on the equipment, and operations will continue to run on the old schedule until the gateway has been fully restarted.