Automatically update the tasks if there arent any.
This commit is contained in:
parent
8db84d01ea
commit
fe42a85204
@ -14,6 +14,7 @@ import {
|
||||
exportMethod,
|
||||
exportProperty
|
||||
} from "../../../lib/decorators/moduleDecorators";
|
||||
import { copy } from "../../../lib/helpers/objectMethods";
|
||||
import { getNopeLogger } from "../../../lib/logger/getLogger";
|
||||
import { InjectableNopeBaseModule } from "../../../lib/module/BaseModule.injectable";
|
||||
import { NopeObservable } from "../../../lib/observables/nopeObservable";
|
||||
@ -190,7 +191,8 @@ export class WaMOBaseModule
|
||||
tasks: MESTask[];
|
||||
}) => Promise<string | false>,
|
||||
resetPlc = true,
|
||||
autoStart = true
|
||||
autoStart = true,
|
||||
demo = false,
|
||||
): Promise<void> {
|
||||
// Define the Author.
|
||||
this.author = {
|
||||
@ -306,42 +308,51 @@ export class WaMOBaseModule
|
||||
|
||||
// Only if there exists a Carrier, proceed.
|
||||
if (value) {
|
||||
// Extract the new task.
|
||||
const taskToStart = await selectProduct({
|
||||
|
||||
let tasks: MESTask[] = _this._xetics.availableTasks.getContent();
|
||||
|
||||
// Only if no tasks are available, try to update the
|
||||
// available tasks. Thereby we check if there are new
|
||||
// tasks, we didnt checked before because they werent
|
||||
// present.
|
||||
if (tasks.length === 0){
|
||||
tasks = await _this._xetics.updateTasks();
|
||||
}
|
||||
|
||||
// We now use the perhaps updated list of tasks, to
|
||||
// determine the task for our carrier.
|
||||
const productToStartTaskWith = await selectProduct({
|
||||
checkedInWorkpieceCarrier: value,
|
||||
tasks: _this._xetics.availableTasks.getContent()
|
||||
tasks
|
||||
});
|
||||
|
||||
// Try to assign the new Task for the Product
|
||||
if (
|
||||
taskToStart &&
|
||||
_this._xetics.selectTaskForProduct(taskToStart)
|
||||
!demo &&
|
||||
productToStartTaskWith &&
|
||||
_this._xetics.selectTaskForProduct(productToStartTaskWith)
|
||||
) {
|
||||
// extract the Task
|
||||
// We are not running in the demo-mode and we have
|
||||
// a task to start, which we are able to select.
|
||||
await _this.performCurrentTask();
|
||||
// Release the Carrier
|
||||
await _this.releaseCarrier();
|
||||
} else {
|
||||
_this._logger.warn(
|
||||
"No Task for the Product",
|
||||
taskToStart,
|
||||
"Release the Product"
|
||||
);
|
||||
|
||||
} else if (demo) {
|
||||
// Demo-Mode
|
||||
// Wait 10 Seconds at least spend additional 0-5000 Seconds
|
||||
await sleep(Math.random() * 5000 + 1000);
|
||||
|
||||
_this._logger.info("waited => release");
|
||||
|
||||
await _this.releaseCarrier();
|
||||
await sleep(Math.random() * 5000 + 10*1000);
|
||||
}
|
||||
|
||||
// Now we are done or we dont have a task.
|
||||
// we release the carrier and wait for a new
|
||||
// product.
|
||||
await _this.releaseCarrier();
|
||||
|
||||
} else {
|
||||
// Updating the State of the System. The System
|
||||
// Waits for a new Carrier
|
||||
_this.baseInformation.getContent().logical.currentState =
|
||||
const baseInformation = copy(_this.baseInformation.getContent());
|
||||
baseInformation.logical.currentState =
|
||||
"waiting";
|
||||
_this.baseInformation.forcePublish();
|
||||
_this.baseInformation.setContent(baseInformation);
|
||||
}
|
||||
} catch (e) {
|
||||
_this._logger.error("Failed to assign a new Task.");
|
||||
@ -407,6 +418,7 @@ export class WaMOBaseModule
|
||||
} as IWaMOProcessModuleDescription
|
||||
];
|
||||
|
||||
// Create the Connector of the Process-Module.
|
||||
this._processModule = await _this._dispatcher.generateInstance<IPROCESSMODULE>(
|
||||
{
|
||||
identifier: _this.identifier + "_BECKHOFF_PROCESSMODULE_CLIENT",
|
||||
@ -414,9 +426,6 @@ export class WaMOBaseModule
|
||||
type: "WaMOProcessModule"
|
||||
}
|
||||
);
|
||||
|
||||
// Not requried
|
||||
// this._plc.initialized.forcePublish();
|
||||
} catch (e) {
|
||||
_this._logger.error("Failed to create a Base-Module.");
|
||||
_this._logger.error(e);
|
||||
@ -453,7 +462,7 @@ export class WaMOBaseModule
|
||||
for (const key in dict) {
|
||||
// Set the PLC.
|
||||
_this._plc.dynamicInstanceProperties[
|
||||
"input.GVL_IOS." + dict[key]
|
||||
"output.GVL_IOS." + dict[key]
|
||||
].setContent(value[key]);
|
||||
|
||||
// Publish on MQTT.
|
||||
@ -691,10 +700,8 @@ export class WaMOBaseModule
|
||||
|
||||
// Now Test if the new Task requires a new product:
|
||||
if (
|
||||
_this._xetics.currentTask.getContent()?.lotId ===
|
||||
currentTask.lotId ||
|
||||
_this._xetics.currentTask.getContent()?.autoId ===
|
||||
currentTask.autoId
|
||||
currentTask?.lotId === currentTask.lotId ||
|
||||
currentTask?.autoId === currentTask.autoId
|
||||
) {
|
||||
_this._logger.info("The product still contains open tasks");
|
||||
|
||||
@ -722,11 +729,30 @@ export class WaMOBaseModule
|
||||
observers = [];
|
||||
};
|
||||
|
||||
let first = true;
|
||||
|
||||
// Todo Check if the Replica has to be adapted
|
||||
observers = [
|
||||
// Subscribe to the connectorReplica of the Process Module.
|
||||
_this._processModule.connector.subscribe((value) => {
|
||||
if (value.active == false) {
|
||||
|
||||
// If we have waited to finish a Task, we are able
|
||||
// to proceed with the task.
|
||||
if (value.active == false && first == false) {
|
||||
// Unsubscribe the Observer
|
||||
clearObservers();
|
||||
finishTask().then(resolve).catch(reject);
|
||||
}
|
||||
|
||||
// Make shure the module just tells ous
|
||||
// that the task has been started.
|
||||
if (value.active) {
|
||||
first = false;
|
||||
}
|
||||
}),
|
||||
_this._plc.dynamicInstanceProperties["input.GVL_IOS.bInputTasterQuittieren"].subscribe((value) => {
|
||||
console.log("bInputTasterQuittieren =>" ,value);
|
||||
if (value) {
|
||||
// Unsubscribe the Observer
|
||||
clearObservers();
|
||||
finishTask().then(resolve).catch(reject);
|
||||
@ -739,13 +765,15 @@ export class WaMOBaseModule
|
||||
await this._xetics.startCurrentTask();
|
||||
|
||||
// Updating the State of the System.
|
||||
this.baseInformation.getContent().logical.currentState = "processing";
|
||||
this.baseInformation.getContent().logical.error = null;
|
||||
this.baseInformation.forcePublish();
|
||||
const baseInformation = this.baseInformation.getContent();
|
||||
baseInformation.logical.currentState = "processing";
|
||||
baseInformation.logical.error = null;
|
||||
this.baseInformation.setContent(copy(baseInformation));
|
||||
|
||||
// Enable the Port Replicas.
|
||||
_this.connector.getContent().start = true;
|
||||
_this.connector.forcePublish();
|
||||
const connector = _this.connector.getContent();
|
||||
connector.start = true;
|
||||
_this.connector.setContent(copy(connector));
|
||||
|
||||
// Wait for the Task to Finish
|
||||
await promiseOfTask;
|
||||
|
Loading…
Reference in New Issue
Block a user