# Quick & Easy File Integration

**URL:** <https://community.criticalmanufacturing.com/t/quick-easy-file-integration/715>\
**Category:** Blog\
**Tags:** equipment\
**Created:** [December 5, 2023, 12:00am UTC](https://community.criticalmanufacturing.com/t/quick-easy-file-integration/715 "2023-12-05T00:00:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nuno\_Nunes](https://avatars.discourse-cdn.com/v4/letter/n/f9ae1b/32.png) [@Nuno\_Nunes](https://community.criticalmanufacturing.com/u/Nuno_Nunes)\
**Post date:** [December 5, 2023, 12:00am UTC](https://community.criticalmanufacturing.com/t/quick-easy-file-integration/715/1 "2023-12-05T00:00:00Z")

</div>

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](https://tfs-projects.cmf.criticalmanufacturing.com/ImplementationProjects/COMMON/_git/Packages?path=%2FFeatures%2FIoT-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:

 ![Adding to Project - Same MES Version (9.1.11)](https://canada1.discourse-cdn.com/flex050/uploads/community_criticalmanufacturing/original/1X/7471fe2508c0510fa9345824d7c60968e9d41ee9.png)

**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:

 ![Adding to Project - Different MES Version](https://canada1.discourse-cdn.com/flex050/uploads/community_criticalmanufacturing/original/1X/bbdad19e74c44361bca142edcfb898436fe260b3.png)

## 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](https://tfs-projects.cmf.criticalmanufacturing.com/ImplementationProjects/COMMON/_git/Packages?path=%2FFeatures%2FIoT-GenericFileIntegration%2FREADME.md&_a=preview).

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](https://devblog.criticalmanufacturing.com/20230606_iot_sending_notification/) 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:

 ![Download manager](https://canada1.discourse-cdn.com/flex050/uploads/community_criticalmanufacturing/original/1X/15a6f3bf14da4ef53744e51ae9f0fe2d3ecd10b1.png)

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

 ![Run It](https://canada1.discourse-cdn.com/flex050/uploads/community_criticalmanufacturing/original/1X/a09a17e6c4db8a6122be741d5e5b58b1ff2fe008.png)

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

 ![File on Incoming](https://canada1.discourse-cdn.com/flex050/uploads/community_criticalmanufacturing/original/1X/a9d8bfde5583de263629ecf0900ea21f53ab7e1a.png)

A new notification should be created:

 ![Notification Created](https://canada1.discourse-cdn.com/flex050/uploads/community_criticalmanufacturing/original/1X/81e3e906b426382e612f3f42ba4abb9eb6240d97.png)

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

 ![Moved to Success](https://canada1.discourse-cdn.com/flex050/uploads/community_criticalmanufacturing/original/1X/76dc3a06b268c4265f92d38e0f8333ad90745c80.png)

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.

 ![Log file on Error](https://canada1.discourse-cdn.com/flex050/uploads/community_criticalmanufacturing/original/1X/4464ba1e36623dec638b6815e3bbd84118df897e.png)

* * *

## Author

### Hello my name is Nuno Nunes

I am an IoT Lead for the SMT area You can visit me at [LinkedIn](https://www.linkedin.com/in/nunones)

Skills: Connect IoT

![Nuno Nunes](https://canada1.discourse-cdn.com/flex050/uploads/community_criticalmanufacturing/original/1X/de2b06b0c211a8454c1f8bddb38a99c5ed7e0dc5.jpeg "IoT Lead")
_IoT Lead_

* * *
This is a companion discussion topic for the original entry at [https://devblog.criticalmanufacturing.com/blog/20231205\_iot\_generic\_file\_integration/](https://devblog.criticalmanufacturing.com/blog/20231205_iot_generic_file_integration/)
