MOONS' CANopen Library User Manual
MOONS' CANopen Library User Manual
User Manual
Rev. 1.1
©Copyright Shanghai AMP & MOONS’ Automation Co., Ltd. All Right Reserved.
MOONS’ CANopen Library User Manual
Contents
1 GETTING STARTED ......................................................................................... 5
5 FAQ ................................................................................................................. 72
Shanghai AMP & MOONS’ Automation Equipment Co., Ltd., 2017 2 / 73
MOONS’ CANopen Library User Manual
5.1 HOW TO SOLVE "LOADERLOCK WAS DETECTED" WHEN ADAPTER IS ZLG? ......... 72
Revision History
1 Getting Started
1.1 Introduction
MOONS’ Motion Control Libraries provides powerful APIs to the users to write their Microsoft
Windows software when there are using MOONS’ field bus drives. It will help the users to develop
there motion control system rapidly and easily. MOONS’ Motion Control Libraries consist of the
following libraries:
Table 1.1 Motion Control Libraries List
Library DLL Description Communication
CANopenLib_x64.DLL
This User Manual gives basic instructions on how to use the CANopen Library to control your
MOONS’ drives via CANopen bus.
MOONS' provides VC++, VB.NET and C# sample codes to show you how to program with
MOONS’ CANopen Library. In the sample codes there is a helper file to encapsulate the
importation to the DLL. This will make it very convenient to use.
1.3 Preparations
Before you program your motion control application, you should do some configurations otherwise
it will lead the communication to muddle.
For MOONS' CANopen drives, you should configure all your drives in one CANopen fieldbus
network with same baud rate. Also the drives Node ID should be different entirely.
32-bit 64-bit
Application Application
CANopenLibHelper CANopenLibHelper
class class
CANopenLib_x86.dll CANopenLib_x64.dll
1. Open
3. Close
2.4.1 C++
// Define Adapter, 0=Kvaser, 1=PEAK, 2=ZLG
int nAdapter = 0;
BYTE nChannel = 0;
// Rel Move: Distance = 20000 steps, Velocity = 10rps, Acceleration = 100 rps/s, Deceleration =
100rps/s
2.4.2 C#
// Define Adapter, 0=Kvaser, 1=PEAK, 2=ZLG
int nAdapter = 0;
byte nChannel = 0;
// Rel Move: Distance = 20000 steps, Velocity = 10rps, Acceleration = 100 rps/s, Deceleration =
100rps/s
2.4.3 VB.NET
' Define Adapter, 0=Kvaser, 1=PEAK, 2=ZLG
Dim nAdapter As Integer = 0
' Rel Move: Distance = 20000 steps, Velocity = 10rps, Acceleration = 100 rps/s, Deceleration =
100rps/s
3 API Definition
3.1.1 Events
The DLL provides 4 type of events. OnHeartBeatReceive, OnDataSend, OnDataReceive and
OnTPDOReceived. You can handle your own process when the events are triggered.
Table 3.1 Events List
API Name Description
IsOpen Return a boolean value that indicate the port is open or closed.
ExecuteCommand Write command to the drive and read response from the drive
~500Eh
~500Eh
Stop Stop
Homing Homing
Almost all the APIs will return Boolean value. If it return “TRUE”, it means the drive executes
correctly. Otherwise it means there is at least one problem when executing. In this case, you can
call GetLastErrorInfo immediately to get the error information. This function will return a structure
named ERROR_INFO. The definition of ERROR_INFO structure is as following:
typedef struct _ERROR_INFO
int ErrorCode;
char* Command;
char* ErrorMessage;
} ERROR_INFO, *PERROR_INFO;
When you read or write a CAN command, the command is definied in a structure named
CANMESSAGE. The definition of CANMESSAGE structure is as following:
Field Description
id Cob ID
flag flag
When received PDO message, you can use GetLastTPDOMessage to read the PDO information.
The PDO information is in a structure named PDOMESSAGE. The definition of PDOMESSAGE
structure is as following:
No PDO No
0:PDO 1
1:PDO 2
2:PDO 3
3:PDO 4
You can use the SetRPDOMapping and SetTPDOMapping API to set the RPDO and TPDO
mapping. The mapping information is definied in a structure named PDOMAPPING. The definition
of PDO structure is as following:
PDOMAPPING Structure Definition:
Index OD index
SubIndex OD sub-index
4 API Reference
4.1 Events
void OnHeartBeatReceived (void* pCallBack);
This event is trigged when the DLL received heart beat message from the drive. You need call
GetLastHeartBeatMessage API to get detailed command data.
This event is trigged when the DLL send message to the drive. You need to call
GetLastSentMessage API to get detailed command data.
Arguments
This event is trigged when the DLL received message from the drive. You need to call
GetLastReceivedMessage API to get detailed command data.
Arguments
This event is trigged when the DLL TPDO message from the drive. You need to call
GetLastTPDOMessage API to get detailed command data.
0=Kvaser
1=PEAK
2=ZLG
0=1Mbps
1=800kbps
2=500kbps
3=250kbps
4=125kbps
5=50kbps
6=20kbps
7=12.5kbps
The argument nChannel appoints the type of adapter. For example, if you use the PCI CAN of
Kvaser, the nChannel is 9(HWTYPE_PCICAN = 9). The following is the type list of Kvaser, PEAK
and ZLG adapter.
1. Kvaser
/// <summary>
/// PEAKDeviceType
/// </summary>
public enum KvaserDeviceType
{
/// <summary>
/// Unknown or undefined
/// </summary>
HWTYPE_NONE = 0,
/// <summary>
/// The virtual CAN bus
/// </summary>
HWTYPE_VIRTUAL = 1,
/// <summary>
/// </summary>
HWTYPE_PCICANX_II = 52,
/// <summary>
/// Kvaser Memorator Professional family
/// </summary>
HWTYPE_MEMORATOR_II = 54,
/// <summary>
/// Kvaser Memorator Professional family
/// </summary>
HWTYPE_MEMORATOR_PRO = 54,
/// <summary>
/// Kvaser USBcan Professional
/// </summary>
HWTYPE_USBCAN_PRO = 56,
/// <summary>
/// Obsolete name, use canHWTYPE_BLACKBIRD instead
/// </summary>
HWTYPE_IRIS = 58,
/// <summary>
/// Kvaser BlackBird
/// </summary>
HWTYPE_BLACKBIRD = 58,
/// <summary>
/// Kvaser Memorator Light
/// </summary>
HWTYPE_MEMORATOR_LIGHT = 60,
/// <summary>
/// Obsolete name, use canHWTYPE_EAGLE instead
/// </summary>
HWTYPE_MINIHYDRA = 62,
/// <summary>
/// Kvaser Eagle family
/// </summary>
HWTYPE_EAGLE = 62,
/// <summary>
/// Obsolete name, use canHWTYPE_BLACKBIRD_V2 instead
/// </summary>
HWTYPE_BAGEL = 64,
/// <summary>
/// Kvaser BlackBird v2
/// </summary>
HWTYPE_BLACKBIRD_V2 = 64,
/// <summary>
/// Kvaser Mini PCI Express
/// </summary>
HWTYPE_MINIPCIE = 66,
/// <summary>
/// USBcan Pro HS/K-Line
/// </summary>
HWTYPE_USBCAN_KLINE = 68,
/// <summary>
/// Kvaser Ethercan
/// </summary>
HWTYPE_ETHERCAN = 70,
/// <summary>
/// Kvaser USBcan Light
/// </summary>
HWTYPE_USBCAN_LIGHT = 72,
/// <summary>
/// Kvaser USBcan Pro 5xHS and variants
/// </summary>
HWTYPE_USBCAN_PRO2 = 74,
/// <summary>
/// Kvaser PCIEcan 4xHS and variants
/// </summary>
HWTYPE_PCIE_V2 = 76,
/// <summary>
/// Kvaser Memorator Pro 5xHS and variants
/// </summary>
HWTYPE_MEMORATOR_PRO2 = 78,
/// <summary>
/// Kvaser Leaf Pro HS v2 and variants
/// </summary>
HWTYPE_LEAF2 = 80,
/// <summary>
/// Kvaser Memorator (2nd generation)
/// </summary>
HWTYPE_MEMORATOR_V2 = 82,
}
2. PEAK
/// <summary>
/// PEAKDeviceType
/// </summary>
public enum PEAKDeviceType
{
/// <summary>
/// Undefined/default value for a PCAN bus
/// </summary>
PCAN_NONEBUS = 0x00,
/// <summary>
/// PCAN-ISA interface, channel 1
/// </summary>
PCAN_ISABUS1 = 0x21,
/// <summary>
/// PCAN-ISA interface, channel 2
/// </summary>
PCAN_ISABUS2 = 0x22,
/// <summary>
/// PCAN-ISA interface, channel 3
/// </summary>
PCAN_ISABUS3 = 0x23,
/// <summary>
/// PCAN-ISA interface, channel 4
/// </summary>
PCAN_ISABUS4 = 0x24,
/// <summary>
/// PCAN-ISA interface, channel 5
/// </summary>
PCAN_ISABUS5 = 0x25,
/// <summary>
/// PCAN-ISA interface, channel 6
/// </summary>
PCAN_ISABUS6 = 0x26,
/// <summary>
/// PCAN-ISA interface, channel 7
/// </summary>
PCAN_ISABUS7 = 0x27,
/// <summary>
/// PCAN-ISA interface, channel 8
/// </summary>
PCAN_ISABUS8 = 0x28,
/// <summary>
/// PPCAN-Dongle/LPT interface, channel 1
/// </summary>
PCAN_DNGBUS1 = 0x31,
/// <summary>
/// PCAN-PCI interface, channel 1
/// </summary>
PCAN_PCIBUS1 = 0x41,
/// <summary>
/// PCAN-PCI interface, channel 2
/// </summary>
PCAN_PCIBUS2 = 0x42,
/// <summary>
/// PCAN-PCI interface, channel 3
/// </summary>
PCAN_PCIBUS3 = 0x43,
/// <summary>
/// PCAN-PCI interface, channel 4
/// </summary>
PCAN_PCIBUS4 = 0x44,
/// <summary>
/// PCAN-PCI interface, channel 5
/// </summary>
PCAN_PCIBUS5 = 0x45,
/// <summary>
/// PCAN-PCI interface, channel 6
/// </summary>
PCAN_PCIBUS6 = 0x46,
/// <summary>
/// PCAN-PCI interface, channel 7
/// </summary>
PCAN_PCIBUS7 = 0x47,
/// <summary>
/// PCAN-PCI interface, channel 8
/// </summary>
PCAN_PCIBUS8 = 0x48,
/// <summary>
/// PCAN-USB interface, channel 1
/// </summary>
PCAN_USBBUS1 = 0x51,
/// <summary>
/// PCAN-USB interface, channel 2
/// </summary>
PCAN_USBBUS2 = 0x52,
/// <summary>
/// PCAN-USB interface, channel 3
/// </summary>
PCAN_USBBUS3 = 0x53,
/// <summary>
/// PCAN-USB interface, channel 4
/// </summary>
PCAN_USBBUS4 = 0x54,
/// <summary>
/// PCAN-USB interface, channel 5
/// </summary>
PCAN_USBBUS5 = 0x55,
/// <summary>
/// PCAN-USB interface, channel 6
/// </summary>
PCAN_USBBUS6 = 0x56,
/// <summary>
/// PCAN-USB interface, channel 7
/// </summary>
PCAN_USBBUS7 = 0x57,
/// <summary>
/// PCAN-USB interface, channel 8
/// </summary>
PCAN_USBBUS8 = 0x58,
/// <summary>
/// PCAN-PC Card interface, channel 1
/// </summary>
PCAN_PCCBUS1 = 0x61,
/// <summary>
/// PCAN-PC Card interface, channel 2
/// </summary>
PCAN_PCCBUS2 = 0x62,
}
3. ZLG
/// <summary>
/// ZLGDeviceType
/// </summary>
public enum ZLGDeviceType
{
PCI5121 = 1,
PCI9810 = 2,
USBCAN1 = 3,
USBCAN2 = 4,
USBCAN2A = 4,
PCI9820 = 5,
CAN232 = 6,
PCI5110 = 7,
CANLITE = 8,
ISA9620 = 9,
ISA5420 = 10,
PC104CAN = 11,
CANETUDP = 12,
CANETE = 12,
DNP9810 = 13,
PCI9840 = 14,
PC104CAN2 = 15,
PCI9820I = 16,
CANETTCP = 17,
PEC9920 = 18,
PCIE_9220 = 18,
PCI5010U = 19,
USBCAN_E_U = 20,
USBCAN_2E_U = 21,
PCI5020U = 22,
EG20T_CAN = 23,
PCIE9221 = 24,
WIFICAN_TCP = 25,
WIFICAN_UDP = 26,
PCIe9120 = 27,
PCIe9110 = 28,
PCIe9140 = 29,
}
BOOL Close();
None.
BOOL IsOpen();
None.
BYTE GetExecuteTimeOut();
None.
BYTE GetExecuteRetryTimes();
None.
BOOL ResetBuffer();
None.
Description Description
0: RPDO1
1: RPDO2
2: RPDO3
3: RPDO4
Description Send a CAN message to drive and read matched CAN message from the drive.
If there is no matched message, it will keep reading until execute time is out
FALSE
Index
FALSE
bMatchFirstByte Point first byte of the CAN message or not TRUE: Match first byte of data
of data
is FALSE
nIndex OD Index
nSubIndex OD Sub-index
nIndex OD Index
nSubIndex OD Sub-index
nIndex OD Index
nSubIndex OD Sub-index
nIndex OD Index
nSubIndex OD Sub-index
nIndex OD Index
nSubIndex OD Sub-index
nIndex OD Index
nSubIndex OD Sub-index
nIndex OD Index
nSubIndex OD Sub-index
nIndex OD Index
nSubIndex OD Sub-index
nIndex OD Index
nSubIndex OD Sub-index
nIndex OD Index
nSubIndex OD Sub-index
nIndex OD Index
nSubIndex OD Sub-index
nIndex OD Index
nSubIndex OD Sub-index
0: RPDO1
1: RPDO2
2: RPDO3
3: RPDO4
0: RPDO1
1: RPDO2
2: RPDO3
3: RPDO4
The following is the sample code that how to set PDO mapping:
C++
// This is a sample to show how to set PDO Mapping
BOOL SetPDOMappingSettingsSample()
{
BOOL ret = TRUE;
byte nNodeID = 1;
byte nRPDONo; // (0~3) 1 means RPDO 2
byte nTPDONo; // (0~3) 1 means TPDO 2
int nLen = 2;
// RPDO 1
nLen = 1;
nRPDONo = 0;
PDOMAPPING RPdoMappingArr1[1];
RPdoMappingArr1[0].Index = 0x6040;
RPdoMappingArr1[0].SubIndex = 0;
RPdoMappingArr1[0].BitCounts = 0x10;
ret = m_CANopenLibHelper.SetRPDOMapping(nNodeID, nRPDONo, nLen, RPdoMappingArr1);
if (ret == FALSE)
{
printf("SetRPDOMapping failed\r\n");
return FALSE;
}
// RPDO 2
nLen = 2;
nRPDONo = 1;
PDOMAPPING RPdoMappingArr2[2];
RPdoMappingArr2[0].Index = 0x6040;
RPdoMappingArr2[0].SubIndex = 0;
RPdoMappingArr2[0].BitCounts = 0x10;
RPdoMappingArr2[1].Index = 0x607A;
RPdoMappingArr2[1].SubIndex = 0;
RPdoMappingArr2[1].BitCounts = 0x20;
ret = m_CANopenLibHelper.SetRPDOMapping(nNodeID, nRPDONo, nLen, RPdoMappingArr2);
if (ret == FALSE)
{
printf("SetRPDOMapping failed\r\n");
return FALSE;
}
// RPDO 3
nLen = 2;
nRPDONo = 2;
PDOMAPPING RPdoMappingArr3[2];
RPdoMappingArr3[0].Index = 0x6040;
RPdoMappingArr3[0].SubIndex = 0;
RPdoMappingArr3[0].BitCounts = 0x10;
Shanghai AMP & MOONS’ Automation Equipment Co., Ltd., 2017 37 / 73
MOONS’ CANopen Library User Manual
RPdoMappingArr3[1].Index = 0x60FF;
RPdoMappingArr3[1].SubIndex = 0;
RPdoMappingArr3[1].BitCounts = 0x20;
ret = m_CANopenLibHelper.SetRPDOMapping(nNodeID, nRPDONo, nLen, RPdoMappingArr3);
if (ret == FALSE)
{
printf("SetRPDOMapping failed\r\n");
return FALSE;
}
// RPDO 4
nLen = 1;
nRPDONo = 3;
PDOMAPPING RPdoMappingArr4[1];
RPdoMappingArr4[0].Index = 0x60FE;
RPdoMappingArr4[0].SubIndex = 0x01;
RPdoMappingArr4[0].BitCounts = 0x20;
ret = m_CANopenLibHelper.SetRPDOMapping(nNodeID, nRPDONo, nLen, RPdoMappingArr4);
if (ret == FALSE)
{
printf("SetRPDOMapping failed\r\n");
return FALSE;
}
// TPDO 1
nLen = 1;
nTPDONo = 0;
PDOMAPPING TPdoMappingArr1[1];
TPdoMappingArr1[0].Index = 0x6041;
TPdoMappingArr1[0].SubIndex = 0;
TPdoMappingArr1[0].BitCounts = 0x10;
ret = m_CANopenLibHelper.SetTPDOMapping(nNodeID, nTPDONo, nLen, TPdoMappingArr1);
if (ret == FALSE)
{
printf("SetTPDOMapping failed\r\n");
return FALSE;
}
// TPDO 2
nLen = 2;
nTPDONo = 1;
PDOMAPPING TPdoMappingArr2[2];
TPdoMappingArr2[0].Index = 0x6041;
TPdoMappingArr2[0].SubIndex = 0;
TPdoMappingArr2[0].BitCounts = 0x10;
Shanghai AMP & MOONS’ Automation Equipment Co., Ltd., 2017 38 / 73
MOONS’ CANopen Library User Manual
TPdoMappingArr2[1].Index = 0x700A;
TPdoMappingArr2[1].SubIndex = 0;
TPdoMappingArr2[1].BitCounts = 0x20;
ret = m_CANopenLibHelper.SetTPDOMapping(nNodeID, nTPDONo, nLen, TPdoMappingArr2);
if (ret == FALSE)
{
printf("SetTPDOMapping failed\r\n");
return FALSE;
}
// TPDO 3
nLen = 2;
nTPDONo = 2;
PDOMAPPING TPdoMappingArr3[2];
TPdoMappingArr3[0].Index = 0x6041;
TPdoMappingArr3[0].SubIndex = 0;
TPdoMappingArr3[0].BitCounts = 0x10;
TPdoMappingArr3[1].Index = 0x7009;
TPdoMappingArr3[1].SubIndex = 0;
TPdoMappingArr3[1].BitCounts = 0x10;
ret = m_CANopenLibHelper.SetTPDOMapping(nNodeID, nTPDONo, nLen, TPdoMappingArr3);
if (ret == FALSE)
{
printf("SetTPDOMapping failed\r\n");
return FALSE;
}
// TPDO 4
nLen = 1;
nTPDONo = 3;
PDOMAPPING TPdoMappingArr4[1];
TPdoMappingArr4[0].Index = 0x7003;
TPdoMappingArr4[0].SubIndex = 0;
TPdoMappingArr4[0].BitCounts = 0x10;
ret = m_CANopenLibHelper.SetTPDOMapping(nNodeID, nTPDONo, nLen, TPdoMappingArr4);
if (ret == FALSE)
{
printf("SetTPDOMapping failed\r\n");
return FALSE;
}
}
C#
/// <summary>
/// This procedure shows how to set RPDO and TPDO mapping
/// </summary>
private void SetPDOMappingSettingsSample()
{
bool ret = true;
byte nNodeID = 1;
byte nRPDONo; // (0~3) 1 means RPDO 2
byte nTPDONo; // (0~3) 1 means TPDO 2
int nLen = 2;
PDOMapping[] PdoMappingArr;
// RPDO 1
nLen = 1;
nRPDONo = 0;
PdoMappingArr = new PDOMapping[nLen];
PdoMappingArr[0].Index = 0x6040;
PdoMappingArr[0].SubIndex = 0;
PdoMappingArr[0].BitCounts = 0x10;
ret = m_CANopenLibHelper.SetRPDOMapping(nNodeID, nRPDONo, nLen, PdoMappingArr);
if (ret == false)
{
txt_CommandHistory.AppendText(string.Format("SetRPDOMapping failed\r\n"));
}
// RPDO 2
nLen = 2;
nRPDONo = 1;
PdoMappingArr = new PDOMapping[nLen];
PdoMappingArr[0].Index = 0x6040;
PdoMappingArr[0].SubIndex = 0;
PdoMappingArr[0].BitCounts = 0x10;
PdoMappingArr[1].Index = 0x607A;
PdoMappingArr[1].SubIndex = 0;
PdoMappingArr[1].BitCounts = 0x20;
ret = m_CANopenLibHelper.SetRPDOMapping(nNodeID, nRPDONo, nLen, PdoMappingArr);
if (ret == false)
{
txt_CommandHistory.AppendText(string.Format("SetRPDOMapping failed\r\n"));
}
// RPDO 3
nLen = 2;
nRPDONo = 2;
PdoMappingArr = new PDOMapping[nLen];
Shanghai AMP & MOONS’ Automation Equipment Co., Ltd., 2017 40 / 73
MOONS’ CANopen Library User Manual
PdoMappingArr[0].Index = 0x6040;
PdoMappingArr[0].SubIndex = 0;
PdoMappingArr[0].BitCounts = 0x10;
PdoMappingArr[1].Index = 0x60FF;
PdoMappingArr[1].SubIndex = 0;
PdoMappingArr[1].BitCounts = 0x20;
ret = m_CANopenLibHelper.SetRPDOMapping(nNodeID, nRPDONo, nLen, PdoMappingArr);
if (ret == false)
{
txt_CommandHistory.AppendText(string.Format("SetRPDOMapping failed\r\n"));
}
// RPDO 4
nLen = 1;
nRPDONo = 3;
PdoMappingArr = new PDOMapping[nLen];
PdoMappingArr[0].Index = 0x60FE;
PdoMappingArr[0].SubIndex = 0x01;
PdoMappingArr[0].BitCounts = 0x20;
ret = m_CANopenLibHelper.SetRPDOMapping(nNodeID, nRPDONo, nLen, PdoMappingArr);
if (ret == false)
{
txt_CommandHistory.AppendText(string.Format("SetRPDOMapping failed\r\n"));
}
// TPDO 1
nLen = 1;
nTPDONo = 0;
PdoMappingArr = new PDOMapping[nLen];
PdoMappingArr[0].Index = 0x6041;
PdoMappingArr[0].SubIndex = 0;
PdoMappingArr[0].BitCounts = 0x10;
ret = m_CANopenLibHelper.SetTPDOMapping(nNodeID, nTPDONo, nLen, PdoMappingArr);
if (ret == false)
{
txt_CommandHistory.AppendText(string.Format("SetTPDOMapping failed\r\n"));
}
// TPDO 2
nLen = 2;
nTPDONo = 1;
PdoMappingArr = new PDOMapping[nLen];
PdoMappingArr[0].Index = 0x6041;
PdoMappingArr[0].SubIndex = 0;
PdoMappingArr[0].BitCounts = 0x10;
Shanghai AMP & MOONS’ Automation Equipment Co., Ltd., 2017 41 / 73
MOONS’ CANopen Library User Manual
PdoMappingArr[1].Index = 0x700A;
PdoMappingArr[1].SubIndex = 0;
PdoMappingArr[1].BitCounts = 0x20;
ret = m_CANopenLibHelper.SetTPDOMapping(nNodeID, nTPDONo, nLen, PdoMappingArr);
if (ret == false)
{
txt_CommandHistory.AppendText(string.Format("SetTPDOMapping failed\r\n"));
}
// TPDO 3
nLen = 2;
nTPDONo = 2;
PdoMappingArr = new PDOMapping[nLen];
PdoMappingArr[0].Index = 0x6041;
PdoMappingArr[0].SubIndex = 0;
PdoMappingArr[0].BitCounts = 0x10;
PdoMappingArr[1].Index = 0x7009;
PdoMappingArr[1].SubIndex = 0;
PdoMappingArr[1].BitCounts = 0x10;
ret = m_CANopenLibHelper.SetTPDOMapping(nNodeID, nTPDONo, nLen, PdoMappingArr);
if (ret == false)
{
txt_CommandHistory.AppendText(string.Format("SetTPDOMapping failed\r\n"));
}
// TPDO 4
nLen = 1;
nTPDONo = 3;
PdoMappingArr = new PDOMapping[nLen];
PdoMappingArr[0].Index = 0x7003;
PdoMappingArr[0].SubIndex = 0;
PdoMappingArr[0].BitCounts = 0x10;
ret = m_CANopenLibHelper.SetTPDOMapping(nNodeID, nTPDONo, nLen, PdoMappingArr);
if (ret == false)
{
txt_CommandHistory.AppendText(string.Format("SetTPDOMapping failed\r\n"));
}
}
VB.NET
''' <summary>
''' This procedure shows how to set RPDO and TPDO mapping
''' </summary>
Private Sub SetPDOMappingSettingsSample()
' RPDO 1
nLen = 1
nRPDONo = 0
PdoMappingArr = New PDOMapping(nLen - 1){}
PdoMappingArr(0).Index = &H6040
PdoMappingArr(0).SubIndex = 0
PdoMappingArr(0).BitCounts = &H10
ret = m_CANopenLibHelper.SetRPDOMapping(nNodeID, nRPDONo, nLen, PdoMappingArr)
If ret = False Then
txt_CommandHistory.AppendText(String.Format("SetRPDOMapping failed" & vbCrLf))
End If
' RPDO 2
nLen = 2
nRPDONo = 1
PdoMappingArr = New PDOMapping(nLen - 1){}
PdoMappingArr(0).Index = &H6040
PdoMappingArr(0).SubIndex = 0
PdoMappingArr(0).BitCounts = &H10
PdoMappingArr(1).Index = &H607A
PdoMappingArr(1).SubIndex = 0
PdoMappingArr(1).BitCounts = &H20
ret = m_CANopenLibHelper.SetRPDOMapping(nNodeID, nRPDONo, nLen, PdoMappingArr)
If ret = False Then
txt_CommandHistory.AppendText(String.Format("SetRPDOMapping failed" & vbCrLf))
End If
' RPDO 3
nLen = 2
nRPDONo = 2
PdoMappingArr = New PDOMapping(nLen - 1){}
PdoMappingArr(0).Index = &H6040
PdoMappingArr(0).SubIndex = 0
PdoMappingArr(0).BitCounts = &H10
PdoMappingArr(1).Index = &H60FF
PdoMappingArr(1).SubIndex = 0
PdoMappingArr(1).BitCounts = &H20
Shanghai AMP & MOONS’ Automation Equipment Co., Ltd., 2017 43 / 73
MOONS’ CANopen Library User Manual
' RPDO 4
nLen = 1
nRPDONo = 3
PdoMappingArr = New PDOMapping(nLen - 1){}
PdoMappingArr(0).Index = &H60FE
PdoMappingArr(0).SubIndex = &H1
PdoMappingArr(0).BitCounts = &H20
ret = m_CANopenLibHelper.SetRPDOMapping(nNodeID, nRPDONo, nLen, PdoMappingArr)
If ret = False Then
txt_CommandHistory.AppendText(String.Format("SetRPDOMapping failed" & vbCrLf))
End If
' TPDO 1
nLen = 1
nTPDONo = 0
PdoMappingArr = New PDOMapping(nLen - 1){}
PdoMappingArr(0).Index = &H6041
PdoMappingArr(0).SubIndex = 0
PdoMappingArr(0).BitCounts = &H10
ret = m_CANopenLibHelper.SetTPDOMapping(nNodeID, nTPDONo, nLen, PdoMappingArr)
If ret = False Then
txt_CommandHistory.AppendText(String.Format("SetTPDOMapping failed" & vbCrLf))
End If
' TPDO 2
nLen = 2
nTPDONo = 1
PdoMappingArr = New PDOMapping(nLen - 1){}
PdoMappingArr(0).Index = &H6041
PdoMappingArr(0).SubIndex = 0
PdoMappingArr(0).BitCounts = &H10
PdoMappingArr(1).Index = &H700A
PdoMappingArr(1).SubIndex = 0
PdoMappingArr(1).BitCounts = &H20
ret = m_CANopenLibHelper.SetTPDOMapping(nNodeID, nTPDONo, nLen, PdoMappingArr)
If ret = False Then
txt_CommandHistory.AppendText(String.Format("SetTPDOMapping failed" & vbCrLf))
End If
' TPDO 3
Shanghai AMP & MOONS’ Automation Equipment Co., Ltd., 2017 44 / 73
MOONS’ CANopen Library User Manual
nLen = 2
nTPDONo = 2
PdoMappingArr = New PDOMapping(nLen - 1){}
PdoMappingArr(0).Index = &H6041
PdoMappingArr(0).SubIndex = 0
PdoMappingArr(0).BitCounts = &H10
PdoMappingArr(1).Index = &H7009
PdoMappingArr(1).SubIndex = 0
PdoMappingArr(1).BitCounts = &H10
ret = m_CANopenLibHelper.SetTPDOMapping(nNodeID, nTPDONo, nLen, PdoMappingArr)
If ret = False Then
txt_CommandHistory.AppendText(String.Format("SetTPDOMapping failed" & vbCrLf))
End If
' TPDO 4
nLen = 1
nTPDONo = 3
PdoMappingArr = New PDOMapping(nLen - 1){}
PdoMappingArr(0).Index = &H7003
PdoMappingArr(0).SubIndex = 0
PdoMappingArr(0).BitCounts = &H10
ret = m_CANopenLibHelper.SetTPDOMapping(nNodeID, nTPDONo, nLen, PdoMappingArr)
If ret = False Then
txt_CommandHistory.AppendText(String.Format("SetTPDOMapping failed" & vbCrLf))
End If
End Sub
Description Restore RPDO & TPDO Mapping settings to factory default settings.
0: RPDO1
1: RPDO2
2: RPDO3
3: RPDO4
0: 5007h
1: 5008h
2: 5009h
3: 500Ah
4: 500Bh
5: 500Ch
6: 500Dh
7: 500Eh
0: 5007h
1: 5008h
2: 5009h
3: 500Ah
4: 500Bh
5: 500Ch
6: 500Dh
7: 500Eh
pPolarity Polarity
1 Velocity Mode
2 Profile Velocity Mode
3 Profile Torque Mode
4 reserved
5 Homing Mode
6 Interpolated Position Mode
7 reserved
8 reserved
9 reserved
10…15 reserved
16…31 Manufacturer sepcific
Bit1: input 2
Bit2: input 3
Bit3: input 4
Bit4: input 5
Bit5: input 6
Bit6: input 7
Bit7: input 8
Bit8-15: reserved
BOOL WriteProfileParam(BYTE nNodeID, int* nMode, int* nDistance, double* dVelocity, double* dAccel, double*
dDecel);
FALSE: Disable
BOOL RelMove(BYTE nNodeID, int nDistance, double* dVelocity, double* dAccel, double* dDecel);
Return value return TRUE if execute command successfully, otherwise return FALSE.
BOOL AbsMove(BYTE nNodeID, int nDistance, double* dVelocity, double* dAccel, double* dDecel);
BOOL MultipleAbsMoveWithStopping(BYTE nNodeID, int nDistance1, int nDistance2, double* dVelocity1, double*
Return value return TRUE if execute command successfully, otherwise return FALSE.
BOOL MultipleAbsMoveContinuous(BYTE nNodeID, int nDistance1, int nDistance2, double* dVelocity1, double*
Return value return TRUE if execute command successfully, otherwise return FALSE.
Other:1~12
Return value return TRUE if send command successfully, otherwise return FALSE.
Other:1~12
Return value return TRUE if execute command successfully, otherwise return FALSE.
BOOL Homing(BYTE nNodeID, int nHomingMethod, double* nHomingVelocity, double* dIndexVelocity, double*
Return value return TRUE if execute command successfully, otherwise return FALSE.
5 FAQ