4. Examples

4.1. CoeSdoUpload

public void CoeSdoUploadExample()
{
  ushort wSlaveAddress = 1012; // slave with station address 1012
  ushort wObIndex = 0x1018; // object index 0x1018
  byte byObSubIndex = 1; // subindex 1 (Vendor ID, which is from type UDINT with 4 bytes)
  uint dwDataLen = 4; // 4 bytes
  byte[] pbyData = new byte[dwDataLen];
  uint dwOutDataLen = 0;
  uint dwTimeout = 5000; // timeout 5s
  uint dwFlags = (uint)EMailBoxFlags.NONE; // no complete access

  uint dwSlaveId = m_oEcWrapper.GetSlaveId(wSlaveAddress);
  ECError eRes = m_oEcWrapper.CoeSdoUpload(dwSlaveId, wObIndex, byObSubIndex, pbyData, dwDataLen, out dwOutDataLen, dwTimeout, dwFlags);
  if (eRes != ECError.EC_NOERROR)
  {
    LogMasterError("CoeSdoUpload failed: ", eRes);
    return;
  }

  string szValue = CEcWrapperDotNet.ConvValueToString(DN_EC_T_DEFTYPE.ARRAY_OF_BYTE, pbyData);
  LogInfo("CoeSdoUpload success: " + szValue); // 02 00 00 00
}

4.2. CoeSdoDownload

public void CoeSdoDownloadExample()
{
  ushort wSlaveAddress = 1012; // slave with station address 1012
  ushort wObIndex = 0x40A2; // object index 0x40A2
  byte byObSubIndex = 2; // subindex 2
  uint dwValue = 123; // value 123
  uint dwTimeout = 5000; // timeout 5s
  uint dwFlags = (uint)EMailBoxFlags.NONE; // no complete access

  // convert UNSIGNED32 value to 4 bytes
  byte[] pbyData = null;
  ECError eRes = CEcWrapperDotNet.ConvValueToBytes(DN_EC_T_DEFTYPE.UNSIGNED32, dwValue, out pbyData);
  if (eRes != ECError.EC_NOERROR)
  {
    LogMasterError("ConvValueToBytes failed: ", eRes);
    return ;
  }

  uint dwSlaveId = m_oEcWrapper.GetSlaveId(wSlaveAddress);
  eRes = m_oEcWrapper.CoeSdoDownload(dwSlaveId, wObIndex, byObSubIndex, pbyData, (uint)pbyData.Length, dwTimeout, dwFlags);
  if (eRes != ECError.EC_NOERROR)
  {
    LogMasterError("CoeSdoDownload failed: ", eRes);
    return;
  }

  LogInfo("CoeSdoDownload success");
}

4.3. ReadSlaveEEPRom

public void ReadSlaveEEPRomExample()
{
  bool bFixedAddressing = true; // enable fixed addressing
  ushort wSlaveAddress = 1006; // slave with station address 1006
  ushort wEEPRomStartOffset = 0x0; // offset 0
  uint dwReadLen = 10; // 10 bytes
  byte[] pwReadData = new byte[dwReadLen];
  uint dwNumOutData = 0;
  uint dwTimeout = 2000; // timeout 2s

  ECError eRes = m_oEcWrapper.ReadSlaveEEPRom(bFixedAddressing, wSlaveAddress, wEEPRomStartOffset, pwReadData, dwReadLen, out dwNumOutData, dwTimeout);
  if (eRes != ECError.EC_NOERROR)
  {
    LogMasterError("ReadSlaveEEPRom failed: ", eRes);
    return;
  }

  string szValue = CEcWrapperDotNet.ConvValueToString(DN_EC_T_DEFTYPE.ARRAY_OF_BYTE, pwReadData);
  LogInfo("ReadSlaveEEPRom success: " + szValue);
}

4.4. FoeFileDownload

public void FoeFileDownloadExample()
{
  ushort wSlaveAddress = 1012; // slave with station address 1012
  string szFileName = "foe.txt"; // filename of file in slave
  byte[] pbyData = new byte[] { 1, 2, 3, 4 }; // 4 bytes
  uint dwPassword = 0;  // password is 0
  uint dwTimeout = 2000; // timeout 2s

  uint dwSlaveId = m_oEcWrapper.GetSlaveId(wSlaveAddress);
  ECError eRes = m_oEcWrapper.FoeFileDownload(dwSlaveId, szFileName, (uint)szFileName.Length, pbyData, (uint)pbyData.Length, dwPassword, dwTimeout);
  if (eRes != ECError.EC_NOERROR)
  {
    LogMasterError("FoeFileDownload failed: ", eRes);
    return;
  }

  LogInfo("FoeFileDownload success");
}