FoeWriteFileFromBuffer
Reads a file from the local buffer and writes it to the device.
Syntax
KsCommandStatus FoeWriteFileFromBuffer(
int SlaveId,
BOOL BootState,
int NameLength,
char* Name,
DWORD Password,
int BufferLength,
BYTE* Buffer
);
Parameters
SlaveId: the index of a slave array. When EtherCAT is started, this index has the same value as the SlaveId, which corresponds to the position of the slave in the network. Please note that after EtherCAT is started in the Operational (Op) state, any addition or removal of slaves from the network will change the position of the slaves in the network (SlaveId). Nevertheless, the index of the slave will remain the same. Newly added devices will be added in the back of the slave array. For all slaves after the change, the index and SlaveId will no longer match. This behavior is only available for physical devices; simulated devices are inapplicable. Please refer to the use cases in EnableHotConnect for more details.
BootState: determines whether the EtherCAT slave is to be in the Bootstrap (Boot) state to use FoE. The Boot state can be used to update firmware or configure the slave settings.
TRUE: Boot state.
FALSE: Normal state.
NameLength: the length of the file name to be written into the device.
Name: the file name to be written into the device.
Password: if the device requires a password to access the file, you need to specify the password here. Zero means there is no password.
BufferLength: the length of the buffer to store the written file.
Buffer: the buffer containing the file to be written.
Return value
Returns the KsCommandStatus structure.
Remarks
- When the EtherCAT link starts properly, the slave's state is Init -> PreOp -> SafeOp -> Op. If the slave is in Op and you use this function with the BootState set to TRUE, the slave's state will become Op -> Init -> Boot. After the task is done, its state becomes Init -> PreOp -> SafeOp -> Op again.
- This function can only be used from RTX64 as pointers. It cannot be shared between RTX64 and Windows.
Usable EtherCAT states
ecatBoot, ecatPreOP, ecatSafeOP, ecatOP
Example
// You can use any 3rd-party library to import the file to the buffer in your application.
char target[32] = "Target.xml";
DWORD nBytes = 0;
HANDLE hFile = CreateFile(_T("Source.xml"), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_ALWAYS, 0, NULL);
if (hFile != INVALID_HANDLE_VALUE)
{
char line[1024] = { 0 };
BOOL bResult;
bResult = ReadFile(hFile, line, sizeof(line), &nBytes, NULL);
Command = FoeWriteFileFromBuffer(0, TRUE, 32, target, 123, 1024, (BYTE*)line);
}
Requirements
RT | Win32 | |
---|---|---|
Minimum supported version | 4.0 | 4.0 |
Header | ksapi.h | ksapi.h |
Library | KsApi_Rtss.lib | KsApi.lib |
See also