-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmd_tutorial_2SDO.html
269 lines (263 loc) · 16 KB
/
md_tutorial_2SDO.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
257
258
259
260
261
262
263
264
265
266
267
268
269
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.11.0"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>CANopenDemo: CANopen SDO Example</title>
<link rel="icon" href="CANopenNode.png" type="image/x-icon" />
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<script type="text/javascript" src="clipboard.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="cookie.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr id="projectrow">
<td id="projectlogo"><img alt="Logo" src="CANopenNode.png"/></td>
<td id="projectalign">
<div id="projectname">CANopenDemo
</div>
<div id="projectbrief">CANopenNode demo, tutorial and testing</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.11.0 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search/",'.html');
/* @license-end */
</script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
$(function() { codefold.init(0); });
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
$(function() {
initMenu('',true,false,'search.php','Search',false);
$(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
$(function(){ initResizable(false); });
/* @license-end */
</script>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<div id="MSearchResults">
<div class="SRPage">
<div id="SRIndex">
<div id="SRResults"></div>
<div class="SRStatus" id="Loading">Loading...</div>
<div class="SRStatus" id="Searching">Searching...</div>
<div class="SRStatus" id="NoMatches">No Matches</div>
</div>
</div>
</div>
</div>
</div><!-- top -->
<div id="doc-content">
<div><div class="header">
<div class="headertitle"><div class="title">CANopen SDO Example</div></div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>This chapter describes some more advanced SDO access to some parameters of the <a class="el" href="md_demo_2README.html">demoDevice</a>. Example runs with CANopen devices as specified in <a class="elRef" href="CANopenNode/index.html#md_README">tutorial/README.md</a>.</p>
<p>We will communicate with demoDevice, so set the default Node-ID to 4: </p><pre class="fragment"> cocomm "set node 4"
</pre><h1><a class="anchor" id="autotoc_md109"></a>
Demo record</h1>
<p>Read 64-bit integer: </p><pre class="fragment">cocomm "r 0x2120 1 i64"
[1] -1234567890123456789
</pre><p> Read 64-bit unsigned integer and display result in different data types: </p><pre class="fragment">cocomm "r 0x2120 2 x64" "r 0x2120 2 u64" "r 0x2120 2"
[1] 0x1234567890ABCDEF
[2] 1311768467294899695
[3] EF CD AB 90 78 56 34 12
</pre><p> Read float values: </p><pre class="fragment">cocomm "r 0x2120 3 r32" "r 0x2120 4 r64"
[1] 12.345
[2] 456.789
</pre><p> Read average of those values (custom read function calculates the average): </p><pre class="fragment">cocomm "r 0x2120 5 r64"
[1] 1.93001e+16
</pre><p> Change one of the input values and re-read the average: </p><pre class="fragment">cocomm "w 0x2120 3 r32 -7.720058e+16" "r 0x2120 5 r64"
[1] OK
[2] 7.8681e+07
</pre><h1><a class="anchor" id="autotoc_md110"></a>
Demo strings</h1>
<p>Read three strings: </p><pre class="fragment">cocomm "r 0x2121 1 vs" "r 0x2121 2 vs" "r 0x2121 3 hex"
[1] "str"
[2] "Example string with 1000 bytes capacity. It may contain UTF-8 characters, like '€', tabs ' ', newlines, etc."
[3] C8 3D BB 00 00 00 00 00 00 00
</pre><p> Write to string with capacity 3 bytes in different ways, also read the values: </p><pre class="fragment">cocomm "w 0x2121 1 vs 12" "r 0x2121 1 vs" \
"w 0x2121 1 vs 1234" "r 0x2121 1 vs" \
"w 0x2121 1 vs \"1 2\"" "r 0x2121 1 vs"
[1] OK
[2] "12"
[3] ERROR:0x06070012 #Data type does not match, length of service parameter too high.
[4] "12"
[5] OK
[6] "1 2"
</pre><p> Write to string with capacity 1000 bytes: </p><pre class="fragment">cocomm "w 0x2121 2 vs \"Writing newLines is not possible as visible string, but exotic \"\"ß\"\" characters works.\""
[1] OK
cocomm "r 0x2121 2 vs"
[1] "Writing newLines is not possible as visible string, but exotic ""ß"" characters works."
</pre><p> Reading the string as "octet string" returns value in base64 format: </p><pre class="fragment">cocomm "r 0x2121 2 os"
[1] V3JpdGluZyBuZXdMaW5lcyBpcyBub3QgcG9zc2libGUgYXMgdmlzaWJsZSBzdHJpbmcsIGJ1dCBleG90aWMgIsOfIiBjaGFyYWN0ZXJzIHdvcmtzLg==
</pre><p> Decode the base64 through a pipe: </p><pre class="fragment">cocomm "r 0x2121 2 os" | base64 -d
[1]
Writing newLines is not possible as visible string, but exotic "ß" characters works.
cocomm "r 0x2121 2 os" | base64 -d | hexdump -C
[1]...
</pre><p> Encode something to base64 and sent it to cocomm via pipe: </p><pre class="fragment">echo -ne "We can encode anything to base64\n\nand transfer data as octet string or domain." | base64 -w0 | cocomm -i "w 0x2121 2 os"
[1] OK
</pre><p> This still works, but would be safer via base64: </p><pre class="fragment">cocomm "r 0x2121 2 vs"
[1] "We can encode anything to base64
and transfer data as octet string or domain."
</pre><p> Read octet string and display result in different data types: </p><pre class="fragment">cocomm "r 0x2121 3 hex" "r 0x2121 3 os" "r 0x2121 3 vs" "r 0x2121 3 d" "r 0x2121 3"
[1] C8 3D BB 00 00 00 00 00 00 00
[2] yD27AAAAAAAAAA==
[3] "�=�"
[4] yD27AAAAAAAAAA==
[5] C8 3D BB 00 00 00 00 00 00 00
</pre><p> Octet strings have fixed length, in contrast to strings, which accept smaller data size than its buffer size: </p><pre class="fragment">cocomm "w 0x2121 3 hex 01 02 03"
[1] ERROR:0x06070013 #Data type does not match, length of service parameter too short.
</pre><p> Our parameter is 10 bytes long: </p><pre class="fragment">cocomm "w 0x2121 3 hex 01 2 30 456789 0A b0 0 ff"
[1] OK
</pre><h1><a class="anchor" id="autotoc_md111"></a>
Demo domain</h1>
<p>Domain enables transfer an arbitrary large block of data in one SDO communication cycle. Application must provide own OD read/write access functions to use domain data type. In our example basic device just transfers incremental sequence of bytes. See <a class="el" href="md_demo_2README.html">demoDevice</a> for details.</p>
<p>SDO block transfer is used for highest efficiency over CAN. If internal virtual CAN network is used, communication is very fast. On real CAN networks data transfer rates are significantly lower. However, SDO communication does not disturb higher priority real time data transfer, which is likely present on CAN bus. SDO block transfer is also resistant to disturbances to some degree. If necessary, it re-transmits corrupted data automatically.</p>
<p>First enable block transfer: </p><pre class="fragment">cocomm "set sdo_block 1"
[1] OK
</pre><p> Read data (by default 1024 bytes) from "Demo domain" parameter: </p><pre class="fragment">cocomm "r 0x2122 0 d" | base64 -d | pv > file_read
[1]
...success
1000 B 0:00:00 [ 986KiB/s] [ <=> ]
ls -l file_read
hexdump -C file_read
</pre><p> <code>pv</code> is nice Linux command, which displays progress. Pure data are stored into to file_read. Other messages from cocomm are printed colored to stderr. If necessary, transfer can be interrupted by <code>Ctrl+C</code>. SDO communication will be closed correctly by abort message.</p>
<p>Now create ten times larger file for write and upload it to the demoDevice: </p><pre class="fragment">for n in {1..10}; do cat file_read >> file_write; done
pv file_write | base64 -w0 | cocomm -i "w 0x2122 0 d"
</pre><p> Domain example in demoDevice works so, that size of data read from device equals to the size of the data written the last time, with initial data size 1024 bytes. Additionally, values of data bytes must be correct sequence of numbers 0, 1, ..., 255, 0, 1, etc. Otherwise error <code>0x06090030 #Invalid value for parameter</code> will be responded.</p>
<p>Try also with segmented transfer: </p><pre class="fragment">cocomm "set sdo_block 0"
pv file_write | base64 -w0 | cocomm -i "w 0x2122 0 d"
</pre><p> Examine candump. Experiment further with larger data sizes or with different devices on real CAN interfaces with different CAN bit-rates, etc.</p>
<p>Here is experimental candump output with two independent pairs of <code>canopend-demoDevice</code> exchanging random binary data over one virtual CAN interface (two SDO block transfers interlaced): </p><pre class="fragment">(000.000003) vcan0 604 [8] 6F C3 A9 6E AF 5C 81 32 'o..n.\.2'
(000.000010) vcan0 604 [8] 70 B7 32 8A B2 B0 62 27 'p.2...b''
(000.000006) vcan0 604 [8] 71 4F 5F 0B F0 40 0B 53 'qO_..@.S'
(000.000003) vcan0 604 [8] 72 CE B9 49 D2 80 BD 55 'r..I...U'
(000.000010) vcan0 603 [8] A2 7F 7F 00 00 00 00 00 '........' < response
(000.000002) vcan0 604 [8] 73 94 A2 9E E2 23 8C 5A 's....#.Z'
(000.000005) vcan0 604 [8] 74 13 90 A2 59 C3 9B 1D 't...Y...'
(000.000003) vcan0 604 [8] 75 5A F4 85 3A 3E B9 10 'uZ..:>..'
(000.000011) vcan0 604 [8] 76 30 81 CC 7D 2E 7E 0F 'v0..}.~.'
(000.000000) vcan0 583 [8] 01 FC 80 1C D4 8F 67 A2 '......g.'
(000.000006) vcan0 604 [8] 77 9B FA 36 21 0F 09 2E 'w..6!...'
(000.000003) vcan0 604 [8] 78 C2 6F 97 DC 1D 97 9E 'x.o.....'
(000.000001) vcan0 583 [8] 02 E0 B9 97 47 8D 37 E6 '....G.7.'
(000.000008) vcan0 583 [8] 03 07 B6 88 68 0B 6A 8C '....h.j.'
(000.000002) vcan0 604 [8] 79 4E 6B 8D 2B 02 F5 9E 'yNk.+...'
(000.000005) vcan0 583 [8] 04 AD AC A3 B5 59 4C 30 '.....YL0'
(000.000001) vcan0 604 [8] 7A 23 97 5B D6 2A 02 F4 'z#.[.*..'
(000.000007) vcan0 583 [8] 05 67 6F 4C 1E AF 18 F3 '.goL....'
(000.000007) vcan0 604 [8] 7C 6E 6A 12 FE 5E 0B 5B '|nj..^.['
(000.000001) vcan0 583 [8] 06 E0 43 D4 2E D2 98 BA '..C.....'
(000.000005) vcan0 604 [8] 7D 4B BF 69 25 43 98 FF '}K.i%C..'
(000.000010) vcan0 583 [8] 08 52 16 57 0D 11 72 AE '.R.W..r.'
(000.000001) vcan0 604 [8] 7F 63 0C B1 2B 19 72 89 '.c..+.r.'
(000.000007) vcan0 583 [8] 09 67 3D EF B9 C1 32 D3 '.g=...2.'
(000.000012) vcan0 583 [8] 0A 3D 22 7E 79 5B D5 D4 '.="~y[..'
(000.000010) vcan0 584 [8] A2 7F 7F 00 00 00 00 00 '........' < response
(000.000001) vcan0 583 [8] 0B EC 91 5C FF 04 0A D7 '...\....'
(000.000011) vcan0 583 [8] 0C 25 86 30 DC 44 6B 59 '.%.0.DkY'
(000.000006) vcan0 583 [8] 0D 56 8F B0 23 81 41 FF '.V..#.A.'
(000.000000) vcan0 604 [8] 01 EF 91 CC EE E8 0D 9C '........'
(000.000006) vcan0 604 [8] 02 EA EB 00 A8 34 71 3F '.....4q?'
(000.000002) vcan0 583 [8] 0E 03 79 87 32 C6 96 15 '..y.2...'
(000.000006) vcan0 604 [8] 03 C2 A9 61 8E 25 3D 0A '...a.%=.'
...
(000.000003) vcan0 604 [8] 79 16 F1 A6 12 9D 3D B2 'y.....=.'
(000.000005) vcan0 604 [8] 7A E2 75 5A 16 18 66 37 'z.uZ..f7'
(000.000003) vcan0 583 [8] 6B 72 30 0A 0F C2 2C F9 'kr0...,.'
(000.000000) vcan0 604 [8] 7B 82 AE B2 D8 F0 71 32 '{.....q2'
(000.000010) vcan0 604 [8] 7C 2A 04 DD BE 30 A4 6E '|*...0.n'
(000.000001) vcan0 583 [8] 6C EA 98 F4 F2 DA C6 93 'l.......'
(000.000005) vcan0 604 [8] 7D 68 15 72 4D D0 B5 48 '}h.rM..H'
(000.000005) vcan0 583 [8] 6D 7B 24 4D 6E 6A C0 71 'm{$Mnj.q'
(000.000008) vcan0 604 [8] 7F E3 B8 4A CA BE 20 F1 '...J.. .'
(000.000003) vcan0 583 [8] 6E 11 7B 1F DA 9D 2B B3 'n.{...+.'
(000.000010) vcan0 583 [8] 6F 0A 1F 8B C4 56 F9 37 'o....V.7'
(000.000012) vcan0 583 [8] 70 67 91 36 4F 59 04 C9 'pg.6OY..'
(000.000012) vcan0 583 [8] 71 D4 B8 AC D1 06 7F 63 'q......c'
(000.000001) vcan0 584 [8] A2 7F 7F 00 00 00 00 00 '........' < response
(000.000008) vcan0 583 [8] 72 F3 5A E9 06 B2 A7 42 'r.Z....B'
(000.000009) vcan0 583 [8] 73 3D 99 69 35 9D B9 43 's=.i5..C'
(000.000000) vcan0 604 [8] 01 3B CB D9 00 E5 6A B7 '.;....j.'
(000.000006) vcan0 604 [8] 02 A6 0F 34 3D 07 C1 6A '...4=..j'
(000.000002) vcan0 583 [8] 74 72 CE 65 1B 82 0F FC 'tr.e....'
(000.000001) vcan0 604 [8] 03 0D 35 70 C2 34 C4 7D '..5p.4.}'
(000.000007) vcan0 583 [8] 75 9C 7A 1D 19 FB A0 92 'u.z.....'
(000.000007) vcan0 583 [8] 76 3D 9E B8 2F FF 9A 1B 'v=../...'
(000.000008) vcan0 583 [8] 77 ED 4E 6D D5 BA E2 D6 'w.Nm....'
(000.000008) vcan0 583 [8] 78 BA E2 83 1E 03 03 9B 'x.......'
(000.000005) vcan0 604 [8] 04 DD 6B BB FA 9C 67 BF '..k...g.'
(000.000002) vcan0 583 [8] 79 B7 2E A5 37 28 1E F6 'y...7(..'
(000.000004) vcan0 604 [8] 05 C6 A3 C7 EE 6D 24 C0 '.....m$.'
(000.000004) vcan0 604 [8] 06 5F 4E 41 25 BB D9 44 '._NA%..D'
(000.000000) vcan0 583 [8] 7A DB 34 D2 46 33 33 AE 'z.4.F33.'
(000.000008) vcan0 583 [8] 7B 30 76 56 31 1A A6 5C '{0vV1..\'
(000.000007) vcan0 583 [8] 7C 20 42 44 A5 60 AC 77 '| BD.`.w'
(000.000004) vcan0 604 [8] 07 42 7F 87 4B A5 ED 0E '.B..K...'
(000.000004) vcan0 583 [8] 7D 5D 36 93 F5 27 08 CF '}]6..'..'
(000.000002) vcan0 604 [8] 08 C1 17 36 99 9E 5F 17 '...6.._.'
(000.000003) vcan0 604 [8] 09 C0 3A 4F AF 7F 92 71 '..:O...q'
(000.000006) vcan0 583 [8] 7E 77 05 8E 00 43 29 D3 '~w...C).'
(000.000005) vcan0 604 [8] 0A CF 24 64 25 4D 81 30 '..$d%M.0'
(000.000004) vcan0 583 [8] 7F 98 C3 03 A3 2E AE E7 '........'
(000.000002) vcan0 604 [8] 0B 60 F0 5B 29 3F 69 4B '.`.[)?iK'
(000.000007) vcan0 604 [8] 0C E1 02 DA CF 08 34 0E '......4.'
(000.000007) vcan0 604 [8] 0D 7F 13 89 DE AB AB 16 '........'
(000.000006) vcan0 604 [8] 0E 98 AF 47 B3 30 56 DF '...G.0V.'
(000.000003) vcan0 604 [8] 0F 83 FB 95 9F EB E9 12 '........'
(000.000010) vcan0 604 [8] 10 F8 09 E9 39 10 CE 0F '....9...'
(000.000007) vcan0 604 [8] 11 4C 72 0B DB 34 92 14 '.Lr..4..'
(000.000003) vcan0 604 [8] 12 9D 83 1C 07 66 DC 7E '.....f.~'
(000.000000) vcan0 603 [8] A2 7F 7F 00 00 00 00 00 '........' < response
(000.000008) vcan0 604 [8] 13 DB E4 73 B0 6F 23 CB '...s.o#.'
(000.000006) vcan0 604 [8] 14 CE 1C 70 EC C3 57 99 '...p..W.'
(000.000006) vcan0 604 [8] 15 7C 33 D5 C7 FC 80 9B '.|3.....'
(000.000000) vcan0 583 [8] 01 2D 89 31 D6 1F 36 88 '.-.1..6.'
(000.000010) vcan0 583 [8] 02 B6 56 16 06 64 21 69 '..V..d!i'
</pre> </div></div><!-- contents -->
</div><!-- PageDoc -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.11.0
</small></address>
</div><!-- doc-content -->
</body>
</html>