Skip to content

Commit 6e8c0e2

Browse files
authored
docs: Add cosine.js for addReturn() example (#271)
1 parent 8c7bd79 commit 6e8c0e2

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

docs/ProgramCall.rst

+8-1
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,18 @@ ProgramCall API
1313
.. autofunction:: returnConfig
1414
.. autofunction:: data
1515

16-
Example
16+
Examples
1717
^^^^^^^^
1818

1919
Call the QUSROBJD Program
2020
"""""""""""""""""""""""""
2121

2222
.. literalinclude:: examples/qusrobjd.js
2323
:language: javascript
24+
25+
Retrieve the Return Value From a Service Program
26+
""""""""""""""""""""""""""""""""""""""""""""""""
27+
28+
.. literalinclude:: examples/cosine.js
29+
:language: javascript
30+

docs/examples/cosine.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const { Connection, ProgramCall } = require('itoolkit');
2+
const { parseString } = require('xml2js');
3+
4+
const conn = new Connection({
5+
transport: 'ssh',
6+
transportOptions: { host: 'myhost', username: 'myuser', password: 'mypassword' },
7+
});
8+
9+
const program = new ProgramCall('QC2UTIL2', { lib: 'QSYS', func: 'cos' });
10+
11+
program.addParam({ type: '8f', value: '0' });
12+
program.addReturn({ type: '8f', value: '' });
13+
14+
conn.add(program);
15+
conn.debug(true);
16+
17+
conn.run((error, xmlOutput) => {
18+
if (error) {
19+
throw error;
20+
}
21+
parseString(xmlOutput, (parseError, result) => {
22+
if (parseError) {
23+
throw parseError;
24+
}
25+
console.log(result.myscript.pgm[0].return[0].data[0]._); // 1
26+
});
27+
});

0 commit comments

Comments
 (0)