Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X
Having data and properties without moving parts would be useless. We already setup services on how to perform an inspection in the last guide. This time around, let's form processes to create our products and generate any alerts whenever we've finished production. We won't show too much into our recipe (it's a family secret), but we will highlight some concepts to help with making our machine process smoother.
We won't go into creating an SMT line. For a complete guide on how to create such an application you can view our Monitor an SMT Assembly Line guide.
Let's create events for the cook time being done and a subscriptions on how to handle these scenarios.
Name | Data Shape | Description |
CookCompleted | AlertEvent | This alert is fired when the machine has completed a batch of our product |
TemperatureReached | AlertEvent | This alert is fired when the machine has reached the desired temperature. |
3. Save these changes and replicate them with the Fizos.SausageMachine.ThingTemplate template.
We now have alerts for the machines (alerts on properties and custom alerts). We can create subscriptions on the individual machines that will later inherit these alerts. One way to have a standard amongst these machines is to create a service in the template that will be called from subscriptions.
Let's create the simple services from now, and later, we will call these services from subscriptions. We will also use Schedules initiate the overall process. This can be a daily process, a timed process, or a process based on alerts and subscriptions. To keep this guide simple, we'll make this a process that runs every 3 hours. Create the below services in each of the Fizos.BrautsMachine.ThingTemplate and Fizos.SausageMachine.ThingTemplate templates:
Name | InputReturn | Type | Override | Async | Description |
StartCookingProcess | N/A | Nothing | Yes | Yes | Start overall product cooking process.Triggedby schedule. |
StartCookingIngredients | N/A | Nothing | Yes | Yes | Start cooking the ingredients for the product.Triggedby subscription. |
// Mix our family secret recipe // Add in meats // Add heat me.TemperatureReached({ aackTimestamp: new Date(), alertType: "Completed", ackBy: "CookUser", ack: true, name: "TemperatureAlert", sourceProperty: "Service", description: "Optimal cooking temperature reached", message: "The desired cooking temperature has been reached. Begin next process.", priority: 1 }); // Perform top secret cooking techniques
2. Add the following code for the StartCookingIngredients service:
// Temperature has already been reached if(true) { // IF COOK COMPLETED me.CookCompleted({ ackTimestamp: new Date(), alertType: "Information", ackBy: "CookUser", ack: true, name: "CookingAlert", sourceProperty: "Service", description: "Cooking process has completed", message: "The cooking time has completed. Move to next machine.", priority: 1 }); } else { //ELSE IF COOKING FAILED OR HALTED me.CookCompleted({ ackTimestamp: new Date(), alertType: "Exception", ackBy: "CookUser", ack: true, name: "CookingAlert", sourceProperty: "Service", description: "Cooking process has failed", message: "The cooking process has stopped. See logs for failure cause.", priority: 1 }); }
Let's keep in mind, these services will be triggered by by a schedule or a subscription to an alert. There will be no manual processed performed here. We also allowed for these services to be overridden, in order to allow more customization for machines that might need to be treated differently. These services are also not on the main machine templates, which allows us to create templates for machines that might have a different role in the process, ie, packaging or freeze drying.
Let's create the schedule that will start the cooking process.
In the ThingWorx Composer, click the + New in the top left of the screen.
3. Name the new Schedule Fizos.MachineCooking.Schedule and set the Project (ie, PTCDefaultProject).
4. For the Run As User field, select the Fizos.Machine.User that was provided in the download.
5. Click Save and your entity should match the below configuration.
6. For the Schedule field, set it to 0 0 0/3 * * ?. This will run the process every 3 hours.
7. Switch to the Subscriptions tab and add a new subscription.
8. Name this new subscription StartCooking and select ScheduledEvent as the event input.
9. Add the following code to the source section:
var index = 0; var brauts = Resources["SearchFunctions"].SearchThingsByTemplate({ thingTemplate: "Fizos.BrautsMachine.ThingTemplate" }); var sausage = Resources["SearchFunctions"].SearchThingsByTemplate({ thingTemplate: "Fizos.SausageMachine.ThingTemplate" }); for(index = 0; index < brauts.rows.length; index++) { brauts.StartCookingProcess(); } for(index = 0; index < brauts.rows.length; index++) { sausage.StartCookingProcess(); } // This will begin the process to start each machines cooking process. // The process itself will then be ran by alerts, subscriptions, and services
So far the process will go as the following:
We now have our moving parts. Let's create some examples to see how it can unfold.
We have many of our main features compeleted. Now we need to handle situations where our machine status needs to be a part of how we handle the cooking process. While much of this work can be handled in a remote process using one of our SDKs or extensions, our events and subscriptions can be a great method to do this also.
In the ThingWorx Composer, click the + New in the top left of the screen.
Select Thing in the dropdown.
Set the Project (ie, PTCDefaultProject) and in the name field, enter Fizos.BrautsMachine.M02X35.
In the Base Thing Template field, enter Fizos.BrautsMachine.ThingTemplate.
6. In the ThingWorx Composer, click the + New in the top left of the screen.
7. Select Thing in the dropdown.
8. In the name field, enter Fizos.SausageMachine.KGYX20.
9. In the Base Thing Template field, enter Fizos.SausageMachine.ThingTemplate.
10, Click Save.
These steps will need to be in both of the entities we just created.
Switch to the Subscriptions tab and add a new subscription.
3. Add the following code to the source section:
//The temperature is high enough. Start cooking me.StartCookingIngredients();
You now have a system (when enabled) will run every three hours. It will start our secret cooking process (that can be added in the service or created remotely).
To make things more fun. Add some logging or fun code to see how this works step by step.
To make things more realistic to a real world scenario, add subscriptions for our property alerts on the status or state properties.
Congratulations! You've successfully completed the Factory Line Automation guide.
In this guide, you learned how to:
The next guide in the Complex and Automatic Food and Beverage Systems learning path is Automated Distribution and Logistics.
We recommend the following resources to continue your learning experience:
Capability Guide
Build | ThingWorx Solutions in Food Industry |
Build | Design Your Data Model |
Build | Implement Services, Events, and Subscriptions |
If you have questions, issues, or need additional information, refer to:
Resource Link
Community | Developer Community Forum |