@things-factory/integration-melsec 4.3.671 → 4.3.673

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.
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ require("./melsec-plc");
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../server/engine/connector/index.ts"],"names":[],"mappings":";;AAAA,wBAAqB"}
@@ -0,0 +1,186 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.MelsecPLCConnector = void 0;
7
+ const net_1 = __importDefault(require("net"));
8
+ const promise_socket_1 = __importDefault(require("promise-socket"));
9
+ const p_queue_1 = __importDefault(require("p-queue"));
10
+ const utils_1 = require("@things-factory/utils");
11
+ const integration_base_1 = require("@things-factory/integration-base");
12
+ const subHeader = '5000';
13
+ const networkNumber = '00';
14
+ const requireNumber = 'FF';
15
+ const requireIoNumber = '03FF';
16
+ const requireMultiNumber = '00';
17
+ const readrequireLength = '0018';
18
+ const writerequireLength = '0019';
19
+ const writewordrequireLength = '001C';
20
+ const reserve = '0000';
21
+ const readCommand = '0401';
22
+ const readWordSubCommand = '0000';
23
+ const readCoilSubCommand = '0001';
24
+ const writeCommand = '1401';
25
+ const writeWordSubCommand = '0000';
26
+ const writeSubCommand = '0001';
27
+ const readLengthDevice = '0001';
28
+ const writeLengthDevice = '0001';
29
+ class MelsecPLCConnector {
30
+ static getWriteCoilCommand(deviceCode, writeStartDevice, writeCoilValue, writeLength) {
31
+ if (writeLength) {
32
+ writeLength = writeLength.toString().padStart(4, '0');
33
+ }
34
+ return (subHeader +
35
+ networkNumber +
36
+ requireNumber +
37
+ requireIoNumber +
38
+ requireMultiNumber +
39
+ writerequireLength +
40
+ reserve +
41
+ writeCommand +
42
+ writeSubCommand +
43
+ deviceCode +
44
+ writeStartDevice +
45
+ (writeLength || writeLengthDevice) +
46
+ writeCoilValue);
47
+ }
48
+ static getWriteWordCommand(deviceCode, writeStartDevice, writeWordValue) {
49
+ return (subHeader +
50
+ networkNumber +
51
+ requireNumber +
52
+ requireIoNumber +
53
+ requireMultiNumber +
54
+ writewordrequireLength +
55
+ reserve +
56
+ writeCommand +
57
+ writeWordSubCommand +
58
+ deviceCode +
59
+ writeStartDevice +
60
+ writeLengthDevice +
61
+ writeWordValue);
62
+ }
63
+ static getReadCoilCommand(deviceCode, readStartDevice, readLength) {
64
+ if (readLength) {
65
+ readLength = readLength.toString().padStart(4, '0');
66
+ }
67
+ return (subHeader +
68
+ networkNumber +
69
+ requireNumber +
70
+ requireIoNumber +
71
+ requireMultiNumber +
72
+ readrequireLength +
73
+ reserve +
74
+ readCommand +
75
+ readCoilSubCommand +
76
+ deviceCode +
77
+ readStartDevice +
78
+ (readLength || readLengthDevice));
79
+ }
80
+ static getReadWordCommand(deviceCode, readStartDevice) {
81
+ return (subHeader +
82
+ networkNumber +
83
+ requireNumber +
84
+ requireIoNumber +
85
+ requireMultiNumber +
86
+ readrequireLength +
87
+ reserve +
88
+ readCommand +
89
+ readWordSubCommand +
90
+ deviceCode +
91
+ readStartDevice +
92
+ readLengthDevice);
93
+ }
94
+ async ready(connectionConfigs) {
95
+ await Promise.all(connectionConfigs.map(this.connect));
96
+ integration_base_1.ConnectionManager.logger.info('mitsubishi-plc connections are ready');
97
+ }
98
+ async connect(config) {
99
+ if (integration_base_1.ConnectionManager.getConnectionInstance(config)) {
100
+ return;
101
+ }
102
+ var [host, port = 1025] = config.endpoint.split(':');
103
+ var socket = new promise_socket_1.default(new net_1.default.Socket());
104
+ await socket.connect(port, host);
105
+ var queue = new p_queue_1.default({ concurrency: 1 });
106
+ var keepalive = true;
107
+ integration_base_1.ConnectionManager.addConnectionInstance(config, {
108
+ request: async function (message, length, { logger }) {
109
+ return await queue.add(async () => {
110
+ while (keepalive) {
111
+ try {
112
+ /* send request message */
113
+ await socket.write(message);
114
+ logger && logger.info(`Request : ${message}`);
115
+ var responseCompleted = '';
116
+ if (length > 0) {
117
+ while (length - responseCompleted.length > 0) {
118
+ logger && logger.info(`Will read ${length - responseCompleted.length}`);
119
+ let response = await socket.read(); // length - responseCompleted.length)
120
+ if (!response) {
121
+ // socket ended or closed
122
+ throw new Error('socket closed');
123
+ }
124
+ responseCompleted += response.toString();
125
+ }
126
+ }
127
+ else {
128
+ let response = await socket.read();
129
+ if (!response) {
130
+ // socket ended or closed
131
+ throw new Error('socket closed');
132
+ }
133
+ responseCompleted = response.toString();
134
+ }
135
+ logger && logger.info(`Response : ${responseCompleted}`);
136
+ return responseCompleted;
137
+ }
138
+ catch (e) {
139
+ logger.error('plc command(write-read) failed.');
140
+ logger.error(e);
141
+ if (keepalive) {
142
+ socket && socket.destroy();
143
+ socket = new promise_socket_1.default(new net_1.default.Socket());
144
+ await socket.connect(port, host);
145
+ await (0, utils_1.sleep)(1000);
146
+ }
147
+ else {
148
+ throw e;
149
+ }
150
+ }
151
+ }
152
+ throw new Error(`${config.name} maybe disconnected normally`);
153
+ });
154
+ },
155
+ close: function () {
156
+ queue.clear();
157
+ keepalive = false;
158
+ socket.destroy();
159
+ }
160
+ });
161
+ integration_base_1.ConnectionManager.logger.info(`mitsubishi-plc connection(${config.name}:${config.endpoint}) is connected`);
162
+ }
163
+ async disconnect(connection) {
164
+ var { close } = integration_base_1.ConnectionManager.removeConnectionInstance(connection);
165
+ close();
166
+ integration_base_1.ConnectionManager.logger.info(`mitsubishi-plc connection(${connection.name}) is disconnected`);
167
+ }
168
+ get parameterSpec() {
169
+ return [
170
+ {
171
+ type: 'checkbox',
172
+ name: 'keepalive',
173
+ label: 'keepalive'
174
+ }
175
+ ];
176
+ }
177
+ get taskPrefixes() {
178
+ return ['melsec'];
179
+ }
180
+ get help() {
181
+ return 'integration/connector/melsec-plc';
182
+ }
183
+ }
184
+ exports.MelsecPLCConnector = MelsecPLCConnector;
185
+ integration_base_1.ConnectionManager.registerConnector('melsec-plc', new MelsecPLCConnector());
186
+ //# sourceMappingURL=melsec-plc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"melsec-plc.js","sourceRoot":"","sources":["../../../server/engine/connector/melsec-plc.ts"],"names":[],"mappings":";;;;;;AAAA,8CAAqB;AACrB,oEAA0C;AAC1C,sDAA4B;AAC5B,iDAA6C;AAE7C,uEAA2F;AAE3F,MAAM,SAAS,GAAG,MAAM,CAAA;AACxB,MAAM,aAAa,GAAG,IAAI,CAAA;AAC1B,MAAM,aAAa,GAAG,IAAI,CAAA;AAC1B,MAAM,eAAe,GAAG,MAAM,CAAA;AAC9B,MAAM,kBAAkB,GAAG,IAAI,CAAA;AAC/B,MAAM,iBAAiB,GAAG,MAAM,CAAA;AAChC,MAAM,kBAAkB,GAAG,MAAM,CAAA;AACjC,MAAM,sBAAsB,GAAG,MAAM,CAAA;AACrC,MAAM,OAAO,GAAG,MAAM,CAAA;AACtB,MAAM,WAAW,GAAG,MAAM,CAAA;AAC1B,MAAM,kBAAkB,GAAG,MAAM,CAAA;AACjC,MAAM,kBAAkB,GAAG,MAAM,CAAA;AACjC,MAAM,YAAY,GAAG,MAAM,CAAA;AAC3B,MAAM,mBAAmB,GAAG,MAAM,CAAA;AAClC,MAAM,eAAe,GAAG,MAAM,CAAA;AAC9B,MAAM,gBAAgB,GAAG,MAAM,CAAA;AAC/B,MAAM,iBAAiB,GAAG,MAAM,CAAA;AAEhC,MAAa,kBAAkB;IAC7B,MAAM,CAAC,mBAAmB,CAAC,UAAU,EAAE,gBAAgB,EAAE,cAAc,EAAE,WAAW;QAClF,IAAI,WAAW,EAAE;YACf,WAAW,GAAG,WAAW,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;SACtD;QAED,OAAO,CACL,SAAS;YACT,aAAa;YACb,aAAa;YACb,eAA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AC,IAAI,CAAC,6BAA6B,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,QAAQ,gBAAgB,CAAC,CAAA;IAC5G,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,UAAsB;QACrC,IAAI,EAAE,KAAK,EAAE,GAAG,oCAAiB,CAAC,wBAAwB,CAAC,UAAU,CAAC,CAAA;QACtE,KAAK,EAAE,CAAA;QAEP,oCAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,6BAA6B,UAAU,CAAC,IAAI,mBAAmB,CAAC,CAAA;IAChG,CAAC;IAED,IAAI,aAAa;QACf,OAAO;YACL;gBACE,IAAI,EAAE,UAAU;gBAChB,IAAI,EAAE,WAAW;gBACjB,KAAK,EAAE,WAAW;aACnB;SACF,CAAA;IACH,CAAC;IAED,IAAI,YAAY;QACd,OAAO,CAAC,QAAQ,CAAC,CAAA;IACnB,CAAC;IAED,IAAI,IAAI;QACN,OAAO,kCAAkC,CAAA;IAC3C,CAAC;CACF;AAxLD,gDAwLC;AAED,oCAAiB,CAAC,iBAAiB,CAAC,YAAY,EAAE,IAAI,kBAAkB,EAAE,CAAC,CAAA"}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ require("./connector");
4
+ require("./task");
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/engine/index.ts"],"names":[],"mappings":";;AAAA,uBAAoB;AACpB,kBAAe"}
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ require("./melsec-read-coil");
4
+ require("./melsec-wait-coil");
5
+ require("./melsec-write-coil");
6
+ require("./melsec-read-word");
7
+ require("./melsec-write-word");
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../server/engine/task/index.ts"],"names":[],"mappings":";;AAAA,8BAA2B;AAC3B,8BAA2B;AAC3B,+BAA4B;AAC5B,8BAA2B;AAC3B,+BAA4B"}
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const integration_base_1 = require("@things-factory/integration-base");
4
+ const melsec_plc_1 = require("../connector/melsec-plc");
5
+ async function MelsecReadCoil(step, { logger, domain }) {
6
+ var { connection: connectionName, params: { plcAddress: address, readLength: readLength } } = step;
7
+ var connection = integration_base_1.ConnectionManager.getConnectionInstanceByName(domain, connectionName);
8
+ if (!connection) {
9
+ throw new Error(`connection '${connectionName}' is not established.`);
10
+ }
11
+ var { request } = connection;
12
+ var deviceCode = address.substring(0, 1) + '*';
13
+ var af_address = Number(address.substring(1)).toString();
14
+ var len = af_address.length;
15
+ for (var i = 0; i < 6 - len; i++) {
16
+ af_address = '0' + af_address;
17
+ }
18
+ var readStartDevice = af_address;
19
+ var sendMessage = melsec_plc_1.MelsecPLCConnector.getReadCoilCommand(deviceCode, readStartDevice, readLength);
20
+ // Request : 500000FF03FF000018000004010001M*0001000001
21
+ // Response : D00000FF03FF00000500000
22
+ var content = await request(sendMessage, 23, { logger }); // (22 + readLength)에서 현재 readLength는 1로 고정
23
+ // TODO readLength가 1이 아닐때 데이터 처리.
24
+ if (content.substring(17, 18) == '5') {
25
+ var data = content.substring(22, 23);
26
+ logger.info(content);
27
+ logger.info(`received response is ok. received: ${data}`);
28
+ return {
29
+ data
30
+ };
31
+ }
32
+ else {
33
+ // error
34
+ throw new Error('response not applicable');
35
+ }
36
+ }
37
+ MelsecReadCoil.parameterSpec = [
38
+ {
39
+ type: 'string',
40
+ name: 'plcAddress',
41
+ label: 'plc_address'
42
+ },
43
+ {
44
+ type: 'number',
45
+ name: 'readLength',
46
+ label: 'read_length'
47
+ }
48
+ ];
49
+ MelsecReadCoil.help = 'integration/task/melsec-read-coil';
50
+ integration_base_1.TaskRegistry.registerTaskHandler('melsec-read-coil', MelsecReadCoil);
51
+ //# sourceMappingURL=melsec-read-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2C;IAEpG,kCAAkC;IAClC,IAAI,OAAO,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,GAAG,EAAE;QACpC,IAAI,IAAI,GAAG,OAAO,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,CAAC,CAAA;QAEpC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QACpB,MAAM,CAAC,IAAI,CAAC,sCAAsC,IAAI,EAAE,CAAC,CAAA;QAEzD,OAAO;YACL,IAAI;SACL,CAAA;KACF;SAAM;QACL,QAAQ;QACR,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAA;KAC3C;AACH,CAAC;AAED,cAAc,CAAC,aAAa,GAAG;IAC7B;QACE,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,YAAY;QAClB,KAAK,EAAE,aAAa;KACrB;IACD;QACE,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,YAAY;QAClB,KAAK,EAAE,aAAa;KACrB;CACF,CAAA;AAED,cAAc,CAAC,IAAI,GAAG,mCAAmC,CAAA;AAEzD,+BAAY,CAAC,mBAAmB,CAAC,kBAAkB,EAAE,cAAc,CAAC,CAAA"}
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const integration_base_1 = require("@things-factory/integration-base");
4
+ const melsec_plc_1 = require("../connector/melsec-plc");
5
+ async function MelsecReadWord(step, { logger, domain }) {
6
+ var { connection: connectionName, params: { plcAddress: address, signed = false } } = step;
7
+ var connection = integration_base_1.ConnectionManager.getConnectionInstanceByName(domain, connectionName);
8
+ if (!connection) {
9
+ throw new Error(`connection '${connectionName}' is not established.`);
10
+ }
11
+ var { request } = connection;
12
+ var deviceCode = address.substring(0, 1) + '*';
13
+ var af_address = Number(address.substring(1)).toString();
14
+ var len = af_address.length;
15
+ for (var i = 0; i < 6 - len; i++) {
16
+ af_address = '0' + af_address;
17
+ }
18
+ var readStartDevice = af_address;
19
+ var sendMessage = melsec_plc_1.MelsecPLCConnector.getReadWordCommand(deviceCode, readStartDevice);
20
+ // Request : 500000FF03FF000018000004010000D*0001010001
21
+ // Response : D00000FF03FF000008000003E9
22
+ var content = await request(sendMessage, 26, { logger });
23
+ var wordValue = content.substring(22, 26);
24
+ var data = parseInt(wordValue, 16);
25
+ if (signed && (data & 0x8000) > 0) {
26
+ data -= 0x10000;
27
+ }
28
+ logger.info(content);
29
+ logger.info(`received response is ok. received: ${data}`);
30
+ return {
31
+ data
32
+ };
33
+ }
34
+ MelsecReadWord.parameterSpec = [
35
+ {
36
+ type: 'string',
37
+ name: 'plcAddress',
38
+ label: 'plc_address'
39
+ },
40
+ {
41
+ type: 'checkbox',
42
+ name: 'signed',
43
+ label: 'signed'
44
+ }
45
+ ];
46
+ MelsecReadWord.help = 'integration/task/melsec-read-word';
47
+ integration_base_1.TaskRegistry.registerTaskHandler('melsec-read-word', MelsecReadWord);
48
+ //# sourceMappingURL=melsec-read-word.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"melsec-read-word.js","sourceRoot":"","sources":["../../../server/engine/task/melsec-read-word.ts"],"names":[],"mappings":";;AAAA,uEAAkF;AAClF,wDAA4D;AAE5D,KAAK,UAAU,cAAc,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE;IACpD,IAAI,EACF,UAAU,EAAE,cAAc,EAC1B,MAAM,EAAE,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,GAAG,KAAK,EAAE,EAChD,GAAG,IAAI,CAAA;IAER,IAAI,UAAU,GAAG,oCAAiB,CAAC,2BAA2B,CAAC,MAAM,EAAE,cAAc,CAAC,CAAA;IACtF,IAAI,CAAC,UAAU,EAAE;QACf,MAAM,IAAI,KAAK,CAAC,eAAe,cAAc,uBAAuB,CAAC,CAAA;KACtE;IAED,IAAI,EAAE,OAAO,EAAE,GAAG,UAAU,CAAA;IAE5B,IAAI,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC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zD,+BAAY,CAAC,mBAAmB,CAAC,kBAAkB,EAAE,cAAc,CAAC,CAAA"}
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const integration_base_1 = require("@things-factory/integration-base");
4
+ const utils_1 = require("@things-factory/utils");
5
+ const melsec_plc_1 = require("../connector/melsec-plc");
6
+ async function MelsecWaitForCoil(step, { logger, root, domain }) {
7
+ var { connection: connectionName, params: { plcAddress: address, value, waitTerm = 50 } } = step;
8
+ var connection = integration_base_1.ConnectionManager.getConnectionInstanceByName(domain, connectionName);
9
+ if (!connection) {
10
+ throw new Error(`connection '${connectionName}' is not established.`);
11
+ }
12
+ var { request } = connection;
13
+ var deviceCode = address.substring(0, 1) + '*';
14
+ var af_address = Number(address.substring(1)).toString();
15
+ var len = af_address.length;
16
+ for (var i = 0; i < 6 - len; i++) {
17
+ af_address = '0' + af_address;
18
+ }
19
+ var readStartDevice = af_address;
20
+ var sendMessage = melsec_plc_1.MelsecPLCConnector.getReadCoilCommand(deviceCode, readStartDevice, undefined);
21
+ while (true) {
22
+ let state = root.getState();
23
+ if (state == integration_base_1.ScenarioInstanceStatus.STARTED /* STARTED */) {
24
+ var content = await request(sendMessage, 23, { logger });
25
+ if (content.substring(17, 18) == '5') {
26
+ var coilValue = content.substring(22, 23);
27
+ if (value == coilValue) {
28
+ logger.info('received response is ok. required: %s, received: %s', value, coilValue);
29
+ return {
30
+ data: coilValue
31
+ };
32
+ }
33
+ else {
34
+ logger.info('received response, but not accepted. required: %s, received: %s', value, coilValue);
35
+ await (0, utils_1.sleep)(waitTerm);
36
+ continue;
37
+ }
38
+ }
39
+ else {
40
+ // error
41
+ throw new Error('response not applicable');
42
+ }
43
+ }
44
+ else if (state == integration_base_1.ScenarioInstanceStatus.STOPPED /* PAUSED */) {
45
+ await (0, utils_1.sleep)(waitTerm);
46
+ }
47
+ else {
48
+ throw new Error('scenario stopped unexpectedly');
49
+ }
50
+ }
51
+ }
52
+ MelsecWaitForCoil.parameterSpec = [
53
+ {
54
+ type: 'string',
55
+ name: 'plcAddress',
56
+ label: 'plc_address'
57
+ },
58
+ {
59
+ type: 'string',
60
+ name: 'value',
61
+ label: 'expected_value'
62
+ },
63
+ {
64
+ type: 'number',
65
+ name: 'waitTerm',
66
+ placeholder: 'milli-seconds',
67
+ label: 'wait_term'
68
+ }
69
+ ];
70
+ MelsecWaitForCoil.help = 'integration/task/melsec-wait-coil';
71
+ integration_base_1.TaskRegistry.registerTaskHandler('melsec-wait-coil', MelsecWaitForCoil);
72
+ //# sourceMappingURL=melsec-wait-coil.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"melsec-wait-coil.js","sourceRoot":"","sources":["../../../server/engine/task/melsec-wait-coil.ts"],"names":[],"mappings":";;AAAA,uEAA0G;AAC1G,iDAA6C;AAE7C,wDAA4D;AAE5D,KAAK,UAAU,iBAAiB,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE;IAC7D,IAAI,EACF,UAAU,EAAE,cAAc,EAC1B,MAAM,EAAE,EAAE,UAAU,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,GAAG,EAAE,EAAE,EACtD,GAAG,IAAI,CAAA;IAER,IAAI,UAAU,GAAG,oCAAiB,CAAC,2BAA2B,CAAC,MAAM,EAAE,cAAc,CAAC,CAAA;IACtF,IAAI,CAAC,UAAU,EAAE;QACf,MAAM,IAAI,KAAK,CAAC,eAAe,cAAc,uBAAuB,CAAC,CAAA;KACtE;IAED,IAAI,EAAE,OAAO,EAAE,GAAG,UAAU,CAAA;IAE5B,IAAI,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,GAAG,CAAA;IAC9C,IAAI,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAA;IACxD,IAAI,GAAG,GAAG,UAAU,CAAC,MAAM,CA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KAAK,CAAC,+BAA+B,CAAC,CAAA;SACjD;KACF;AACH,CAAC;AAED,iBAAiB,CAAC,aAAa,GAAG;IAChC;QACE,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,YAAY;QAClB,KAAK,EAAE,aAAa;KACrB;IACD;QACE,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,OAAO;QACb,KAAK,EAAE,gBAAgB;KACxB;IACD;QACE,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,UAAU;QAChB,WAAW,EAAE,eAAe;QAC5B,KAAK,EAAE,WAAW;KACnB;CACF,CAAA;AAED,iBAAiB,CAAC,IAAI,GAAG,mCAAmC,CAAA;AAE5D,+BAAY,CAAC,mBAAmB,CAAC,kBAAkB,EAAE,iBAAiB,CAAC,CAAA"}
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const integration_base_1 = require("@things-factory/integration-base");
4
+ const melsec_plc_1 = require("../connector/melsec-plc");
5
+ const utils_1 = require("@things-factory/utils");
6
+ async function MelsecWriteCoil(step, { logger, domain }) {
7
+ var { connection: connectionName, params: { plcAddress: address, value, writeLength = 1, autoReset, delay = 50 } } = step;
8
+ var connection = integration_base_1.ConnectionManager.getConnectionInstanceByName(domain, connectionName);
9
+ if (!connection) {
10
+ throw new Error(`connection '${connectionName}' is not established.`);
11
+ }
12
+ var { request } = connection;
13
+ var w_address = address;
14
+ var w_value = value;
15
+ var deviceCode = w_address.substring(0, 1) + '*';
16
+ var af_address = Number(w_address.substring(1)).toString();
17
+ var len = af_address.length;
18
+ for (var i = 0; i < 6 - len; i++) {
19
+ af_address = '0' + af_address;
20
+ }
21
+ var writeStartDevice = af_address;
22
+ if (w_value == 1) {
23
+ var writeCoilValue = '1';
24
+ }
25
+ else {
26
+ var writeCoilValue = '0';
27
+ }
28
+ await doRequest(request, deviceCode, writeStartDevice, writeCoilValue, writeLength, logger);
29
+ if (autoReset) {
30
+ await (0, utils_1.sleep)(delay);
31
+ await doRequest(request, deviceCode, writeStartDevice, Number(!Number(writeCoilValue)), writeLength, logger);
32
+ }
33
+ return {
34
+ data: writeCoilValue
35
+ };
36
+ }
37
+ async function doRequest(request, deviceCode, writeStartDevice, writeCoilValue, writeLength, logger) {
38
+ var sendMessage = melsec_plc_1.MelsecPLCConnector.getWriteCoilCommand(deviceCode, writeStartDevice, writeCoilValue, writeLength);
39
+ // Request : 500000FF03FF000019000014010001M*00033300011
40
+ // Response : D00000FF03FF0000040000
41
+ var content = await request(sendMessage, 22, { logger });
42
+ // TODO writeLength 1이 아닐때 데이터 처리.
43
+ if (content.substring(17, 18) == '4') {
44
+ // ok
45
+ return {
46
+ data: writeCoilValue
47
+ };
48
+ }
49
+ else {
50
+ // error
51
+ throw new Error('response not applicable');
52
+ }
53
+ }
54
+ MelsecWriteCoil.parameterSpec = [
55
+ {
56
+ type: 'string',
57
+ name: 'plcAddress',
58
+ placeholder: 'M0,Y1,..',
59
+ label: 'plc_address'
60
+ },
61
+ {
62
+ type: 'number',
63
+ name: 'writeLength',
64
+ label: 'write_length'
65
+ },
66
+ {
67
+ type: 'number',
68
+ name: 'value',
69
+ label: 'value'
70
+ },
71
+ {
72
+ type: 'checkbox',
73
+ name: 'autoReset',
74
+ label: 'auto_reset'
75
+ },
76
+ {
77
+ type: 'number',
78
+ name: 'delay',
79
+ placeholder: 'milisecodes, default is 50ms',
80
+ label: 'reset_delay'
81
+ }
82
+ ];
83
+ MelsecWriteCoil.help = 'integration/task/melsec-write-coil';
84
+ integration_base_1.TaskRegistry.registerTaskHandler('melsec-write-coil', MelsecWriteCoil);
85
+ //# sourceMappingURL=melsec-write-coil.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"melsec-write-coil.js","sourceRoot":"","sources":["../../../server/engine/task/melsec-write-coil.ts"],"names":[],"mappings":";;AAAA,uEAAkF;AAClF,wDAA4D;AAE5D,iDAA6C;AAE7C,KAAK,UAAU,eAAe,CAAC,IAAI,EAAE,EAAE,MAA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8BAA8B;QAC3C,KAAK,EAAE,aAAa;KACrB;CACF,CAAA;AAED,eAAe,CAAC,IAAI,GAAG,oCAAoC,CAAA;AAE3D,+BAAY,CAAC,mBAAmB,CAAC,mBAAmB,EAAE,eAAe,CAAC,CAAA"}
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const integration_base_1 = require("@things-factory/integration-base");
4
+ const utils_1 = require("@things-factory/utils");
5
+ const melsec_plc_1 = require("../connector/melsec-plc");
6
+ async function MelsecWriteWord(step, { data, logger, domain }) {
7
+ var { connection: connectionName, params: { plcAddress: address, accessor, value } } = step;
8
+ var connection = integration_base_1.ConnectionManager.getConnectionInstanceByName(domain, connectionName);
9
+ if (!connection) {
10
+ throw new Error(`connection '${connectionName}' is not established.`);
11
+ }
12
+ var { request } = connection;
13
+ var w_address = address;
14
+ var deviceCode = w_address.substring(0, 1) + '*';
15
+ var af_address = Number(w_address.substring(1)).toString();
16
+ var len = af_address.length;
17
+ for (var i = 0; i < 6 - len; i++) {
18
+ af_address = '0' + af_address;
19
+ }
20
+ var writeStartDevice = af_address;
21
+ value = accessor ? (0, utils_1.access)(accessor, data) : value;
22
+ if (isNaN(value)) {
23
+ throw new Error(`invalid number value : ${value}`);
24
+ }
25
+ var valueDefine = Number(value).toString(16);
26
+ var writeWordValue = '';
27
+ if (valueDefine.length == 1) {
28
+ writeWordValue = '000' + Number(value).toString(16);
29
+ }
30
+ else if (valueDefine.length == 2) {
31
+ writeWordValue = '00' + Number(value).toString(16);
32
+ }
33
+ else if (valueDefine.length == 3) {
34
+ writeWordValue = '0' + Number(value).toString(16);
35
+ }
36
+ else if (valueDefine.length == 4) {
37
+ writeWordValue = Number(value).toString(16);
38
+ }
39
+ // Request : 500000FF03FF00001C000014010000D*00010000010001
40
+ // Response : D00000FF03FF0000040000
41
+ logger.info(`will send request value: ${value}:${writeWordValue}`);
42
+ var sendMessage = melsec_plc_1.MelsecPLCConnector.getWriteWordCommand(deviceCode, writeStartDevice, writeWordValue);
43
+ var content = await request(sendMessage, 22, { logger });
44
+ logger.info(`received response: ${content}`);
45
+ return {
46
+ data: writeWordValue
47
+ };
48
+ }
49
+ MelsecWriteWord.parameterSpec = [
50
+ {
51
+ type: 'string',
52
+ name: 'plcAddress',
53
+ placeholder: 'M0,Y1,..',
54
+ label: 'plc_address'
55
+ },
56
+ {
57
+ type: 'scenario-step-input',
58
+ name: 'accessor',
59
+ label: 'accessor'
60
+ },
61
+ {
62
+ type: 'number',
63
+ name: 'value',
64
+ label: 'value'
65
+ }
66
+ ];
67
+ MelsecWriteWord.help = 'integration/task/melsec-write-word';
68
+ integration_base_1.TaskRegistry.registerTaskHandler('melsec-write-word', MelsecWriteWord);
69
+ //# sourceMappingURL=melsec-write-word.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"melsec-write-word.js","sourceRoot":"","sources":["../../../server/engine/task/melsec-write-word.ts"],"names":[],"mappings":";;AAAA,uEAAkF;AAClF,iDAA8C;AAC9C,wDAA4D;AAE5D,KAAK,UAAU,eAAe,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE;IAC3D,IAAI,EACF,UAAU,EAAE,cAAc,EAC1B,MAAM,EAAE,EAAE,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,EACjD,GAAG,IAAI,CAAA;IAER,IAAI,UAAU,GAAG,oCAAiB,CAAC,2BAA2B,CAAC,MAAM,EAAE,cAAc,CAAC,CAAA;IACtF,IAAI,CAAC,UAAU,EAAE;QACf,MAAM,IAAI,KAAK,CAAC,eAAe,cAAc,uBAAuB,CAAC,CAAA;KACtE;IAED,IAAI,EAAE,OAAO,EAAE,GAAG,UAAU,CAAA;IAE5B,IAAI,SAAS,GAAG,OAAO,CAAA;IACvB,IAAI,UAAU,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,GAAG,CAAA;IAEhD,IAAI,UAAU,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AA;KAC5C;IAED,2DAA2D;IAC3D,oCAAoC;IACpC,MAAM,CAAC,IAAI,CAAC,4BAA4B,KAAK,IAAI,cAAc,EAAE,CAAC,CAAA;IAElE,IAAI,WAAW,GAAG,+BAAkB,CAAC,mBAAmB,CAAC,UAAU,EAAE,gBAAgB,EAAE,cAAc,CAAC,CAAA;IACtG,IAAI,OAAO,GAAG,MAAM,OAAO,CAAC,WAAW,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC,CAAA;IAExD,MAAM,CAAC,IAAI,CAAC,sBAAsB,OAAO,EAAE,CAAC,CAAA;IAE5C,OAAO;QACL,IAAI,EAAE,cAAc;KACrB,CAAA;AACH,CAAC;AAED,eAAe,CAAC,aAAa,GAAG;IAC9B;QACE,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,YAAY;QAClB,WAAW,EAAE,UAAU;QACvB,KAAK,EAAE,aAAa;KACrB;IACD;QACE,IAAI,EAAE,qBAAqB;QAC3B,IAAI,EAAE,UAAU;QAChB,KAAK,EAAE,UAAU;KAClB;IACD;QACE,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,OAAO;QACb,KAAK,EAAE,OAAO;KACf;CACF,CAAA;AAED,eAAe,CAAC,IAAI,GAAG,oCAAoC,CAAA;AAE3D,+BAAY,CAAC,mBAAmB,CAAC,mBAAmB,EAAE,eAAe,CAAC,CAAA"}
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ require("./engine");
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../server/index.ts"],"names":[],"mappings":";;AAAA,oBAAiB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/integration-melsec",
3
- "version": "4.3.671",
3
+ "version": "4.3.673",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "client/index.js",
6
6
  "things-factory": true,
@@ -22,8 +22,8 @@
22
22
  "clean": "npm run clean:server"
23
23
  },
24
24
  "dependencies": {
25
- "@things-factory/integration-base": "^4.3.671",
25
+ "@things-factory/integration-base": "^4.3.673",
26
26
  "p-queue": "^6.4.0"
27
27
  },
28
- "gitHead": "ef524cb207378186ec71917d9a8546363d4300b2"
28
+ "gitHead": "d22f985380f3af2ebc0f81ea8bec478ba00b4777"
29
29
  }