forked from CANopenNode/CANopenSocket
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
256 lines (196 loc) · 11.1 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link href='https://fonts.googleapis.com/css?family=Architects+Daughter' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type="text/css" href="stylesheets/stylesheet.css" media="screen">
<link rel="stylesheet" type="text/css" href="stylesheets/github-light.css" media="screen">
<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print">
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<title>CANopenSocket by CANopenNode</title>
</head>
<body>
<header>
<div class="inner">
<h1>CANopenSocket</h1>
<h2>CANopen implementation for Linux SocketCAN with master command interface.</h2>
<a href="https://github.com/CANopenNode/CANopenSocket" class="button"><small>View project on</small> GitHub</a>
</div>
</header>
<div id="content-wrapper">
<div class="inner clearfix">
<section id="main-content">
<h1>
<a id="canopensocket" class="anchor" href="#canopensocket" aria-hidden="true"><span class="octicon octicon-link"></span></a>CANopenSocket</h1>
<p>CANopenSocket is a collection of CANopen tools running on Linux with socketCAN interface.
It is based on CANopenNode, which is an opensource <a href="http://can-cia.org/">CANopen</a> Stack
(<a href="http://can-cia.org/standardization/technical-documents">CiA301</a>) and is included as a git submodule.</p>
<p>CANopenSocket may be used as a master or a slave device. However, CANopen itself is not a
typical master/slave protocol. It is more like producer/consumer protocol. It is also
possible to operate CANopen network without a master. Pre-configured process data (PDO)
are transmitted from producers. Each PDO may be consumed by multiple nodes.</p>
<p>CANopen master of CANopenNode functionality contains command line interface with SDO and NMT master
commands. With SDO master (or SDO client) it is possible to read or write any variable on any device
on the CANopen Network. NMT master can start, stop or reset nodes.</p>
<p>CANopenNode should run on any Linux machine. Examples below was tested on Debian based machines,
including <strong>Ubuntu</strong>, <strong>Beaglebone Black</strong> and <strong>Raspberry PI</strong>. It is possible to run tests described
below without real CAN interface, because Linux kernel already contains virtual CAN interface.</p>
<p>CANopenSocket consists of two applocations: <strong>canopend</strong>, which runs in background, and
<strong>canopencomm</strong>, command interface for SDO and NMT master.</p>
<h3>
<a id="canopend" class="anchor" href="#canopend" aria-hidden="true"><span class="octicon octicon-link"></span></a>canopend</h3>
<p><strong>canopend</strong> is an implementation of CANopen device with master functionality. It runs within three
threads. Realtime thread processes CANopen SYNC and PDO objects. Mainline thread processes other
non time critical objects. Both are nonblocking. Command interface thread is blocking. It accepts
commands from socket connection from external application and executes master SDO and NMT tasks.</p>
<h3>
<a id="canopencomm" class="anchor" href="#canopencomm" aria-hidden="true"><span class="octicon octicon-link"></span></a>canopencomm</h3>
<p><strong>canopencomm</strong> is the other end of the Command interface. It accepts text commands form arguments
or from standard input or from file. It sends commands to <em>canopend</em> via socket, line after line.
Received result is printed to standard output. It is implementation of the CiA 309 standard.</p>
<h2>
<a id="getting-started-with-canopen-socket" class="anchor" href="#getting-started-with-canopen-socket" aria-hidden="true"><span class="octicon octicon-link"></span></a>Getting started with CANopen Socket</h2>
<p>We will run two instances of <em>CANopend</em>. First will be basic node with ID=4,
second, with nodeID = 3, will have master functionality.</p>
<h3>
<a id="get-the-project" class="anchor" href="#get-the-project" aria-hidden="true"><span class="octicon octicon-link"></span></a>Get the project</h3>
<p>Clone the project from git repoitory and get submodules:</p>
<pre><code>$ git clone https://github.com/CANopenNode/CANopenSocket.git
$ cd CANopenSocket
$ git submodule init
$ git submodule update
</code></pre>
<p>(If you want to work on submodule CANopenNode, you can apply git commands directly on it:)</p>
<pre><code>$ cd CANopenNode
$ git checkout master
$ git remote -v
$ git remote set-url origin {url-of-your-git-repository}
$ git remote add {yourName} {url-of-your-git-repository} # alternative
$ git pull ({yourName} {yourbranch})
$ # etc.
</code></pre>
<h3>
<a id="first-terminal-can-dump" class="anchor" href="#first-terminal-can-dump" aria-hidden="true"><span class="octicon octicon-link"></span></a>First terminal: CAN dump</h3>
<p>Prepare CAN virtual (or real) device:</p>
<pre><code>$ sudo modprobe vcan
$ sudo ip link add dev vcan0 type vcan
$ sudo ip link set up vcan0
</code></pre>
<p>Run candump from <a href="https://github.com/linux-can/can-utils">can-utils</a>:</p>
<pre><code>$ sudo apt-get install can-utils
$ candump vcan0
</code></pre>
<p>It will show all CAN trafic on vcan0.</p>
<h3>
<a id="second-terminal-canopend" class="anchor" href="#second-terminal-canopend" aria-hidden="true"><span class="octicon octicon-link"></span></a>Second terminal: canopend</h3>
<p>Start second terminal, compile and start <em>canopend</em>.</p>
<pre><code>$ cd CANopenSocket/canopend
$ make
$ ./canopend --help
$ ./canopend vcan0 -i 4 -s od4_storage -a od4_storage_auto
</code></pre>
<p>You should now see CAN messages on CAN dump terminal. Wait few seconds and
press CTRL-C.</p>
<pre><code>vcan0 704 [1] 00 # Bootup message.
vcan0 084 [8] 00 50 01 2F F3 FF FF FF # Emergency message.
vcan0 704 [1] 7F # Heartbeat messages
vcan0 704 [1] 7F # one per second.
</code></pre>
<p>Heartbeat messages shows pre-operational state (0x7F). If you follow byte 4 of the
Emergency message into [CANopenNode/stack/CO_Emergency.h],
CO_EM_errorStatusBits, you will see under 0x2F "CO_EM_NON_VOLATILE_MEMORY",
which is generic, critical error with access to non volatile device memory.
This byte is CANopenNode specific. You can observe also first two bytes,
which shows standard error code (0x5000 - Device Hardware) or third byte,
which shows error register. If error register is different than zero, then
node is not able to enter operational and PDOs can not be exchanged with it.</p>
<p>You can follow the reason of the problem inside the source code. However,
there are missing non-default storage files. Add them and run it again.</p>
<pre><code>$ echo - > od4_storage
$ echo - > od4_storage_auto
$ ./canopend vcan0 -i 4 -s od4_storage -a od4_storage_auto
vcan0 704 [1] 00
vcan0 184 [2] 00 00 # PDO message
vcan0 704 [1] 05
</code></pre>
<p>Now there is operational state (0x05) and there shows one PDO on CAN
address 0x184. To learn more about PDOs, how to configure communication
and mapping parameters and how to use them see other sources of CANopen
documentation.</p>
<p>Start also second instance of <em>canopend</em> (master on nodeID=3) in the same
window (<em>canopend terminal</em>). Use default od_storage files and default
socket for command interface.</p>
<pre><code>$ # press CTRL-Z
$ bg
$ ./canopend vcan0 -i 3 -c ""
</code></pre>
<h3>
<a id="third-terminal-canopencomm" class="anchor" href="#third-terminal-canopencomm" aria-hidden="true"><span class="octicon octicon-link"></span></a>Third terminal: canopencomm</h3>
<p>Start third terminal, compile and start canopencomm.</p>
<pre><code>$ cd CANopenSocket/canopencomm
$ make
$ ./canopencomm --help
</code></pre>
<h4>
<a id="sdo-master" class="anchor" href="#sdo-master" aria-hidden="true"><span class="octicon octicon-link"></span></a>SDO master</h4>
<p>Play with it and also observe CAN dump teminal. First Hertbeat at
index 0x1017, subindex 0, 16-bit integer, on nodeID 4.</p>
<pre><code>$ ./canopencomm [1] 4 read 0x1017 0 i16
$ ./canopencomm [1] 4 write 0x1017 0 i16 5000
</code></pre>
<p>In CAN dump you can see some SDO communication. You will notice, that
Heartbeats from node 4 are coming in 5 second interval now. You can do
the same also for node 3. Now store Object dictionary, so it will preserve
variables on next start of the program.</p>
<pre><code>$ ./canopencomm 4 w 0x1010 1 u32 0x65766173
</code></pre>
<p>You can read more about Object dictionary variables for this
CANopenNode in [canopend/CANopenSocket.html].</p>
<h4>
<a id="nmt-master" class="anchor" href="#nmt-master" aria-hidden="true"><span class="octicon octicon-link"></span></a>NMT master</h4>
<p>If node is operational (started), it can exchange all objects, including
PDO, SDO, etc. In pre-operational, PDOs are disabled, SDOs works. In stopped
only NMT messages are accepted.</p>
<pre><code>$ ./canopencomm 4 preop
$ ./canopencomm 4 start
$ ./canopencomm 4 stop
$ ./canopencomm 4 r 0x1017 0 i16 # time out
$ ./canopencomm 4 reset communication
$ ./canopencomm 4 reset node
$ ./canopencomm 3 reset node
</code></pre>
<p>In <em>canopend terminal</em> you see, that both devices finished. Further commands
are not possible. If you set so, last command can also reset computer.</p>
<h3>
<a id="next-steps" class="anchor" href="#next-steps" aria-hidden="true"><span class="octicon octicon-link"></span></a>Next steps</h3>
<p>Now you can learn more skills on CANopen from some other sources:
books, data sheet of some CANopen device, standard CiA 301(it's free), etc.
Then you can enter the big world of <a href="http://can-newsletter.org/hardware">CANopen devices</a>.</p>
<p>With <a href="https://github.com/CANopenNode/CANopenNode">CANopenNode</a> you can also design your
own device. There are many very useful and high quality specifications for different
<a href="http://www.can-cia.org/standardization/specifications/">device profiles</a>,
some of them are public and free to download.</p>
<p>Here we played with virtual CAN interface and result shows as pixels on
screen. If you connect real CAN interface to your computer, things may
become dangerous. Keep control on your machines!</p>
</section>
<aside id="sidebar">
<a href="https://github.com/CANopenNode/CANopenSocket/zipball/master" class="button">
<small>Download</small>
.zip file
</a>
<a href="https://github.com/CANopenNode/CANopenSocket/tarball/master" class="button">
<small>Download</small>
.tar.gz file
</a>
<p class="repo-owner"><a href="https://github.com/CANopenNode/CANopenSocket"></a> is maintained by <a href="https://github.com/CANopenNode">CANopenNode</a>.</p>
<p>This page was generated by <a href="https://pages.github.com">GitHub Pages</a> using the Architect theme by <a href="https://twitter.com/jasonlong">Jason Long</a>.</p>
</aside>
</div>
</div>
</body>
</html>