AoeWriteCommand

Writes data through ADS over EtherCAT (AoE).

Syntax

KsCommandStatus AoeWriteCommand(
     int SlaveId,
     int Port,
     int IndexGroup,
     int IndexOffset,
     BYTE* Value,
     int Length
);

Parameters

SlaveId: the slave index. This index value is automatically assigned by the KINGSTAR master when the EtherCAT network starts, based on the physical connection order. The first device connected directly to the master is assigned Index 0, followed by Index 1, Index 2, and so on. These indexes remain consistent within the slave array even if devices are added, removed, or reconnected. Please refer to the use cases in HotConnect, Repair, and Restart for more details.

Port: the EtherCAT slave port.

IndexGroup: the index group of the object to write.

IndexOffset: the offset of the object in the group.

Value: pointer to the buffer containing the value to write.

Length: the length in byte of the value to write.

Return value

Returns the KsCommandStatus structure.

Usable EtherCAT states

ecatPreOP, ecatSafeOP, ecatOP

Example

Copy
//////////////////////////////////////////////////////////////////
//
// This code snippet demonstrates how to configure CANopen devices
// connected to CANopen master and use AoeReadCommand to request
// service data stored in these CANopen devices.
// This code snippet is to be used with Beckhoff EL6751 CANopen
// master/slave terminal.
//
//////////////////////////////////////////////////////////////////

KsError nRet = errNoError;
KsCommandStatus Command = { 0 };
CanOpenSetting CanOpen = { 0 };
BYTE byteRead = 0;
BYTE byteWrite = 1;

CanOpen.RxPdoCount = 4;
CanOpen.RxPdos[0] = { TRUE, 16, 0x1800, 0xFF };
CanOpen.RxPdos[1] = { FALSE, 48, 0x1801, 0xFF };
CanOpen.RxPdos[2] = { FALSE, 48, 0x1802, 0xFF };
CanOpen.RxPdos[3] = { FALSE, 0, 0x1803, 0xFF };

CanOpen.TxPdoCount = 4;
CanOpen.TxPdos[0] = { TRUE, 16, 0x1400, 0xFF };
CanOpen.TxPdos[1] = { FALSE, 48, 0x1401, 0xFF };
CanOpen.TxPdos[2] = { FALSE, 48, 0x1402, 0xFF };
CanOpen.TxPdos[3] = { FALSE, 0, 0x1403, 0xFF };

// Send start-up SDO commands so that some settings can be done after KINGSTAR subsystem is started
CanOpen.SdoCommandCount = 1;
CanOpen.SdoCommands[0].Index = 0x6060;
CanOpen.SdoCommands[0].SubIndex = 0;
CanOpen.SdoCommands[0].Length = 1;
CanOpen.SdoCommands[0].Data[0] = 0x1;

nRet = Create(0, 0);

nRet = AddModuleConfiguration(
           1,                // EthercatSlaveID
           0x70,             // LinkedDeviceID, it is CANopen device's node ID for CANopen protocol
           configCANopen,    // Protocol
           &CanOpen          // Settings
       );

Command = WaitForCommand(60, TRUE, Start());

Command = WaitForCommand(
              5,
              FALSE,
              AoeReadCommand(
                  1,            // SlaveID
                  0x1070,       // Port, it is 0x1000 + LinkedDeviceID used in ConfigLinkedDevice
                  0x6060,       // IndexGroup, enter object index here for SDO reading/writing through EL6751
                  0,            // IndexOffset, enter object subindex here for SDO reading/writing through EL6751
                  &byteRead,    // Value
                  1             // Length
              )
          );
Command = WaitForCommand(5, FALSE, AoeWriteCommand(1, 0x1070, 0x6060, 0, &byteWrite, 1));

Command = WaitForCommand(5, FALSE, Stop());

Requirements

  RT Win32
Minimum supported version 4.0 4.0
Header ksapi.h ksapi.h
Library KsApi_Rtss.lib KsApi.lib

See also

AoeReadCommand

AoeReadSdoObject

AoeReadWriteCommand

AoeWriteControlCommand

AoeWriteSdoObject