Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
osie
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
osie
Commits
94dc1896
Commit
94dc1896
authored
Oct 05, 2021
by
Ivan Tyagov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Set ON/OFF relay0 at setting a variable over OPC-UA call (WIP).
parent
f170efca
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
0 deletions
+37
-0
coupler/opc-ua-server/server.c
coupler/opc-ua-server/server.c
+37
-0
No files found.
coupler/opc-ua-server/server.c
View file @
94dc1896
...
...
@@ -86,6 +86,42 @@ static void addVariable(UA_Server *server) {
UA_NODEID_NUMERIC
(
0
,
UA_NS0ID_BASEDATAVARIABLETYPE
),
attr
,
NULL
,
NULL
);
}
/* Connecto to physcal relays
*
*/
static
void
beforeReadTime
(
UA_Server
*
server
,
const
UA_NodeId
*
sessionId
,
void
*
sessionContext
,
const
UA_NodeId
*
nodeid
,
void
*
nodeContext
,
const
UA_NumericRange
*
range
,
const
UA_DataValue
*
data
)
{
//printf("Before read.");
}
static
void
afterWriteTime
(
UA_Server
*
server
,
const
UA_NodeId
*
sessionId
,
void
*
sessionContext
,
const
UA_NodeId
*
nodeId
,
void
*
nodeContext
,
const
UA_NumericRange
*
range
,
const
UA_DataValue
*
data
)
{
UA_LOG_INFO
(
UA_Log_Stdout
,
UA_LOGCATEGORY_USERLAND
,
"The variable was updated"
);
setRelayState
(
0x0F
);
printf
(
"Relays ON.
\n
"
);
// wait 1s
sleep
(
1
);
// switch off all relays
setRelayState
(
0x00
);
}
static
void
addValueCallbackToCurrentTimeVariable
(
UA_Server
*
server
)
{
UA_NodeId
currentNodeId
=
UA_NODEID_STRING
(
1
,
"relay0"
);
UA_ValueCallback
callback
;
callback
.
onRead
=
beforeReadTime
;
callback
.
onWrite
=
afterWriteTime
;
UA_Server_setVariableNode_valueCallback
(
server
,
currentNodeId
,
callback
);
}
/**
* Now we change the value with the write service. This uses the same service
* implementation that can also be reached over the network by an OPC UA client.
...
...
@@ -154,6 +190,7 @@ int main(void) {
addVariable
(
server
);
writeVariable
(
server
);
addValueCallbackToCurrentTimeVariable
(
server
);
UA_StatusCode
retval
=
UA_Server_run
(
server
,
&
running
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment