-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4749793
commit 8f4f1fb
Showing
7 changed files
with
87 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<script type="text/javascript"> | ||
RED.nodes.registerType('opcua-write', { | ||
category: 'opcuax', | ||
color: '#a6bbcf', | ||
defaults: { | ||
client: { value: "", required: true, type: "opcua-client" }, | ||
nodeid: { required: true }, | ||
}, | ||
inputs: 1, | ||
outputs: 0, | ||
icon: "opcua-logo.png", | ||
label: function () { | ||
return this.defaults.client.name; | ||
} | ||
}); | ||
</script> | ||
|
||
<script type="text/html" data-template-name="opcua-write"> | ||
<div class="form-row"> | ||
<label for="node-input-client"><i class="fa fa-plug"></i> Client</label> | ||
<input type="text" id="node-input-client" placeholder=""> | ||
</div> | ||
<div class="form-row"> | ||
<label for="node-input-nodeid"><i class="fa fa-link"></i> NodeId</label> | ||
<input type="text" id="node-input-nodeid" placeholder="ns=*;i=*, ns=*;s=*"> | ||
</div> | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// See example https://github.com/node-opcua/node-opcua/blob/af235f19e9e353fa748c11009b1300f76026fb28/packages/node-opcua-service-write/test/test_service_write.js | ||
module.exports = function (RED) { | ||
|
||
var core = require('./core'); | ||
var opcua = require('node-opcua'); | ||
|
||
function opcUaWriteNode(args) { | ||
|
||
RED.nodes.createNode(this, args); | ||
const opcuaclientnode = RED.nodes.getNode(args.client); | ||
const existingClient = core.opcClients[opcuaclientnode.connectionId]; | ||
|
||
var node = this; | ||
|
||
node.name = args.name; | ||
node.nodeId = args.nodeid; | ||
|
||
node.on('input', function (msg) { | ||
|
||
if(existingClient.clientState == "reconnecting") return; | ||
if(existingClient.clientState == "disconnected") return; | ||
|
||
// Override nodeId from incoming node if not defined on read node | ||
//if (!args.nodeId && msg.nodeId) node.nodeId = msg.nodeId; | ||
|
||
const value = msg.payload.value; | ||
|
||
write(value); | ||
}); | ||
|
||
async function write(requestValue) { | ||
const dataType = await existingClient.session.getBuiltInDataType(node.nodeId); | ||
const resultStatus = await existingClient.session.write({ | ||
nodeId: node.nodeId, | ||
attributeId: opcua.AttributeIds.Value, | ||
value: new opcua.DataValue({ | ||
value: new opcua.Variant({ | ||
dataType: dataType, | ||
value: requestValue | ||
}) | ||
}) | ||
}); | ||
node.debug(resultStatus.description); | ||
} | ||
} | ||
|
||
RED.nodes.registerType("opcua-write", opcUaWriteNode); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters