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
0
Merge Requests
0
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
Martin Manchev
osie
Commits
2799f12f
Commit
2799f12f
authored
Oct 05, 2021
by
Ivan Tyagov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanups.
parent
94dc1896
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
32 deletions
+10
-32
coupler/opc-ua-server/server.c
coupler/opc-ua-server/server.c
+10
-32
No files found.
coupler/opc-ua-server/server.c
View file @
2799f12f
/* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
* See http://creativecommons.org/publicdomain/zero/1.0/ for more information. */
/**
* Adding Variables to a Server
* ----------------------------
*
* This tutorial shows how to work with data types and how to add variable nodes
* to a server. First, we add a new variable to the server. Take a look at the
* definition of the ``UA_VariableAttributes`` structure to see the list of all
* attributes defined for VariableNodes.
*
* Note that the default settings have the AccessLevel of the variable value as
* read only. See below for making the variable writable.
/*
* Example controling MOD-IO's relays' state over OPC-UA protocol
* Based on
* https://www.kernel.org/doc/Documentation/i2c/dev-interface
* https://github.com/open62541/open62541/blob/master/examples/tutorial_server_variable.c
*/
// Example controling MOD-IO's relays' state
// Based on https://www.kernel.org/doc/Documentation/i2c/dev-interface
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
...
...
@@ -24,14 +13,14 @@
#include <sys/ioctl.h>
#include <unistd.h>
#include <signal.h>
#include <open62541/plugin/log_stdout.h>
#include <open62541/server.h>
#include <open62541/server_config_default.h>
// relays
static
int
setRelayState
(
int
command
)
{
// Set relays' state over I2C
/*
* Set relays' state over I2C
*/
int
file
;
int
adapter_nr
=
1
;
/* probably dynamically determined */
char
filename
[
20
];
...
...
@@ -86,7 +75,7 @@ static void addVariable(UA_Server *server) {
UA_NODEID_NUMERIC
(
0
,
UA_NS0ID_BASEDATAVARIABLETYPE
),
attr
,
NULL
,
NULL
);
}
/* Connecto to
phys
cal relays
/* Connecto to
variables to physi
cal relays
*
*/
static
void
beforeReadTime
(
UA_Server
*
server
,
...
...
@@ -156,9 +145,9 @@ static void writeVariable(UA_Server *server) {
UA_Server_write
(
server
,
&
wv
);
}
/** It follows the main server code, making use of the above definitions. */
static
volatile
UA_Boolean
running
=
true
;
static
void
stopHandler
(
int
sign
)
{
UA_LOG_INFO
(
UA_Log_Stdout
,
UA_LOGCATEGORY_SERVER
,
"received ctrl-c"
);
running
=
false
;
...
...
@@ -166,17 +155,6 @@ static void stopHandler(int sign) {
int
main
(
void
)
{
// switch on all relays
setRelayState
(
0x0F
);
printf
(
"Relays ON.
\n
"
);
// wait 1s
sleep
(
1
);
// switch off all relays
setRelayState
(
0x00
);
printf
(
"Relays OFF.
\n
"
);
signal
(
SIGINT
,
stopHandler
);
signal
(
SIGTERM
,
stopHandler
);
...
...
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