rscada / libcanopen Goto Github PK
View Code? Open in Web Editor NEWOpen-source library for CANopen. This library is designed to be used together with the SocketCAN Linux framework for CAN.
License: BSD 3-Clause "New" or "Revised" License
Open-source library for CANopen. This library is designed to be used together with the SocketCAN Linux framework for CAN.
License: BSD 3-Clause "New" or "Revised" License
When using rs-canopen-dump
I frequently encountered these errors and the tool would exit:
read: can raw socket read: Resource temporarily unavailable
This is because a non-blocking socket is opened when using can_socket_open()
:
libcanopen/bin/rs-canopen-dump.c
Lines 49 to 50 in 6e4758b
An alternate approach is to use can_socket_open_timeout()
with a timeout of 0 instead:
diff --git a/bin/rs-canopen-dump.c b/bin/rs-canopen-dump.c
index 7b68661..7439799 100644
--- a/bin/rs-canopen-dump.c
+++ b/bin/rs-canopen-dump.c
@@ -47,7 +47,7 @@ main(int argc, char **argv)
}
/* Create the socket */
- if ((sock = can_socket_open(argv[1])) < 0)
+ if ((sock = can_socket_open_timeout(argv[1], 0)) < 0)
{
fprintf(stderr, "Error: Failed to create socket.\n");
return -1;
This is consistent with how rs-canopen-monitor
operates:
libcanopen/bin/rs-canopen-monitor.c
Lines 174 to 190 in 6e4758b
Thanks for your work on libcanopen
.
The "SEG" argument here:
libcanopen/bin/rs-canopen-sdo-upload.c
Line 76 in 6e4758b
Is not documented as available here:
libcanopen/bin/rs-canopen-sdo-upload.c
Line 52 in 6e4758b
The existence of the equivalent argument is (somewhat) documented here for the download tool:
libcanopen/bin/rs-canopen-sdo-download.c
Line 51 in 6e4758b
Without the SEG
argument documented it's not clear that e.g. visible strings longer than an expedited transfer can handle are still able to be viewed, e.g.:
$ rs-canopen-sdo-upload can0 30 0x1008 0
0000000b
$ rs-canopen-sdo-upload can0 30 0x1008 0 SEG
43414e6f70656e4e6f6465 // 'C', 'A', 'N', 'o', 'p', 'e', 'n', 'N', 'o', 'd', 'e'
after ./configure i have given make. it is produced below error
siva@siva-Vostro-3268:~/Downloads/libcanopen-master$ make
make all-recursive
make[1]: Entering directory '/home/siva/Downloads/libcanopen-master'
Making all in canopen
make[2]: Entering directory '/home/siva/Downloads/libcanopen-master/canopen'
source='canopen.c' object='canopen.lo' libtool=yes
DEPDIR=.deps depmode=none /bin/bash ../depcomp
/bin/bash ../libtool --tag=CC --mode=compile gcc -DHAVE_CONFIG_H -I. -I.. -I.. -I.. -g -O2 -c -o canopen.lo canopen.c
/bin/bash: ../depcomp: No such file or directory
Makefile:325: recipe for target 'canopen.lo' failed
make[2]: *** [canopen.lo] Error 127
make[2]: Leaving directory '/home/siva/Downloads/libcanopen-master/canopen'
Makefile:359: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/home/siva/Downloads/libcanopen-master'
Makefile:270: recipe for target 'all' failed
make: *** [all] Error 2
It wasn't at all obvious to me how the size of data is calculated from supplied arguments and it turns out it's IMO non-obvious/non-intuitive. In some scenarios it also appears to work but causes CANopen errors which are not easily diagnose-able.
Specifically, the data length is calculated based on the length of the supplied string argument:
libcanopen/bin/rs-canopen-pdo-download.c
Lines 74 to 75 in 6e4758b
libcanopen/bin/rs-canopen-sdo-download.c
Lines 74 to 78 in 6e4758b
That is, it expects the data to be expressed as two ASCII characters per byte being the hexadecimal value of the byte without any 0x
prefix. e.g.: 00
or 03e8
The approach currently used leads to issues in a number of situations, including when the value is 0
or is prefixed with 0x
.
This is significant because there are a number of situations where a data value of 0 is required (e.g. TPDO/RPDO remapping).
If one naively uses 0
as the argument value it results in CANopen errors such as 0x06070010
"Data type does not match". (Or, rather it should result in this error number but the value is currently incorrect, see #7.)
Ideally, a more robust size calculation would be implemented but in the interim hopefully documenting this will clarify the situation.
The correct format to use is two ASCII characters per byte being the hexadecimal value of the byte without any 0x
prefix.
Here is a working example (remapping a TPDO for Node ID 0x30 a.k.a 48 & modifying the event timer) to clarify how the data should be specified:
rs-canopen-sdo-download can0 30 0x1800 1 800001b0
rs-canopen-sdo-download can0 30 0x1A00 0 00
rs-canopen-sdo-download can0 30 0x1A00 1 64010110
rs-canopen-sdo-download can0 30 0x1A00 0 02
rs-canopen-sdo-download can0 30 0x1800 1 000001b0
rs-canopen-sdo-download can0 30 0x1800 5 03e8
There are a number of issues related to the parsing of numeric arguments which would benefit from fixing and/or documenting:
The rs-canopen-ds401
tool has useful documentation here and it would be helpful to replicate for the other tools:
libcanopen/bin/rs-canopen-ds401.c
Lines 39 to 45 in 6e4758b
Except that it gives the NODE
ID range as 0 .. 127
(implied to be a decimal/base 10 number) when the argument is actually parsed as hexadecimal:
libcanopen/bin/rs-canopen-ds401.c
Lines 81 to 82 in 6e4758b
The rs-canopen-nmt
tool uses atoi()
to parse the Node ID argument as a decimal/base 10 number:
libcanopen/bin/rs-canopen-nmt.c
Line 116 in 6e4758b
But all the other tools use strol()
to parse the Node ID (and other numeric arguments) as a hexadecimal/base 16 number:
libcanopen/bin/rs-canopen-node-info.c
Line 77 in 6e4758b
libcanopen/bin/rs-canopen-pdo-download.c
Lines 71 to 75 in 6e4758b
libcanopen/bin/rs-canopen-pdo-upload.c
Lines 69 to 71 in 6e4758b
libcanopen/bin/rs-canopen-sdo-download.c
Lines 71 to 74 in 6e4758b
libcanopen/bin/rs-canopen-sdo-upload.c
Lines 72 to 74 in 6e4758b
With the exception of rs-canopen-ds401
all the other tools don't document the format/range of their numeric arguments in their usage message. It would be helpful to document this.
Related:
SEG
mode argument is available for SDO upload tool. #6"In part I've created this issue to document these details for people until any changes are added to the code base.
While a function named canopen_sdo_upload_block()
exists, it has no implementation:
libcanopen/canopen/canopen-com.c
Lines 470 to 475 in 6e4758b
A Python wrapper function does exist but uses the unimplemented C function:
libcanopen/python/pycanopen/CANopen.py
Lines 222 to 232 in 6e4758b
The Python wrapper function used to mention that the function was unimplemented but the note was removed here.
These SDO abort code values are incorrect as they have the prefix 0x0606 instead of 0x0607 (e.g. see):
Lines 49 to 51 in 6e4758b
Presumably this is a copy/paste error.
Quick patch:
diff --git a/canopen/canopen.c b/canopen/canopen.c
index b02fdda..b2d2b7a 100644
--- a/canopen/canopen.c
+++ b/canopen/canopen.c
@@ -46,9 +46,9 @@ static SDO_abort_code_t SDO_abort_codes[] = {
{ 0x06040043, "General parameter incompatibility reason"},
{ 0x06040047, "General internal incompatibility in the device"},
{ 0x06060000, "Object access failed due to a hardware error"},
- { 0x06060010, "Data type does not match, lengh of service parameter does not match"},
- { 0x06060012, "Data type does not match, lengh of service parameter is too high"},
- { 0x06060013, "Data type does not match, lengh of service parameter is too low"},
+ { 0x06070010, "Data type does not match, lengh of service parameter does not match"},
+ { 0x06070012, "Data type does not match, lengh of service parameter is too high"},
+ { 0x06070013, "Data type does not match, lengh of service parameter is too low"},
{ 0x06090011, "Sub-index does not exist"},
{ 0x06090030, "Value range of parameter exceeded (only for write access)"},
{ 0x06090031, "Value of parameter written too high"},
Note: "length" is also misspelled.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.