// =====================================================================
// Example OptoScript block for a chart that manages drive 1 via ecatd.
// Strategy variables used:
//   chEcat   Communication Handle, initial value "tcp:127.0.0.1:5020"
//   sReply, sValue            String (width 256)
//   nResult                   Integer 32
//   fDrive1Pos                Float
//   nDrive1Enabled, nDrive1Fault   Integer 32
//
// If your PAC Control version does not allow calling a subroutine from
// OptoScript, use a "Call Subroutine" action block with the same
// parameters instead of the EcatCommand(...) lines.
// =====================================================================

// ---- read actual position ----
EcatCommand(chEcat, "GET 1 POS_ACTUAL", 1000, sReply, sValue, nResult);
if (nResult == 0) then
  fDrive1Pos = StringToFloat(sValue);
endif

// ---- read enable / fault state ----
// reply looks like: OK STATE=OPERATION_ENABLED SW=0x0237 CW=0x000F FAULT=0 WARN=0 ENABLED=1 CMD=ENABLE
EcatCommand(chEcat, "STATUS 1", 1000, sReply, sValue, nResult);
if (nResult == 0) then
  nDrive1Enabled = (FindSubstringInString("ENABLED=1", 0, sValue) >= 0);
  nDrive1Fault   = (FindSubstringInString("FAULT=1",   0, sValue) >= 0);
endif

// ---- commands (normally triggered by operator buttons / sequence logic) ----
// EcatCommand(chEcat, "ENABLE 1",  1000, sReply, sValue, nResult);
// EcatCommand(chEcat, "DISABLE 1", 1000, sReply, sValue, nResult);
// EcatCommand(chEcat, "RESET 1",   1000, sReply, sValue, nResult);
// EcatCommand(chEcat, "SET 1 PROFILE_VEL 5000", 1000, sReply, sValue, nResult);
