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
Nikola Balog
osie
Commits
57c14e10
Commit
57c14e10
authored
Sep 29, 2021
by
Ivan Tyagov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extend example.
parent
3ed110ea
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
4 deletions
+12
-4
coupler/opc-ua-server/ic2_set_relays_example.c
coupler/opc-ua-server/ic2_set_relays_example.c
+12
-4
No files found.
coupler/opc-ua-server/ic2_set_relays_example.c
View file @
57c14e10
// Example controling MOD-IO's relays' state
// Based on https://www.kernel.org/doc/Documentation/i2c/dev-interface
/*
Example controling MOD-IO's relays' state
Based on https://www.kernel.org/doc/Documentation/i2c/dev-interface
To compile:
root@olimex-rt:~/osie/coupler/opc-ua-server# gcc ic2_set_relays_example.c -o ic2_set_relays_example
root@olimex-rt:~/osie/coupler/opc-ua-server# ./ic2_set_relays_example
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
...
...
@@ -12,6 +19,7 @@ int main()
{
int
file
;
int
adapter_nr
=
1
;
/* probably dynamically determined */
int
addr
=
0x58
;
/* The I2C slave's address */
char
filename
[
20
];
// step 1: open device
...
...
@@ -24,7 +32,6 @@ int main()
}
// step 2: address the slave by its address
int
addr
=
0x58
;
/* The I2C address */
if
(
ioctl
(
file
,
I2C_SLAVE
,
addr
)
<
0
)
{
/* ERROR HANDLING; you can check errno to see what went wrong */
printf
(
"Error addressing i2c slave."
);
...
...
@@ -36,7 +43,8 @@ int main()
__s32
res
;
char
buf
[
10
];
buf
[
0
]
=
reg
;
buf
[
1
]
=
0x05
;
//0x00 -all off, 0x0F - all 4 on
buf
[
1
]
=
0x07
;
// the most right bits represent 4 relays' state: for example 00001111 - means all ON
// send as a hexadecimal number
buf
[
2
]
=
0x65
;
// seems irrelevant the value
if
(
write
(
file
,
buf
,
3
)
!=
3
)
{
/* ERROR HANDLING: i2c transaction failed */
...
...
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