node-red-trexmes-commands 0.0.1 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -9,7 +9,47 @@ Run the following command in the root directory of your Node-RED install
9
9
  npm install node-red-trexmes-commands
10
10
 
11
11
  # Usage
12
+ The following operations can be performed with this node by communicating with the Trex-Mes system.
13
+ - Load Job Plan
14
+ - Finish Production
15
+ - Start Stoppage
16
+ - Change Stoppage
17
+ - Finish Stoppage
18
+ - Login Employee
19
+ - Logout Employee
20
+ - Shifted Shift
21
+ - Start Test Mode
22
+ - Finish Test Mode
23
+ - Create Deffect
12
24
 
25
+ For configuration, first MS SQL server connection setting must be made. In addition, the "company" company identification id and the identification id of the personnel who will perform the transaction should be defined as default in the connection features, specifically for the Trex system.
26
+
27
+ Then, the relevant operation is selected from the "Operation Type" combo contained in the node.
28
+ The Json sample data requested as input is displayed on the node for each operation.
29
+
30
+ For example, the input example for "Load Job Plan" should be as follows
31
+ ```sh
32
+ {
33
+ "WorkstationId": 10,
34
+ "PlanId": 123
35
+ }
36
+ ```
37
+
38
+ When json data is sent in accordance with this sample data, the relevant operation is performed.
39
+
40
+ As an operation return, for example, when the operation is successful for the "Loas Job Plan" operation, the following information is returned.
41
+ ```sh
42
+ {
43
+ "COMMANDID":91,
44
+ "ISPROCESSED":true,
45
+ "ISSUCCESS":1,
46
+ "MESSAGE":"LoadPlan Success"
47
+ }
48
+ ```
49
+
50
+ The example can be found in the node-red import examples page.
51
+
52
+ ![trexMes-CMD Node image1](src/assets/1.jpg)
13
53
 
14
54
  # Requirements
15
55
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-trexmes-commands",
3
- "version": "0.0.1",
3
+ "version": "1.1.1",
4
4
  "description": "A node-red node to execute commands for Trex Mes Systems",
5
5
  "main": "trexcommands.js",
6
6
  "dependencies": {
@@ -16,13 +16,16 @@
16
16
  "files": [
17
17
  "src/"
18
18
  ],
19
+ "directories": {
20
+ "example": "examples"
21
+ },
19
22
  "keywords": [
20
23
  "node-red",
21
24
  "trex-mes",
22
25
  "trex",
23
- "mes"
26
+ "mes"
24
27
  ],
25
- "author": "asafyurdakul",
28
+ "author": "asafyurdakul",
26
29
  "license": "GPL-3.0-or-later",
27
30
  "engines": {
28
31
  "node": ">=16"
Binary file
@@ -17,141 +17,7 @@
17
17
  <script type="text/html" data-help-name="trexMes-CMD">
18
18
  <p>Node for Node-RED to trexMes Commands</p>
19
19
 
20
- <h3>Foreword</h3>
21
- <dl class="message-properties">
22
- Examples have been included to help you do some common tasks.
23
- <a onclick="RED.actions.invoke('core:show-examples-import-dialog')" href="#">Click here</a> to import an example or press the hamburger menu <a class="button" href="#"><i class="fa fa-bars"></i></a> select <b>import</b> then <b>examples</b> or press <kbd>ctrl+i</kbd>
24
- </dl>
25
-
26
- <h3>Query Mode...</h3>
27
- <div style="padding-left: 15px;">
28
- <p>Select the execution mode, this can be "Query", "Stored procedure" or "Bulk Insert"</p>
29
- <div class="form-tips" style="width: 100%">
30
- TIP: Query mode can be set in the UI or dynamically via msg, flow, global or env. The value sent must be either "query", "execute" or "bulk"
31
- </div>
32
- <p>INFO: TVP variables are only supported in stored procedures. Some variable types are not supported by the underlying SQL driver.
33
- </p>
34
- </div>
35
-
36
- <h3>Query...</h3>
37
- <div style="padding-left: 15px;">
38
- <p>Enter the query or stored procedure name to execute. It is possible to use <i><a href="http://mustache.github.io/mustache.5.html" target="_new">mustache</a></i> format to access properties of the msg, flow context and global context.</p>
39
- <div class="form-tips" style="width: 100%">
40
- TIP: Query can be set in the UI or dynamically via msg, flow, global or env. The value sent can also contain mustache items.
41
- </div>
42
- <br>
43
- <p>Query Examples (with mustache and parameters)...
44
- <ul>
45
- <li><code style="white-space: normal;">SELECT TOP {{{flow.maxRows}}} * FROM [MyTable] WHERE Name = @name AND quantity >= {{{global.minQty}}}</code></li>
46
- <li><code style="white-space: normal;">INSERT INTO [MyTable] (id, name, quantity) VALUES (@id, '{{{payload.name}}}', {{{payload.qty}}})</code></li>
47
- <li><code style="white-space: normal;">UPDATE [MyTable] SET quantity = @quantity WHERE id = {{{payload.id}}}</code></li>
48
- <li><code style="white-space: normal;">DELETE FROM [MyTable] WHERE id = @id</code></li>
49
- </ul>
50
- </p>
51
- <div class="form-tips" style="width: 100%">Query mode tips...
52
- <ul>
53
- <li>To access <code>msg</code> properties, just use the variable name. e.g.
54
- <code>SELECT top {{{payload}}} * from [MyTable]</code></li>
55
- <li>To access <code>flow</code> and <code>global</code> properties,
56
- specify them in the mustache e.g.
57
- <code>SELECT {{{flow.name}}} FROM {{{global.table_name}}}</code></li>
58
- <li>To prevent certain characters being escaped, use triple curly brackets. e.g.
59
- <code>{{{flow.my_string}}}</code> </li>
60
- </ul>
61
- </div>
62
- <div class="form-tips" style="width: 100%">Execute tips...
63
- <ul>
64
- <li>The query should be just the name of the stored procedure (don't include <code>exec</code>)</li>
65
- <li>Parameters can be entered in the procedure query
66
- (but are not necessary - just enter the matching parameter name in the <code>Parameters</code> list) </li>
67
- </ul>
68
- </div>
69
- <div class="form-tips" style="width: 100%">Bulk Insert tips...
70
- <ul>
71
- <li>The query should be just the name table to bulk insert into</li>
72
- <li>Data to bulk insert must be provided to the <code>Rows (bulk data)</code> field as either ...
73
- <ul>
74
- <li>an array of array rows e.g. <code>[ [col1_value, col2_value], [col1_value, col2_value] ]</code></li>
75
- <li>an array of object rows e.g. <code>[ {col1:"value", col2:"value"}, {col1:"value", col2:"value"} ]</code></li>
76
- </ul>
77
- </li>
78
- </ul>
79
- </div>
80
-
81
- <br>
82
- <p>INFO: When the 'Result type' is set to 'Driver output'...
83
- <ul>
84
- <li>Multiple results can be returned in the <code>recordsets</code> array if multiple queries are
85
- executed.</li>
86
- <li>It is recommended the user checks the value(s) in the <code>rowsAffected</code> property to confirm
87
- operation - especially when performing INSERT, UPDATE and DELETE operations.</li>
88
- </ul>
89
- </p>
90
- </div>
91
-
92
- <h3>Parameters...</h3>
93
- <div style="padding-left: 15px;">
94
- <p>Input and Output Parameters can be specified for a query or procedure. In bulk mode, the parameters represent the columns of the table</p>
95
- <div class="form-tips" style="width: 100%">
96
- TIP: Query can be set in the UI or dynamically via msg, flow, global in the following format...<br>
97
- <code><pre style="white-space: pre;">[
98
- {
99
- "output": false,
100
- "name": "parameter name",
101
- "type": "parameter type",
102
- "value": "parameter value"
103
- },
104
- {
105
- "output": true,
106
- "name": "parameter name",
107
- "type": "parameter type"
108
- }
109
- ]</pre></code>
110
- </div>
111
- <br>
112
- <p>Query Examples (with parameters)...
113
- <div style="padding-left: 15px;">
114
- <code style="font-weight: bold;">Query</code>
115
- <div style="padding-left: 15px;">
116
- <code style="white-space: normal;">SELECT TOP {{{payload.maxRows}}} * FROM [MyTable] WHERE Name = @name AND quantity >= @minQty</code>
117
- </div>
118
- </div>
119
- <div style="padding-left: 15px;">
120
- <code style="font-weight: bold;">Parameters</code>
121
- <ul>
122
- <li>
123
- <span>In/Out </span><code style="white-space: normal;">input</code>
124
- <span>, Name </span><code style="white-space: normal;">name</code>
125
- <span>, Type </span><code style="white-space: normal;">varchar(20)</code>
126
- <span>, Value </span><code style="white-space: normal;">stephen</code>
127
- </li>
128
- <li>
129
- <span>In/Out </span><code style="white-space: normal;">input</code>
130
- <span>, Name </span><code style="white-space: normal;">minQty</code>
131
- <span>, Type </span><code style="white-space: normal;">int</code>
132
- <span>, Value </span><code style="white-space: normal;">5</code>
133
- </li>
134
- </ul>
135
- </div>
136
- </p>
137
- </div>
138
-
139
- <h3>Output options...</h3>
140
- <div style="padding-left: 15px;">
141
- <h4>Output property</h4>
142
- <ul>
143
- <li>The field to write the results to. Typically this is <code>msg.payload</code></li>
144
- </ul>
145
- <h4>Output type (not used for "Bulk Insert" mode)</h4>
146
- <ul>
147
- <li><b>Original output</b>: The property specified by 'Output property' will be populated with a single recordset (if
148
- any). This is the same as earlier mssql-plus version - for compatibility</li>
149
- <li><b>Driver output</b>: The property specified by 'Output property' will be populated with the result of the query
150
- direct from the driver output. This format can return multiple recordsets and other information. Add a
151
- debug node to see all available properties returned.</li>
152
- </ul>
153
- </div>
154
-
20
+
155
21
  <h3>Error Handling...</h3>
156
22
  <div style="padding-left: 15px;">
157
23
  <ul>
@@ -163,4 +29,4 @@
163
29
  </ul>
164
30
  </div>
165
31
 
166
- </script>
32
+ </script>
@@ -333,24 +333,59 @@
333
333
  const modeField = $('#node-input-modeOpt').typedInput({
334
334
  types: [
335
335
  { value: '1|Load Job Plan', label: 'Load Job Plan', hasValue: false },
336
- { value: '2|Change Job Plan', label: 'Change Job Plan', hasValue: false },
337
- { value: '3|Save Production', label: 'Save Production', hasValue: false }
336
+ { value: '4|Finish Production', label: 'Finish Production', hasValue: false },
337
+ { value: '5|Start Stoppage', label: 'Start Stoppage', hasValue: false },
338
+ { value: '6|Change Stoppage', label: 'Change Stoppage', hasValue: false },
339
+ { value: '7|Finish Stoppage', label: 'Finish Stoppage', hasValue: false },
340
+ { value: '9|Login Employee', label: 'Login Employee', hasValue: false },
341
+ { value: '10|Logout Employee', label: 'Logout Employee', hasValue: false },
342
+ { value: '13|Shifted Shift', label: 'Shifted Shift', hasValue: false },
343
+ { value: '14|Start Test Mode', label: 'Start Test Mode', hasValue: false },
344
+ { value: '15|Finish Test Mode', label: 'Finish Test Mode', hasValue: false },
345
+ { value: '16|Create Deffect', label: 'Create Deffect', hasValue: false }
338
346
  ],
339
347
  typeField: $('#node-input-modeOptType'),
340
348
  default: 'Load Job Plan'
341
349
  });
342
350
 
343
- //show/hide rows field depending on query type
351
+ //show expected data sample
344
352
  modeField.on('change', function() {
345
353
  const operationMode = $(this).typedInput('type');
346
354
 
347
355
  let data = '{}';
348
- if(operationMode.startsWith('1|')) {
356
+ if(operationMode.startsWith('1|')) { // Load Job Plan
349
357
  data = '{ "WorkstationId": 10 , "PlanId": 123 }';
350
358
  }
351
- else if(operationMode.startsWith('2|')) {
352
- data = '{"deneme": "123"}';
359
+ else if(operationMode.startsWith('4|')) { //Finish Production
360
+ data = '{ "WorkstationId": 10 }';
353
361
  }
362
+ else if(operationMode.startsWith('5|')) { //Start Stoppage
363
+ data = '{ "WorkstationId": 10 , "StoppageCauseId": 11 }';
364
+ }
365
+ else if(operationMode.startsWith('6|')) { //Change Stoppage
366
+ data = '{ "WorkstationId": 10 , "StoppageCauseId": 11 }';
367
+ }
368
+ else if(operationMode.startsWith('7|')) { //Finish Stoppage
369
+ data = '{ "WorkstationId": 10 }';
370
+ }
371
+ else if(operationMode.startsWith('9|')) { //Login Employee
372
+ data = '{ "WorkstationId": 10, "EmployeeId": 11 }';
373
+ }
374
+ else if(operationMode.startsWith('10|')) { //Logout Employee
375
+ data = '{ "WorkstationId": 10, "EmployeeId": 11 }';
376
+ }
377
+ else if(operationMode.startsWith('13|')) { //Shifted Shift
378
+ data = '{ "WorkstationId": 10, "LineId": 11 }';
379
+ }
380
+ else if(operationMode.startsWith('14|')) { //Start Test Mode
381
+ data = '{ "WorkstationId": 10, "StoppageCauseId": 11 }';
382
+ }
383
+ else if(operationMode.startsWith('15|')) { //Finish Test Mode
384
+ data = '{ "WorkstationId": 10 }';
385
+ }
386
+ else if(operationMode.startsWith('16|')) { //Create Deffect
387
+ data = '{ "WorkstationId": 10, "DefectId": 11,"StockId": 12, "Quantity": 15.5 }';
388
+ }
354
389
  node.editor.setValue(JSON.stringify(JSON.parse(data),null, 2));
355
390
 
356
391
  });
@@ -45,13 +45,73 @@ module.exports = function (RED) {
45
45
  result.command = JSON.stringify({ "WorkstationId" : payload.WorkstationId, "PlanId": payload.PlanId });
46
46
  result.isOk = true;
47
47
  }
48
- else if(payload.operationMode == "2" ) { // Change Job Plan
49
-
48
+ else if(payload.operationMode == "4" ) { // Finish Production
49
+ result.command = JSON.stringify({ "WorkstationId" : payload.WorkstationId, "Quantity": 0, "ReferenceQuantityType": 0, "IsQuantityApproved": false });
50
+ result.isOk = true;
50
51
  }
51
- else if(payload.operationMode == "3" ) { // Save Production
52
-
52
+ else if(payload.operationMode == "5" ) { // Start Stoppage
53
+ if(!payload.StoppageCauseId){
54
+ return result;
55
+ }
56
+ result.command = JSON.stringify({ "WorkstationId" : payload.WorkstationId, "StoppageCauseId": payload.StoppageCauseId });
57
+ result.isOk = true;
53
58
  }
54
-
59
+ else if(payload.operationMode == "6" ) { // Change Stoppage
60
+ if(!payload.StoppageCauseId){
61
+ return result;
62
+ }
63
+ result.command = JSON.stringify({ "WorkstationId" : payload.WorkstationId, "StoppageCauseId": payload.StoppageCauseId });
64
+ result.isOk = true;
65
+ }
66
+ else if(payload.operationMode == "7" ) { // Finish Stoppage
67
+ result.command = JSON.stringify({ "WorkstationId" : payload.WorkstationId });
68
+ result.isOk = true;
69
+ }
70
+ else if(payload.operationMode == "9" ) { // Login Employee
71
+ if(!payload.EmployeeId){
72
+ return result;
73
+ }
74
+ result.command = JSON.stringify({ "WorkstationId" : payload.WorkstationId, "EmployeeId": payload.EmployeeId });
75
+ result.isOk = true;
76
+ }
77
+ else if(payload.operationMode == "10" ) { // Logout Employee
78
+ if(!payload.EmployeeId){
79
+ return result;
80
+ }
81
+ result.command = JSON.stringify({ "WorkstationId" : payload.WorkstationId, "EmployeeId": payload.EmployeeId });
82
+ result.isOk = true;
83
+ }
84
+ else if(payload.operationMode == "13" ) { // Shifted Shift
85
+ if(!payload.LineId){
86
+ return result;
87
+ }
88
+ result.command = JSON.stringify({ "WorkstationId" : payload.WorkstationId, "LineId": payload.LineId });
89
+ result.isOk = true;
90
+ }
91
+ else if(payload.operationMode == "14" ) { // Start Test Mode
92
+ if(!payload.StoppageCauseId){
93
+ return result;
94
+ }
95
+ result.command = JSON.stringify({ "WorkstationId" : payload.WorkstationId, "StoppageCauseId": payload.StoppageCauseId });
96
+ result.isOk = true;
97
+ }
98
+ else if(payload.operationMode == "15" ) { // Finish Test Mode
99
+ result.command = JSON.stringify({ "WorkstationId" : payload.WorkstationId });
100
+ result.isOk = true;
101
+ }
102
+ else if(payload.operationMode == "16" ) { // Create Deffect
103
+ if(!payload.DefectId){
104
+ return result;
105
+ }
106
+ if(!payload.StockId){
107
+ return result;
108
+ }
109
+ if(!payload.Quantity){
110
+ return result;
111
+ }
112
+ result.command = JSON.stringify({ "WorkstationId" : payload.WorkstationId, "DefectId": payload.DefectId, "StockId": payload.StockId, "Quantity": payload.Quantity, "ReferenceQuantityType": 0 });
113
+ result.isOk = true;
114
+ }
55
115
  return result;
56
116
  }
57
117
 
@@ -372,7 +432,7 @@ module.exports = function (RED) {
372
432
  }
373
433
  //Process onay bekleniyor
374
434
  setTimeout(function () {
375
- query = "select COMMANDID,ISPROCESSED from NGPCOMMANDQUEUE where COMMANDID=" + commandId;
435
+ query = "select Q.COMMANDID,Q.ISPROCESSED,P.ISSUCCESS,P.MESSAGE from NGPCOMMANDQUEUE Q join NGPCOMMANDRESPONSE P on Q.COMMANDID = P.COMMANDID where P.COMMANDID=" + commandId;
376
436
  //node.log(query);
377
437
  trexmesCN.execSql("", query, [], {}, function (err, data, info) {
378
438
  if (err) {
@@ -380,23 +440,34 @@ module.exports = function (RED) {
380
440
  } else {
381
441
  setResult(msg, node.outField, data, node.returnType);
382
442
  let isProcessed = 0;
443
+ let isSuccess = 0;
444
+ let message = "";
383
445
  if(msg.payload.length>0) {
384
446
  isProcessed = msg.payload[0].ISPROCESSED;
447
+ isSuccess = msg.payload[0].ISSUCCESS;
448
+ message = msg.payload[0].MESSAGE;
385
449
  }
386
450
  node.send(msg);
387
- if(isProcessed == 1) {
451
+ if( isProcessed == 1 && isSuccess == 1) {
388
452
  node.status({
389
453
  fill: 'green',
390
454
  shape: 'dot',
391
455
  text: 'done'
392
456
  });
393
457
  }
458
+ else if( isProcessed == 1 && isSuccess == 0) {
459
+ node.status({
460
+ fill: 'yellow',
461
+ shape: 'dot',
462
+ text: 'done with error: ' + message
463
+ });
464
+ }
394
465
  else {
395
466
  node.status({
396
- fill: 'orange',
467
+ fill: 'blue',
397
468
  shape: 'dot',
398
469
  text: 'command not processed in 2 sec.'
399
- });
470
+ });
400
471
  }
401
472
  }
402
473
  });