Can Open Interface A Pi
Can Open Interface A Pi
Can Open Interface A Pi
se
www.datalink.se
1
Datalink Engineering | www.datalink.se
Contents
1 Product introduction ....................................................................................................................... 4
2 Application news ............................................................................................................................. 6
2.1 2013-01-27: Stuttgart Universität ........................................................................................... 6
2.2 2013-10-14: GPL license is discontiued ................................................................................... 6
3 Licensing conditions ........................................................................................................................ 7
3.1 Evaluation License (EL) ............................................................................................................ 7
3.2 Registered License (RL) ............................................................................................................ 7
3.3 Source Code License (SCL) ....................................................................................................... 7
3.4 Developer license (DEVL)......................................................................................................... 7
4 Supported hardware ....................................................................................................................... 9
4.1 Available CAN interface plug-ins. ............................................................................................ 9
4.1.1 Zanthic Technologies CAN4USB FX ................................................................................ 10
4.1.2 Lawicel CANUSB / CAN232 ............................................................................................ 10
4.1.3 KVASER CANLIB (USB, PCI, PC104, PC104+, PCMICA,WLAN) ........................................ 11
4.1.4 Movimento Castor (USB) ............................................................................................... 11
4.1.5 EMS Dr. Thomas Wünsche (USB, Ethernet, PCI, PC104) ............................................... 12
4.1.6 PEAK System (PCAN-Light API) ...................................................................................... 12
4.1.7 MHS Elektronik GmbH (Tiny-CAN API) .......................................................................... 13
4.1.8 Create your own plug-in? .............................................................................................. 14
5 Software layout structure for C++ applications ............................................................................ 15
6 Software layout structure for C#/.NET applications ..................................................................... 16
7 Getting started. ............................................................................................................................. 17
7.1 Reference .NET DLL (canopenlib_NET.dll) in your Visual Studio project .............................. 17
7.2 No need to include any namespace. ..................................................................................... 17
7.3 Communication classes overview - .NET. .............................................................................. 17
7.3.1 ClientSDO_NET .............................................................................................................. 18
7.3.2 NMT_Master_NET ......................................................................................................... 20
7.3.3 CanMonitor_NET ........................................................................................................... 20
7.3.4 EmcyServer_NET............................................................................................................ 22
7.3.5 EmcyClient_NET............................................................................................................. 23
7.3.6 ReceivePDO_NET ........................................................................................................... 24
7.3.7 TransmitPDO_NET ......................................................................................................... 25
2
Datalink Engineering | www.datalink.se
CANopen®
Is a registered Community Trademarks of CAN in Automation.
http://www.can-cia.org
We make no difference between our customers when it comes to support and service but some
are more familiar than others - do you know any of them?
3
Datalink Engineering | www.datalink.se
1 Product introduction
The purpose of this library is that it should be easy to create 3rd party CANopen® compliant
applications in a high level language such as C# or C++. The library is well suited for helping develop
diagnostic or tools for maintenance or service or developers. The driver supports;
SDO expedited transfer (read and write 1-4 bytes in object dictionary of your CANopen
node(s)).
SDO segmented transfer (read and write typically strings in object dictionary of your
CANopen node(s)).
SDO block transfers (write only, use this for firmware upgrade).
NMT Slave
Transmit PDO
Receive PDO
Emergency producer
Emergency consumer
CAN raw mode (send and receive raw CAN frames). This can "simulate" PDOs.
4
Datalink Engineering | www.datalink.se
Product Evaluation
Datalink Engineering CANopen API source code is available for evaluation using Subversion.
2) If you know how Subversion works check out the source code on the following URL:
https://subversion.assembla.com/svn/datalinkengineeringcanopen/trunk
3) Once you have the source code you can follow the instructions in this YouTube-video how to
get started working with the library.
https://www.youtube.com/watch?v=KxJBv0Up338
5
Datalink Engineering | www.datalink.se
2 Application news
6
Datalink Engineering | www.datalink.se
3 Licensing conditions
Datalink Engineering CANopen API (C++/.NET) is made available under the terms of the following
three licenses.
Datalink Engineering grants to Licensee and Licensee accepts from Datalink Engineering a non-
exclusive, non-transferable, royalty-free license solely for evaluation purposes for application
developing using .NET. Any use of library for a commercial purpose or to produce meshes having
commercial value, including any project or mesh of a type performed in the normal course of a
business or practice, is prohibited. This license will throw a "pop-up" every 20 minutes.
This license grants the Licensee to use library for a commercial purpose. In exchange for payment
licensee receive a License File (LF) to be included with the developed application. This License File
(LF) will be read and validated by the library and, if valid, the limitations (window pop-up) of the
evaluation license ceases.
Source Code License includes a Registered License (RL) but also includes source code for the library.
This license grants the licensee to modify the source code except for the parts of the code that
validates the License File (LF), and if License File (LF) is missing or invalid show pop-up window.
Contribute to the project with functionality growth and you will have a Registered License (RL) at no
cost at all (or discount) if your code is accepted by Datalink Engineering.
Check out the source code here using Subversion:
URL https://subversion.assembla.com/svn/datalinkengineeringcanopen/trunk
Online video with instructions how to check out source code is available here.
7
Datalink Engineering | www.datalink.se
Kvaser 1 Registered License (RL) + 5 Kvaser Leaf Light (USB2.0 480 Mbits/s)
commercial 1349€
offer #1
Kvaser 1 Registered License (RL) + 1 Kvaser Leaf Light (USB2.0 480 Mbits/s)
commercial 375€
offer #2
These prices may change without prior notice – please ask for a quotation before ordering on
8
Datalink Engineering | www.datalink.se
4 Supported hardware
The structure of the CANopen API (C++/C#) driver is that all CAN-layer dependent calls are made via a
DLL called canopenlib_hw.dll (see chapter 4 in this document) – there are no direct dependencies
from the CANopen® network to the CAN interface API.
This means that you can choose any of the listed hardware’s below and just use the specific DLL for
your hardware. You can also develop your own plug-in DLL; source code can be downloaded, free of
charge for the listed hardware below as example how to implement your own plug-in for your
preferred hardware. It has been kept in mind that this CANopen library should be possible to port to
cheap CAN interfaces or even migrate to a embedded environment - without a fancy CAN API –
therefore this library CAN-interface class holds a lot of intelligence (CAN message dispatcher, thread
safe calls etc).
Today we can provide you with, free of charge, plug-in DLLs for the listed CAN interfaces below. You
simply select your preferred hardware in the “Debug/Release” drop down in Visual Studio.
9
Datalink Engineering | www.datalink.se
A plug-in for the Lawicel ASCII-API is available which means that it will work with both low price
CANUSB and CAN232.
CANUSB – http://www.canusb.com/documents/canusb_manual.pdf
CAN232 – http://www.can232.com/can232_v3.pdf
10
Datalink Engineering | www.datalink.se
All KVASER’s hardware ( www.kvaser.com ) is using the same interface API – this means that you can
choose any of the KVASER CAN-products as they are all supporting the CANLIB API.
Movimento Castor USB is low cost USB to CAN adapter. Contact [email protected] to reach all
preferred retailing contacts and best price.
http://www.movimentogroup.com/pdf/Movimento%20Castor%20CAN.pdf
11
Datalink Engineering | www.datalink.se
All EMS hardware ( http://www.ems-wuensche.com ) is using the same interface API – this means
that you can choose any of the EMS CAN-products to use with the EMS plug-in DLL.
Important notice: EMS windows drivers are not delivered with a free of charge API (SDK) – this means
that you will have to purchase a proper developer license for your EMS device/devices to make the
canopen_hw.dll working properly. Contact EMS for further information about developer licenses.
A plug-in for the PEAK System (www.peak-system.com) is available which means that it will work
with all PEAK System hardware that is supporting the PCAN-Light API.
12
Datalink Engineering | www.datalink.se
A plug-in for the Tiny-CAN II XL (www.mhs-elektronik.de) is available which means that it will work
with all MHS System hardware that is supporting the Tiny-CAN API.
USB DRIVER NOTICE: Install the latest driver version 2.08.08 from the FTDI Homepage to get this
adapter working stable on your OS – download: http://www.ftdichip.com/Drivers/D2XX.htm . The
FTDI driver version 2.08.02 (WHQL Certified) doesn't work correctly on Windows 7 and Windows
VISTA (Windows XP, or others?) is Datalink Engineering’s experience.
13
Datalink Engineering | www.datalink.se
14
Datalink Engineering | www.datalink.se
canopenlib.dll (C++)
canopenlib_hw.dll
( “Porting” for hardware being used, can
be developed by you for your hardware.)
CAN hardware
CAN bus
15
Datalink Engineering | www.datalink.se
canopenlib.dll (C++)
canopenlib_hw.dll (C)
( “Porting” for hardware being used, can
be developed by you for your hardware. )
CAN hardware
CAN bus
The syntax for the C# API version of this driver is very similar to the C++ and therefore left out in the
examples. The appendix of this document includes a C# example program that should hopefully be
sufficient.
16
Datalink Engineering | www.datalink.se
7 Getting started.
This tutorial explains how to get started using the library together with Visual Studio 2010.
17
Datalink Engineering | www.datalink.se
7.3.1 ClientSDO_NET
The ClientSDO-class is used for write to and read from the Object Dictionary of the nodes on the
network. The class support expedited read/write, segmented read/write and block write.
SDO_NET.CanOpenStatus stat;
uint value;
uint error;
18
Datalink Engineering | www.datalink.se
If you want to write to (or read from) the object dictionary of a node you simply use the
ClientSDO_NET class. Example below show a write attempt to object dictionary 0x1234 and subindex
0x12.
ClientSDO_NET client_SDO;
client_SDO =new ClientSDO_NET(); // Create instance.
CANOPEN_LIB_ERROR.CanOpenStatus stat;
stat = client_SDO.canHardwareConnect(0, 250000); // Connect CAN-hw ch 0, bitr 250kbps.
if (stat != CANOPEN_LIB_ERROR.CanOpenStatus.CANOPEN_OK)
{
// Something went wrong, is no CAN adapter connected?
}
uint error_code;
stat = client_SDO.objectWrite(0x1234, 0x12, 4, out error_code);
if (stat != CANOPEN_LIB_ERROR.CanOpenStatus.CANOPEN_OK)
{
if (stat == CANOPEN_LIB_ERROR.CanOpenStatus.CANOPEN_ERROR_HW_NOT_CONNECTED)
{
// Hardware error, is the adapter unplugged?
}
else
{
if (stat == CANOPEN_LIB_ERROR.CanOpenStatus.CANOPEN_TIMEOUT)
{
// Write timeout – is node 12 powered off?
}
else
{
// Remote node didn’t accept the value. Read node’s error code in variable
// variable error_code – see nodes documentation what this error code means.
}
}
}
else
{
// Success!
}
19
Datalink Engineering | www.datalink.se
7.3.2 NMT_Master_NET
The NMT_Master_NET class is used to network management. The library supports sending network
management commands (i.e. start, stop, reset, etc. node).
7.3.2.2 Example how to start transmitting node-guard messages and verify node
operational state.
class Program
{
static void Main(string[] args)
{
NMT_Master_NET nmt_Master;
nmt_Master = new NMT_Master_NET();
nmt_Master.canHardwareConnect(0, 500000);
nmt_Master.registerNodeStateCallback(
new NMTOperationalStateDelegate(node_state_callback),(Object)nmt_Master);
…
…
7.3.3 CanMonitor_NET
The CanMonitor_NET class is used to send and receive the raw CAN data ("CAN frames") on the bus.
20
Datalink Engineering | www.datalink.se
7.3.3.2 Example how to send/receive raw CAN data (CAN frames) on hardware channel
class Program
{
static void Main(string[] args)
{
CanMonitor_NET can_monitor;
can_monitor = new CanMonitor_NET();
can_monitor.registerCanReceiveCallback(
(Object)this, new CanReceiveDelegate(canReceiveCallback));
can_monitor.canHardwareConnect(0, 500000);
..
..
data[0] = 0x01;
data[1] = 0x02;
data[2] = 0x03;
data[3] = 0x04;
data[4] = 0x05;
data[5] = 0x06;
data[6] = 0x07;
data[7] = 0x018;
21
Datalink Engineering | www.datalink.se
7.3.4 EmcyServer_NET
The EmcyServer_NET class is used to listen for and emergency messages on the network.
..
.
}
static EmcyServer_NET.CanOpenStatus emcy_callback(object obj, byte nodeId, ushort emcyErrorCode, byte errorRegister,
byte[] manufacturerSpecificErrorField)
{
Console.WriteLine("EMERGENCY MESSAGE RECEIVED!");
return CANOPEN_LIB_ERROR.CanOpenStatus.CANOPEN_OK;
}
22
Datalink Engineering | www.datalink.se
7.3.5 EmcyClient_NET
The EmcyClient_NET class is used to send network messages on the bus.
manufSpecific[0] = 0x10;
manufSpecific[1] = 0x20;
manufSpecific[2] = 0x30;
manufSpecific[3] = 0x40;
manufSpecific[4] = 0x50;
ret = emcy_client.nodeSetId(3);
if (ret != CANOPEN_LIB_ERROR.CanOpenStatus.CANOPEN_OK)
return;
23
Datalink Engineering | www.datalink.se
7.3.6 ReceivePDO_NET
The ReceivePDO_NET class is used to PDO data from the network messages on the bus.
ret = receive_pdo.setCobid(0x555);
if (ret != CANOPEN_LIB_ERROR.CanOpenStatus.CANOPEN_OK)
return;
..
.
}
return CANOPEN_LIB_ERROR.CanOpenStatus.CANOPEN_OK;
}
}
24
Datalink Engineering | www.datalink.se
7.3.7 TransmitPDO_NET
The TransmitPDO_NET class is used to PDO data from the network messages on the bus.
Thread.Sleep(1000);
Thread.Sleep(5000);
Thread.Sleep(5000);
}
}
25