Quick & Easy File Integration

On this blog post we will implement a generic file integration: some file will be read from some folder and it’s contents will be read and passed on to some DEE Action.

COMMON Package

For this integration we will use a COMMON Feature package: Cmf.Custom.IoT-GenericFileIntegration

Feature Packages: COMMON is a repository where projects can implement features that can be shared and reused. This serves to mitigate having to implement the same code throughout different projects. The features are posted to COMMON and every project is free to import it, use it and contributing back to make it even more robust.

Using this package on my project

To use this package on your project, you simply add to your cmfpackage.json file:

Important: If your project is using a different patch version than the one this package was prepared for (9.1.11), please use the components unrooted:

Creating a Controller Instance

After the release process, the environment will have a new automation manager, GenericFileIntegration_Manager, and a new controller, GenericFileIntegration_Controller. To use it, just create a controller instance by connecting this controller to a Resource.

Feature Configuration

Available package options are described on package README.md.

Configuration is orchestrated on a smart table IoTMetaDataDefinition by name/value pairs. Minimal configuration is:

Name Value Description
FileRaw_filePath c:\iot\Shares\Incoming Incoming folder (where file are created)
FileRaw_SuccessArchiveFilePath c:\iot\Shares\Success Where to store the files on DEE Action Success
FileRaw_ErrorArchiveFilePath c:\iot\Shares\Error Where to store the files on DEE Action Error
FileRaw_DEEActionName CustomSendNotificationOnDisconnected DEE to execute
FileRaw_InputParameterName ErrorMessage Input parameter name on DEE/Service

We can reuse the blog post Send a Notification in Connect IoT as a DEE example (CustomSendNotificationOnDisconnected). With this example, whenever a new file is put on the incoming folder, a new notification is created with the content of the file.

Execution time!

Download the manager from MES GUI:

Unzip and run it (as Administrator to be able to mount network files):

Now, drop a file with some content on the incoming folder:

A new notification should be created:

and the file should be moved to a timestamped subfolder on `Success`` folder:

Great Success!

Things to consider

Multiple files being dropped at the same time on the incoming folder

If you would need to handle multiple files at the same time, please add to your manager config.json: "controller": {"useClassicEngine": false}.

Error calling DEE/Service

If DEE fails, file is moved to the Error folder (with some date timestamp) and the received error is also stored on a .log file: This is very helpfull to debug whithout the need to check IoT logs.






Author

Hello my name is Nuno Nunes

I am an IoT Lead for the SMT area You can visit me at LinkedIn

Skills: Connect IoT

IoT Lead


This is a companion discussion topic for the original entry at https://devblog.criticalmanufacturing.com/blog/20231205_iot_generic_file_integration/