Skip to content

4.6 C99 BasScript Builder

Overview

C99 BasScript uses ArmBasScriptHandle* and ArmBasExtraParamHandle* as builder handles. They are local script-text construction objects. An ArmHandle* is only required when the script is executed.

Header file:

  • include/c_arm_bas_script.h

Basic APIs

Arm_BasScript_Create

c
int Arm_BasScript_Create(ArmBasScriptHandle** outScript);
ItemDescription
DescriptionCreates an empty BAS script builder.
Request parametersoutScript : ArmBasScriptHandle** , output script-builder handle; on success, a non-null pointer is written
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Arm_BasScript_CreateWithName

c
int Arm_BasScript_CreateWithName(const char* scriptName, ArmBasScriptHandle** outScript);
ItemDescription
DescriptionCreates a BAS script builder with a script name.
Request parametersscriptName : const char* , script name string
outScript : ArmBasScriptHandle** , output script-builder handle; on success, a non-null pointer is written
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Arm_BasScript_Destroy

c
void Arm_BasScript_Destroy(ArmBasScriptHandle* script);
ItemDescription
DescriptionDestroys a BAS script builder.
Request parametersscript : ArmBasScriptHandle* , BasScript script-builder handle
Return valueNo return value

Arm_BasScript_Reset

c
int Arm_BasScript_Reset(ArmBasScriptHandle* script);
ItemDescription
DescriptionResets a BAS script builder.
Request parametersscript : ArmBasScriptHandle* , BasScript script-builder handle
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Arm_BasScript_SetName

c
int Arm_BasScript_SetName(ArmBasScriptHandle* script, const char* scriptName);
ItemDescription
DescriptionSets the BAS script name.
Request parametersscript : ArmBasScriptHandle* , BasScript script-builder handle
scriptName : const char* , script name string
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Arm_BasScript_GetName

c
int Arm_BasScript_GetName(ArmBasScriptHandle* script, char* outBuf, size_t bufSize);
ItemDescription
DescriptionReads the BAS script name.
Request parametersscript : ArmBasScriptHandle* , BasScript script-builder handle
outBuf : char* , output string buffer allocated by the caller
bufSize : size_t , output buffer size, including space for the trailing \0
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions
NotesString output uses the caller-provided buffer. If the buffer is too small, the function reports that through the status code.

Arm_BasScript_AppendLine

c
int Arm_BasScript_AppendLine(ArmBasScriptHandle* script, const char* line);
ItemDescription
DescriptionAppends one line of BAS script text.
Request parametersscript : ArmBasScriptHandle* , BasScript script-builder handle
line : const char* , one BAS script text line
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Arm_BasScript_AppendLines

c
int Arm_BasScript_AppendLines(ArmBasScriptHandle* script, const char* const* lines, size_t lineCount);
ItemDescription
DescriptionAppends multiple BAS script text lines.
Request parametersscript : ArmBasScriptHandle* , BasScript script-builder handle
lines : const char* const* , array of BAS script text lines
lineCount : size_t , number of script text lines
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Arm_BasScript_GetText

c
int Arm_BasScript_GetText(ArmBasScriptHandle* script, char* outBuf, size_t bufSize);
ItemDescription
DescriptionExports the BAS script text generated by the current builder.
Request parametersscript : ArmBasScriptHandle* , BasScript script-builder handle
outBuf : char* , output string buffer allocated by the caller
bufSize : size_t , output buffer size, including space for the trailing \0
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions
NotesString output uses the caller-provided buffer. If the buffer is too small, the function reports that through the status code.

Arm_BasScript_GetLineCount

c
int Arm_BasScript_GetLineCount(ArmBasScriptHandle* script, size_t* outCount);
ItemDescription
DescriptionReads the current number of script text lines.
Request parametersscript : ArmBasScriptHandle* , BasScript script-builder handle
outCount : size_t* , output-count pointer; on success, receives the actual count
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Arm_BasScript_Execute

c
int Arm_BasScript_Execute(ArmHandle* h, ArmBasScriptHandle* script);
ItemDescription
DescriptionExecutes the BAS script generated by the current builder.
Request parametersh : ArmHandle* , C99 session handle, usually created by Arm_Create() ; service APIs require a successful connection first
script : ArmBasScriptHandle* , BasScript script-builder handle
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Value Construction APIs

Arm_BasValue_Int32

c
ArmBasValue Arm_BasValue_Int32(int32_t value);
ItemDescription
DescriptionConstructs a BAS parameter value of type int32_t .
Request parametersvalue : int32_t , integer literal
Return valueArmBasValue ; a value object that can be passed to BasScript builder APIs

Arm_BasValue_Float64

c
ArmBasValue Arm_BasValue_Float64(double value);
ItemDescription
DescriptionConstructs a BAS parameter value of type double .
Request parametersvalue : double , floating-point literal
Return valueArmBasValue ; a value object that can be passed to BasScript builder APIs

Arm_BasValue_String

c
ArmBasValue Arm_BasValue_String(const char* value);
ItemDescription
DescriptionConstructs a BAS parameter value of string type.
Request parametersvalue : const char* , string literal; must not be NULL
Return valueArmBasValue ; a value object that can be passed to BasScript builder APIs

Arm_BasValue_TaggedInt

c
ArmBasValue Arm_BasValue_TaggedInt(int32_t tag, int32_t value);
ItemDescription
DescriptionConstructs a tagged integer BAS parameter value for enum-style parameters.
Request parameterstag : int32_t , value tag that identifies which field of ArmBasValue is active
value : int32_t , enum value or index value associated with the tag
Return valueArmBasValue ; a value object that can be passed to BasScript builder APIs

Instruction Construction APIs

Arm_BasScript_SetParam

c
int Arm_BasScript_SetParam(ArmBasScriptHandle* script, int32_t type, int32_t valueType, ArmBasValue value);
ItemDescription
DescriptionGenerates a BAS statement that sets a script parameter.
Request parametersscript : ArmBasScriptHandle* , BasScript script-builder handle
type : int32_t , script parameter type; see ArmBasParamType for values
valueType : int32_t , value source type; see ArmBasValueType for values
value : ArmBasValue ; when valueType is a direct value, this is the parameter value; when it is an R register, this is the R number
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Arm_BasScript_AssignValue

c
int Arm_BasScript_AssignValue(ArmBasScriptHandle* script, int32_t param1, int32_t index, ArmBasValue param2, ArmBasValue value, int32_t optIndex, int32_t optValue);
ItemDescription
DescriptionGenerates a BAS assignment statement.
Request parametersscript : ArmBasScriptHandle* , BasScript script-builder handle
param1 : int32_t , assignment left-side type; see ArmBasAssignType for values
index : int32_t , left-side number, for example an R, PR, SR, or IO number
param2 : ArmBasValue , right-side source type, such as register, IO, literal, string, or current pose
value : ArmBasValue , right-side value or source number
optIndex : int32_t , PR element, IO group, or additional index
optValue : int32_t , PR element, IO status, or additional value
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Arm_BasScript_Motion_MoveJoint

c
int Arm_BasScript_Motion_MoveJoint(ArmBasScriptHandle* script, int32_t poseType, int32_t poseIndex, int32_t speedType, double speedValue, int32_t smoothType, double smoothDistance, const ArmBasExtraParamHandle* extraParam);
ItemDescription
DescriptionExecutes or generates a joint-motion statement.
Request parametersscript : ArmBasScriptHandle* , BasScript script-builder handle
poseType : int32_t , pose type, joint or Cartesian
poseIndex : int32_t , PR point index
speedType : int32_t , speed type, either a direct value or a register
speedValue : double , speed value or speed register index
smoothType : int32_t , smoothing type
smoothDistance : double , smoothing distance
extraParam : const ArmBasExtraParamHandle* , BasScript extra-parameter builder handle; may be NULL to append no extra parameters
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Arm_BasScript_Motion_MoveLine

c
int Arm_BasScript_Motion_MoveLine(ArmBasScriptHandle* script, int32_t poseType, int32_t poseIndex, int32_t speedType, double speedValue, int32_t smoothType, double smoothDistance, const ArmBasExtraParamHandle* extraParam);
ItemDescription
DescriptionExecutes or generates a linear-motion statement.
Request parametersscript : ArmBasScriptHandle* , BasScript script-builder handle
poseType : int32_t , pose type, joint or Cartesian
poseIndex : int32_t , PR point index
speedType : int32_t , speed type, either a direct value or a register
speedValue : double , speed value or speed register index
smoothType : int32_t , smoothing type
smoothDistance : double , smoothing distance
extraParam : const ArmBasExtraParamHandle* , BasScript extra-parameter builder handle; may be NULL to append no extra parameters
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Arm_BasScript_Motion_MoveCircle

c
int Arm_BasScript_Motion_MoveCircle(ArmBasScriptHandle* script, int32_t poseType1, int32_t poseIndex1, int32_t poseType2, int32_t poseIndex2, int32_t speedType, double speedValue, int32_t smoothType, double smoothDistance, const ArmBasExtraParamHandle* extraParam);
ItemDescription
DescriptionExecutes or generates an arc-motion statement.
Request parametersscript : ArmBasScriptHandle* , BasScript script-builder handle
poseType1 : int32_t , via-point source type; the currently exposed value is ARM_BAS_MOVE_POSE_PR
poseIndex1 : int32_t , via-point PR index
poseType2 : int32_t , end-point source type; the currently exposed value is ARM_BAS_MOVE_POSE_PR
poseIndex2 : int32_t , end-point PR index
speedType : int32_t , speed type, either a direct value or a register
speedValue : double , speed value or speed register index
smoothType : int32_t , smoothing type
smoothDistance : double , smoothing distance
extraParam : const ArmBasExtraParamHandle* , BasScript extra-parameter builder handle; may be NULL to append no extra parameters
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Arm_BasScript_Motion_MoveJump

c
int Arm_BasScript_Motion_MoveJump(ArmBasScriptHandle* script, int32_t poseType, int32_t poseIndex, double speedValue, double speedRatio, int32_t limZType, double limZValue, int32_t smoothType, double smoothDistance, const ArmBasExtraParamHandle* extraParam);
ItemDescription
DescriptionProvides the C99 API capability for BasScript Motion MoveJump .
Request parametersscript : ArmBasScriptHandle* , BasScript script-builder handle
poseType : int32_t , pose type, joint or Cartesian
poseIndex : int32_t , PR point index
speedValue : double , speed value or speed register index
speedRatio : double , speed ratio
limZType : int32_t , Jump height-limit parameter type
limZValue : double , Jump height-limit value
smoothType : int32_t , smoothing type
smoothDistance : double , smoothing distance
extraParam : const ArmBasExtraParamHandle* , BasScript extra-parameter builder handle; may be NULL to append no extra parameters
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Arm_BasScript_Motion_MoveJump3

c
int Arm_BasScript_Motion_MoveJump3(ArmBasScriptHandle* script, int32_t poseType, const int32_t* poseIndexList, size_t poseIndexCount, double speedValue, double speedRatio, int32_t smoothType, double smoothDistance, const ArmBasExtraParamHandle* extraParam);
ItemDescription
DescriptionProvides the C99 API capability for BasScript Motion MoveJump3 .
Request parametersscript : ArmBasScriptHandle* , BasScript script-builder handle
poseType : int32_t , pose type, joint or Cartesian
poseIndexList : const int32_t* , array of PR point indexes
poseIndexCount : size_t , number of PR point indexes
speedValue : double , speed value or speed register index
speedRatio : double , speed ratio
smoothType : int32_t , smoothing type
smoothDistance : double , smoothing distance
extraParam : const ArmBasExtraParamHandle* , BasScript extra-parameter builder handle; may be NULL to append no extra parameters
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Arm_BasScript_Motion_MoveJump3cp

c
int Arm_BasScript_Motion_MoveJump3cp(ArmBasScriptHandle* script, int32_t poseType, const int32_t* poseIndexList, size_t poseIndexCount, double speedValue, int32_t smoothType, double smoothDistance, const ArmBasExtraParamHandle* extraParam);
ItemDescription
DescriptionProvides the C99 API capability for BasScript Motion MoveJump3cp .
Request parametersscript : ArmBasScriptHandle* , BasScript script-builder handle
poseType : int32_t , pose type, joint or Cartesian
poseIndexList : const int32_t* , array of PR point indexes
poseIndexCount : size_t , number of PR point indexes
speedValue : double , speed value or speed register index
smoothType : int32_t , smoothing type
smoothDistance : double , smoothing distance
extraParam : const ArmBasExtraParamHandle* , BasScript extra-parameter builder handle; may be NULL to append no extra parameters
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Arm_BasScript_Logical_If

c
int Arm_BasScript_Logical_If(ArmBasScriptHandle* script, ArmBasValue param1, int32_t index, ArmBasValue param2, ArmBasValue value, int32_t op);
ItemDescription
DescriptionGenerates an IF condition statement.
Request parametersscript : ArmBasScriptHandle* , BasScript script-builder handle
param1 : ArmBasValue , left-side source type for the condition, such as register, IO, literal, or string
index : int32_t , left-side number, for example an R, SR, or IO number
param2 : ArmBasValue , right-side source type for the condition
value : ArmBasValue , right-side value or source number
op : int32_t , comparison or logical operator; see ArmBasBooleanOperator for values
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Arm_BasScript_Logical_ElseIf

c
int Arm_BasScript_Logical_ElseIf(ArmBasScriptHandle* script, ArmBasValue param1, int32_t index, ArmBasValue param2, ArmBasValue value, int32_t op);
ItemDescription
DescriptionGenerates an ELSE IF condition statement.
Request parametersscript : ArmBasScriptHandle* , BasScript script-builder handle
param1 : ArmBasValue , left-side source type for the condition, such as register, IO, literal, or string
index : int32_t , left-side number, for example an R, SR, or IO number
param2 : ArmBasValue , right-side source type for the condition
value : ArmBasValue , right-side value or source number
op : int32_t , comparison or logical operator; see ArmBasBooleanOperator for values
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Arm_BasScript_Logical_Else

c
int Arm_BasScript_Logical_Else(ArmBasScriptHandle* script);
ItemDescription
DescriptionGenerates an ELSE statement.
Request parametersscript : ArmBasScriptHandle* , BasScript script-builder handle
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Arm_BasScript_Logical_EndIf

c
int Arm_BasScript_Logical_EndIf(ArmBasScriptHandle* script);
ItemDescription
DescriptionGenerates an ENDIF statement.
Request parametersscript : ArmBasScriptHandle* , BasScript script-builder handle
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Arm_BasScript_Logical_Switch

c
int Arm_BasScript_Logical_Switch(ArmBasScriptHandle* script, ArmBasValue param, int32_t index);
ItemDescription
DescriptionGenerates a SWITCH / SELECT statement.
Request parametersscript : ArmBasScriptHandle* , BasScript script-builder handle
param : ArmBasValue , SELECT expression source type
index : int32_t , SELECT expression number, for example an R, SR, or IO number
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Arm_BasScript_Logical_Case

c
int Arm_BasScript_Logical_Case(ArmBasScriptHandle* script, ArmBasValue param, ArmBasValue value);
ItemDescription
DescriptionGenerates a CASE statement.
Request parametersscript : ArmBasScriptHandle* , BasScript script-builder handle
param : ArmBasValue , CASE value source type
value : ArmBasValue , CASE match value or source number
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Arm_BasScript_Logical_Default

c
int Arm_BasScript_Logical_Default(ArmBasScriptHandle* script);
ItemDescription
DescriptionGenerates a DEFAULT statement.
Request parametersscript : ArmBasScriptHandle* , BasScript script-builder handle
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Arm_BasScript_Logical_EndSwitch

c
int Arm_BasScript_Logical_EndSwitch(ArmBasScriptHandle* script);
ItemDescription
DescriptionGenerates an END SWITCH / ENDSELECT statement.
Request parametersscript : ArmBasScriptHandle* , BasScript script-builder handle
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Arm_BasScript_Logical_While

c
int Arm_BasScript_Logical_While(ArmBasScriptHandle* script, ArmBasValue param1, int32_t index, ArmBasValue param2, ArmBasValue value, int32_t op);
ItemDescription
DescriptionGenerates a WHILE statement.
Request parametersscript : ArmBasScriptHandle* , BasScript script-builder handle
param1 : ArmBasValue , left-side source type for the condition, such as register, IO, literal, or string
index : int32_t , left-side number, for example an R, SR, or IO number
param2 : ArmBasValue , right-side source type for the condition
value : ArmBasValue , right-side value or source number
op : int32_t , comparison or logical operator; see ArmBasBooleanOperator for values
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Arm_BasScript_Logical_EndWhile

c
int Arm_BasScript_Logical_EndWhile(ArmBasScriptHandle* script);
ItemDescription
DescriptionGenerates a WHILE ending statement.
Request parametersscript : ArmBasScriptHandle* , BasScript script-builder handle
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Arm_BasScript_Logical_Goto

c
int Arm_BasScript_Logical_Goto(ArmBasScriptHandle* script, int32_t index);
ItemDescription
DescriptionGenerates a GOTO statement.
Request parametersscript : ArmBasScriptHandle* , BasScript script-builder handle
index : int32_t , target LABEL number
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Arm_BasScript_Logical_Label

c
int Arm_BasScript_Logical_Label(ArmBasScriptHandle* script, int32_t index);
ItemDescription
DescriptionGenerates a LABEL statement.
Request parametersscript : ArmBasScriptHandle* , BasScript script-builder handle
index : int32_t , current LABEL number
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Arm_BasScript_Logical_SkipCondition

c
int Arm_BasScript_Logical_SkipCondition(ArmBasScriptHandle* script, ArmBasValue param1, int32_t index, ArmBasValue param2, ArmBasValue value, int32_t op);
ItemDescription
DescriptionGenerates a SKIP CONDITION statement.
Request parametersscript : ArmBasScriptHandle* , BasScript script-builder handle
param1 : ArmBasValue , left-side source type for the condition, such as register, IO, literal, or string
index : int32_t , left-side number, for example an R, SR, or IO number
param2 : ArmBasValue , right-side source type for the condition
value : ArmBasValue , right-side value or source number
op : int32_t , comparison or logical operator; see ArmBasBooleanOperator for values
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Arm_BasScript_Logical_Break

c
int Arm_BasScript_Logical_Break(ArmBasScriptHandle* script);
ItemDescription
DescriptionGenerates a BREAK statement.
Request parametersscript : ArmBasScriptHandle* , BasScript script-builder handle
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Arm_BasScript_Logical_Continue

c
int Arm_BasScript_Logical_Continue(ArmBasScriptHandle* script);
ItemDescription
DescriptionGenerates a CONTINUE statement.
Request parametersscript : ArmBasScriptHandle* , BasScript script-builder handle
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Arm_BasScript_Structure_Wait

c
int Arm_BasScript_Structure_Wait(ArmBasScriptHandle* script, ArmBasValue param1, int32_t index, ArmBasValue param2, ArmBasValue value, int32_t op);
ItemDescription
DescriptionGenerates a conditional WAIT statement.
Request parametersscript : ArmBasScriptHandle* , BasScript script-builder handle
param1 : ArmBasValue , left-side source type for the wait condition
index : int32_t , left-side number for the wait condition, for example an R, SR, or IO number
param2 : ArmBasValue , right-side source type for the wait condition
value : ArmBasValue , right-side value or source number for the wait condition
op : int32_t , comparison or logical operator; see ArmBasBooleanOperator for values
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Arm_BasScript_Structure_WaitTime

c
int Arm_BasScript_Structure_WaitTime(ArmBasScriptHandle* script, int32_t valueType, ArmBasValue value);
ItemDescription
DescriptionGenerates a time-based WAIT statement.
Request parametersscript : ArmBasScriptHandle* , BasScript script-builder handle
valueType : int32_t , time source type; see ArmBasValueType for values
value : ArmBasValue , wait time in seconds or R register number
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Arm_BasScript_Structure_Pause

c
int Arm_BasScript_Structure_Pause(ArmBasScriptHandle* script);
ItemDescription
DescriptionGenerates a PAUSE statement.
Request parametersscript : ArmBasScriptHandle* , BasScript script-builder handle
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Arm_BasScript_Structure_Abort

c
int Arm_BasScript_Structure_Abort(ArmBasScriptHandle* script);
ItemDescription
DescriptionGenerates an abort statement.
Request parametersscript : ArmBasScriptHandle* , BasScript script-builder handle
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Arm_BasScript_Structure_Call

c
int Arm_BasScript_Structure_Call(ArmBasScriptHandle* script, const char* name);
ItemDescription
DescriptionGenerates a synchronous script-call statement.
Request parametersscript : ArmBasScriptHandle* , BasScript script-builder handle
name : const char* , script name to call synchronously; must not be NULL
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Arm_BasScript_Structure_Run

c
int Arm_BasScript_Structure_Run(ArmBasScriptHandle* script, const char* name);
ItemDescription
DescriptionGenerates an asynchronous script-run statement.
Request parametersscript : ArmBasScriptHandle* , BasScript script-builder handle
name : const char* , script name to run asynchronously; must not be NULL
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Arm_BasScript_Structure_Load

c
int Arm_BasScript_Structure_Load(ArmBasScriptHandle* script, int32_t loadType, ArmBasValue value);
ItemDescription
DescriptionGenerates a LOAD statement.
Request parametersscript : ArmBasScriptHandle* , BasScript script-builder handle
loadType : int32_t , program identifier source; see ArmBasLoadType for values
value : ArmBasValue , script name, R/SR number, or direct value
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Arm_BasScript_Structure_Unload

c
int Arm_BasScript_Structure_Unload(ArmBasScriptHandle* script, int32_t loadType, ArmBasValue value);
ItemDescription
DescriptionGenerates an UNLOAD statement.
Request parametersscript : ArmBasScriptHandle* , BasScript script-builder handle
loadType : int32_t , program identifier source; see ArmBasLoadType for values
value : ArmBasValue , script name, R/SR number, or direct value
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Arm_BasScript_Structure_Exec

c
int Arm_BasScript_Structure_Exec(ArmBasScriptHandle* script, int32_t loadType, ArmBasValue value);
ItemDescription
DescriptionGenerates an EXEC statement.
Request parametersscript : ArmBasScriptHandle* , BasScript script-builder handle
loadType : int32_t , program identifier source; see ArmBasLoadType for values
value : ArmBasValue , script name, R/SR number, or direct value
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Arm_BasScript_Socket_Open

c
int Arm_BasScript_Socket_Open(ArmBasScriptHandle* script, int32_t index);
ItemDescription
DescriptionGenerates a Socket open statement.
Request parametersscript : ArmBasScriptHandle* , BasScript script-builder handle
index : int32_t , Socket channel number
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Arm_BasScript_Socket_Close

c
int Arm_BasScript_Socket_Close(ArmBasScriptHandle* script, int32_t index);
ItemDescription
DescriptionGenerates a Socket close statement.
Request parametersscript : ArmBasScriptHandle* , BasScript script-builder handle
index : int32_t , Socket channel number
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Arm_BasScript_Socket_Connect

c
int Arm_BasScript_Socket_Connect(ArmBasScriptHandle* script, int32_t index);
ItemDescription
DescriptionGenerates a Socket connect statement.
Request parametersscript : ArmBasScriptHandle* , BasScript script-builder handle
index : int32_t , Socket channel number
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Arm_BasScript_Socket_Send

c
int Arm_BasScript_Socket_Send(ArmBasScriptHandle* script, int32_t index, int32_t msgType, ArmBasValue value);
ItemDescription
DescriptionGenerates a Socket send statement.
Request parametersscript : ArmBasScriptHandle* , BasScript script-builder handle
index : int32_t , Socket channel number
msgType : int32_t , Socket message type; see ArmBasStrType for values
value : ArmBasValue ; when ARM_BAS_STR_STRING , this is a string; when ARM_BAS_STR_SR , this is an SR number
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Arm_BasScript_Socket_Recv

c
int Arm_BasScript_Socket_Recv(ArmBasScriptHandle* script, int32_t index, int32_t msgLength, int32_t msgType, ArmBasValue value);
ItemDescription
DescriptionGenerates a Socket receive statement.
Request parametersscript : ArmBasScriptHandle* , BasScript script-builder handle
index : int32_t , Socket channel number
msgLength : int32_t , receive message length
msgType : int32_t , Socket message type; see ArmBasStrType for values
value : ArmBasValue ; when ARM_BAS_STR_STRING , this is the string variable name; when ARM_BAS_STR_SR , this is an SR number
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Arm_BasScript_Modbus_ReadMH

c
int Arm_BasScript_Modbus_ReadMH(ArmBasScriptHandle* script, int32_t index, int32_t id, int32_t address, int32_t length, int32_t rIndex);
ItemDescription
DescriptionGenerates a Modbus script statement that reads MH.
Request parametersscript : ArmBasScriptHandle* , BasScript script-builder handle
index : int32_t , Modbus statement index
id : int32_t , Modbus slave ID
address : int32_t , MH start address
length : int32_t , read length
rIndex : int32_t , R register number that receives the result
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Arm_BasScript_Modbus_ReadMI

c
int Arm_BasScript_Modbus_ReadMI(ArmBasScriptHandle* script, int32_t index, int32_t id, int32_t address, int32_t length, int32_t rIndex);
ItemDescription
DescriptionGenerates a Modbus script statement that reads MI.
Request parametersscript : ArmBasScriptHandle* , BasScript script-builder handle
index : int32_t , Modbus statement index
id : int32_t , Modbus slave ID
address : int32_t , MI start address
length : int32_t , read length
rIndex : int32_t , R register number that receives the result
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Arm_BasScript_Modbus_WriteMH

c
int Arm_BasScript_Modbus_WriteMH(ArmBasScriptHandle* script, int32_t index, int32_t id, int32_t address, int32_t length, int32_t valueType, int32_t value);
ItemDescription
DescriptionGenerates a Modbus script statement that writes MH.
Request parametersscript : ArmBasScriptHandle* , BasScript script-builder handle
index : int32_t , Modbus statement index
id : int32_t , Modbus slave ID
address : int32_t , MH start address
length : int32_t , write length
valueType : int32_t , write-value source; see ArmBasValueType for values
value : int32_t , direct write value or R register number
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Arm_BasScript_Vision_Find

c
int Arm_BasScript_Vision_Find(ArmBasScriptHandle* script, const char* name);
ItemDescription
DescriptionGenerates a vision find statement.
Request parametersscript : ArmBasScriptHandle* , BasScript script-builder handle
name : const char* , vision task name; must not be NULL
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Arm_BasScript_Vision_GetOffset

c
int Arm_BasScript_Vision_GetOffset(ArmBasScriptHandle* script, const char* name, int32_t index, int32_t labelIndex);
ItemDescription
DescriptionGenerates a vision offset retrieval statement.
Request parametersscript : ArmBasScriptHandle* , BasScript script-builder handle
name : const char* , vision task name; must not be NULL
index : int32_t , vision offset result number
labelIndex : int32_t , label number to jump to when offset retrieval fails
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Arm_BasScript_Vision_GetQuantity

c
int Arm_BasScript_Vision_GetQuantity(ArmBasScriptHandle* script, const char* name, int32_t index);
ItemDescription
DescriptionGenerates a vision quantity retrieval statement.
Request parametersscript : ArmBasScriptHandle* , BasScript script-builder handle
name : const char* , vision task name; must not be NULL
index : int32_t , number that receives the quantity result
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Extra Parameter APIs

Arm_BasExtraParam_Create

c
int Arm_BasExtraParam_Create(ArmBasExtraParamHandle** outExtraParam);
ItemDescription
DescriptionCreates a BAS extra-parameter builder.
Request parametersoutExtraParam : ArmBasExtraParamHandle** , output extra-parameter builder handle; on success, a non-null pointer is written
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Arm_BasExtraParam_Destroy

c
void Arm_BasExtraParam_Destroy(ArmBasExtraParamHandle* extraParam);
ItemDescription
DescriptionDestroys a BAS extra-parameter builder.
Request parametersextraParam : ArmBasExtraParamHandle* , extra-parameter builder to destroy; may be NULL
Return valueNo return value

Arm_BasExtraParam_Reset

c
int Arm_BasExtraParam_Reset(ArmBasExtraParamHandle* extraParam);
ItemDescription
DescriptionResets a BAS extra-parameter builder.
Request parametersextraParam : ArmBasExtraParamHandle* , extra-parameter builder to reset
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Arm_BasExtraParam_GetText

c
int Arm_BasExtraParam_GetText(ArmBasExtraParamHandle* extraParam, char* outBuf, size_t bufSize);
ItemDescription
DescriptionExports the current extra-parameter text.
Request parametersextraParam : ArmBasExtraParamHandle* , extra-parameter builder
outBuf : char* , output string buffer allocated by the caller
bufSize : size_t , output buffer size, including space for the trailing \0
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions
NotesString output uses the caller-provided buffer. If the buffer is too small, the function reports that through the status code.

Arm_BasExtraParam_Acceleration

c
int Arm_BasExtraParam_Acceleration(ArmBasExtraParamHandle* extraParam, double value);
ItemDescription
DescriptionAppends an acceleration extra parameter.
Request parametersextraParam : ArmBasExtraParamHandle* , extra-parameter builder
value : double , extra acceleration; values outside 1~120 are emitted as 100.0
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Arm_BasExtraParam_Rctp

c
int Arm_BasExtraParam_Rctp(ArmBasExtraParamHandle* extraParam);
ItemDescription
DescriptionAppends an RTCP extra parameter.
Request parametersextraParam : ArmBasExtraParamHandle* , extra-parameter builder
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Arm_BasExtraParam_Offset

c
int Arm_BasExtraParam_Offset(ArmBasExtraParamHandle* extraParam, int32_t index);
ItemDescription
DescriptionAppends a coordinate offset extra parameter.
Request parametersextraParam : ArmBasExtraParamHandle* , extra-parameter builder
index : int32_t , PR number used for the offset
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Arm_BasExtraParam_Tb

c
int Arm_BasExtraParam_Tb(ArmBasExtraParamHandle* extraParam, double second, const char* type, const char* name, int32_t index, const char* status);
ItemDescription
DescriptionAppends a TB extra parameter.
Request parametersextraParam : ArmBasExtraParamHandle* , extra-parameter builder
second : double , time parameter in seconds
type : const char* , TB type, for example RUN or ASSIGN
name : const char* , script name used by the RUN type; may be empty depending on the TB type
index : int32_t , index used by the ASSIGN type
status : const char* , status string used by the ASSIGN type
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Arm_BasExtraParam_Skip

c
int Arm_BasExtraParam_Skip(ArmBasExtraParamHandle* extraParam, int32_t index);
ItemDescription
DescriptionAppends a Skip extra parameter.
Request parametersextraParam : ArmBasExtraParamHandle* , extra-parameter builder
index : int32_t , target LABEL number to jump to
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Arm_BasExtraParam_Approach

c
int Arm_BasExtraParam_Approach(ArmBasExtraParamHandle* extraParam, double departureDist, double approachingDist);
ItemDescription
DescriptionAppends Jump approach/departure distance parameters.
Request parametersextraParam : ArmBasExtraParamHandle* , extra-parameter builder
departureDist : double , Jump departure distance
approachingDist : double , Jump approach distance
Return valueInteger STATUS_CODE ; 0 means success, and other values should be handled according to the status-code definitions

Enums and Values

EnumDescription
ArmBasMovePoseTypeMotion point source; exposes ARM_BAS_MOVE_POSE_PR
ArmBasSmoothTypeExact-to-point or distance-based smoothing
ArmBasSpeedTypeSpeed from a direct value or MR
ArmBasRegisterTypeR / SR / MH / MI
ArmBasIOTypeDI / DO / AI / AO / RI / RO / UI / UO / GI / GO / TAI / TAO / TDI / TDO
ArmBasIOStatusON / OFF / PULSE / rising edge / falling edge
ArmBasBooleanOperatorAND / OR / EQ / NE / GT / GE / LT / LE
ArmBasAssignTypeASSIGN left-side target or right-side source
ArmBasOtherTypeLiteral, string, IO status, or current pose
ArmBasCurrentPoseCurrent joint or Cartesian pose
ArmBasLoadTypeProgram identifier source for LOAD / UNLOAD / EXEC
ArmBasStrTypeSocket string or SR
ArmBasValueTypeDirect value or R register
ArmBasParamTypeTF, UF, OVC, OAC, or payload number
ArmBasMathOperatorReserved arithmetic operator enum
ArmBasValueTagIdentifies which field of ArmBasValue is active

Key Semantics

CategoryDescription
Motion speedWhen MoveJoint uses a direct speed value, the range is 0~100 ; when MoveLine or MoveCircle uses a direct speed value, the range is 0~5000 .
Jump pointsposeIndexList for MoveJump3 and MoveJump3cp must contain exactly 3 PR point indexes.
Condition statementsIF, ELSE IF, WHILE, WAIT, and SKIP CONDITION use the same condition-parameter convention, supporting registers, IO, literals, strings, and IO status.
SELECT statementArm_BasScript_Logical_Switch() emits SELECT; Arm_BasScript_Logical_EndSwitch() emits ENDSELECT.
Closing validationIF / SELECT / WHILE blocks must be closed; add the matching end statement before exporting or executing script text.
SocketARM_BAS_STR_STRING uses a string value, and ARM_BAS_STR_SR uses an SR number.
ModbusReadMH / ReadMI write results to an R register; WriteMH can write either a direct value or an R register value.
Extra accelerationThe valid range of Arm_BasExtraParam_Acceleration() is 1~120 ; out-of-range values are emitted as 100.0 .
TB extra parameterTB parameters must satisfy one of two forms: RUN with name , or ASSIGN with index + status .
ApproachArm_BasExtraParam_Approach() is only used as an extra parameter for Jump-style instructions.

Builder Rules

  • Arm_BasScript_Create() creates an empty builder.
  • Arm_BasScript_CreateWithName() creates a builder with a script name and generates the script header.
  • Arm_BasScript_SetName() changes only the name; existing content is preserved.
  • Arm_BasScript_AppendLine() / Arm_BasScript_AppendLines() only append script text.
  • Arm_BasScript_GetText() serializes the current content; use Arm_BasScript_CreateWithName() when a script header is required.
  • Arm_BasScript_Reset() returns the builder to the mode it had at creation time.
  • Arm_BasScript_Execute() executes the script generated by the builder through ArmHandle* .
  • Arm_BasExtraParam_GetText() outputs the current extra-parameter text.

Minimal Example

c
#include <stdio.h>  // Provides printf for printing the generated script text.
#include "c_arm_api.h"  // Includes the aggregate C99 SDK header.
int main(void)  // Example program entry point.
{  // Enters the example main function.
    ArmBasScriptHandle* script = NULL;  // Prepares the script-builder handle.
    char text[2048] = {0};  // Prepares the script-text output buffer.
    int ret = Arm_BasScript_CreateWithName("demo.bas", &script);  // Creates a named script builder.
    if (ret != 0 || script == NULL) {  // Checks whether builder creation failed.
        return 1;  // Exits when creation fails.
    }  // Ends the creation check.
    Arm_BasScript_Structure_WaitTime(script, ARM_BAS_VALUE_TYPE_VALUE, Arm_BasValue_Float64(0.1));  // Appends a wait statement.
    Arm_BasScript_GetText(script, text, sizeof(text));  // Exports the script text.
    printf("%s\n", text);  // Prints the script text.
    Arm_BasScript_Destroy(script);  // Destroys the script builder.
    return 0;  // Ends the example successfully.
}  // Ends the example main function.

Scenario Examples

Motion Statements and Extra Parameters

c
ArmBasScriptHandle* script = NULL;  // Prepares the script builder.
ArmBasExtraParamHandle* extra = NULL;  // Prepares the extra-parameter builder.
int createRet = Arm_BasScript_Create(&script);  // Creates the script builder.
int extraRet = Arm_BasExtraParam_Create(&extra);  // Creates the extra-parameter builder.
Arm_BasExtraParam_Acceleration(extra, 80.0);  // Sets extra acceleration.
Arm_BasExtraParam_Rctp(extra);  // Sets the RTCP extra parameter.
Arm_BasExtraParam_Offset(extra, 1);  // Sets FRAME_OFFSET PR[1].
Arm_BasExtraParam_Skip(extra, 10);  // Sets SKIP GOTO LABEL10.
Arm_BasExtraParam_Approach(extra, 20.0, 10.0);  // Sets Jump approach/departure distance.
Arm_BasScript_Motion_MoveJoint(script, ARM_BAS_MOVE_POSE_PR, 1, ARM_BAS_SPEED_VALUE, 30.0, ARM_BAS_SMOOTH_FINE, 0.0, extra);  // Generates a joint-motion statement.
Arm_BasScript_Motion_MoveLine(script, ARM_BAS_MOVE_POSE_PR, 2, ARM_BAS_SPEED_VALUE, 30.0, ARM_BAS_SMOOTH_DISTANCE, 5.0, extra);  // Generates a linear-motion statement.
Arm_BasScript_Motion_MoveCircle(script, ARM_BAS_MOVE_POSE_PR, 2, ARM_BAS_MOVE_POSE_PR, 3, ARM_BAS_SPEED_VALUE, 20.0, ARM_BAS_SMOOTH_FINE, 0.0, extra);  // Generates an arc-motion statement.
Arm_BasScript_Motion_MoveJump(script, ARM_BAS_MOVE_POSE_PR, 4, 40.0, 80.0, ARM_BAS_VALUE_TYPE_VALUE, 100.0, ARM_BAS_SMOOTH_FINE, 0.0, extra);  // Generates a Jump statement.
(void)createRet;  // Keeps the creation status code in this example.
(void)extraRet;  // Keeps the extra-parameter creation status code in this example.
Arm_BasExtraParam_Destroy(extra);  // Destroys the extra-parameter builder.
Arm_BasScript_Destroy(script);  // Destroys the script builder.

Logic, Flow, Socket, Modbus, and Vision

c
ArmBasScriptHandle* script = NULL;  // Prepares the script builder.
Arm_BasScript_Create(&script);  // Creates the script builder.
Arm_BasScript_SetParam(script, ARM_BAS_PARAM_OVC, ARM_BAS_VALUE_TYPE_VALUE, Arm_BasValue_Float64(20.0));  // Sets OVC.
Arm_BasScript_AssignValue(script, ARM_BAS_ASSIGN_R, 1, Arm_BasValue_TaggedInt(ARM_BAS_VALUE_TAG_OTHER_TYPE, ARM_BAS_OTHER_VALUE), Arm_BasValue_Float64(1.0), 0, 0);  // Generates an assignment statement.
Arm_BasScript_Logical_If(script, Arm_BasValue_TaggedInt(ARM_BAS_VALUE_TAG_REGISTER_TYPE, ARM_BAS_REGISTER_R), 1, Arm_BasValue_TaggedInt(ARM_BAS_VALUE_TAG_OTHER_TYPE, ARM_BAS_OTHER_VALUE), Arm_BasValue_Float64(1.0), ARM_BAS_BOOLEAN_EQ);  // Generates IF.
Arm_BasScript_Logical_Else(script);  // Generates ELSE.
Arm_BasScript_Logical_EndIf(script);  // Generates ENDIF.
Arm_BasScript_Logical_Switch(script, Arm_BasValue_TaggedInt(ARM_BAS_VALUE_TAG_REGISTER_TYPE, ARM_BAS_REGISTER_R), 1);  // Generates SWITCH.
Arm_BasScript_Logical_Case(script, Arm_BasValue_TaggedInt(ARM_BAS_VALUE_TAG_OTHER_TYPE, ARM_BAS_OTHER_VALUE), Arm_BasValue_Int32(1));  // Generates CASE.
Arm_BasScript_Logical_Default(script);  // Generates DEFAULT.
Arm_BasScript_Logical_EndSwitch(script);  // Generates ENDSWITCH.
Arm_BasScript_Logical_While(script, Arm_BasValue_TaggedInt(ARM_BAS_VALUE_TAG_REGISTER_TYPE, ARM_BAS_REGISTER_R), 1, Arm_BasValue_TaggedInt(ARM_BAS_VALUE_TAG_OTHER_TYPE, ARM_BAS_OTHER_VALUE), Arm_BasValue_Float64(0.0), ARM_BAS_BOOLEAN_GT);  // Generates WHILE.
Arm_BasScript_Logical_Break(script);  // Generates BREAK.
Arm_BasScript_Logical_Continue(script);  // Generates CONTINUE.
Arm_BasScript_Logical_EndWhile(script);  // Generates ENDWHILE.
Arm_BasScript_Logical_Label(script, 10);  // Generates LABEL.
Arm_BasScript_Logical_Goto(script, 10);  // Generates GOTO.
Arm_BasScript_Logical_SkipCondition(script, Arm_BasValue_TaggedInt(ARM_BAS_VALUE_TAG_IO_TYPE, ARM_BAS_IO_DI), 1, Arm_BasValue_TaggedInt(ARM_BAS_VALUE_TAG_OTHER_TYPE, ARM_BAS_OTHER_IO_STATUS), Arm_BasValue_TaggedInt(ARM_BAS_VALUE_TAG_IO_STATUS, ARM_BAS_IO_STATUS_ON), ARM_BAS_BOOLEAN_EQ);  // Generates a SKIP condition.
Arm_BasScript_Structure_Wait(script, Arm_BasValue_TaggedInt(ARM_BAS_VALUE_TAG_IO_TYPE, ARM_BAS_IO_DI), 1, Arm_BasValue_TaggedInt(ARM_BAS_VALUE_TAG_OTHER_TYPE, ARM_BAS_OTHER_IO_STATUS), Arm_BasValue_TaggedInt(ARM_BAS_VALUE_TAG_IO_STATUS, ARM_BAS_IO_STATUS_ON), ARM_BAS_BOOLEAN_EQ);  // Generates a WAIT condition.
Arm_BasScript_Structure_Pause(script);  // Generates a pause statement.
Arm_BasScript_Structure_Call(script, "sub.bas");  // Generates CALL.
Arm_BasScript_Structure_Run(script, "sub.bas");  // Generates RUN.
Arm_BasScript_Structure_Load(script, ARM_BAS_LOAD_STRING, Arm_BasValue_String("sub.bas"));  // Generates LOAD.
Arm_BasScript_Structure_Unload(script, ARM_BAS_LOAD_STRING, Arm_BasValue_String("sub.bas"));  // Generates UNLOAD.
Arm_BasScript_Structure_Exec(script, ARM_BAS_LOAD_STRING, Arm_BasValue_String("sub.bas"));  // Generates EXEC.
Arm_BasScript_Socket_Open(script, 1);  // Generates Socket Open.
Arm_BasScript_Socket_Connect(script, 1);  // Generates Socket Connect.
Arm_BasScript_Socket_Send(script, 1, ARM_BAS_STR_STRING, Arm_BasValue_String("ping"));  // Generates Socket Send.
Arm_BasScript_Socket_Recv(script, 1, 128, ARM_BAS_STR_SR, Arm_BasValue_Int32(1));  // Generates Socket Recv.
Arm_BasScript_Socket_Close(script, 1);  // Generates Socket Close.
Arm_BasScript_Modbus_ReadMH(script, 1, 1, 0, 2, 1);  // Generates MH read.
Arm_BasScript_Modbus_ReadMI(script, 1, 1, 0, 2, 1);  // Generates MI read.
Arm_BasScript_Modbus_WriteMH(script, 1, 1, 0, 1, ARM_BAS_VALUE_TYPE_VALUE, 7);  // Generates MH write.
Arm_BasScript_Vision_Find(script, "camera");  // Generates vision find.
Arm_BasScript_Vision_GetOffset(script, "camera", 1, 10);  // Generates vision offset.
Arm_BasScript_Vision_GetQuantity(script, "camera", 1);  // Generates vision quantity.
Arm_BasScript_Structure_Abort(script);  // Generates an abort statement.
Arm_BasScript_Destroy(script);  // Destroys the script builder.

Sample code

c99/bas_script_execution/src/main.cpp
cpp
#include <stdio.h>

#include "c_arm_api.h"

int main(void)
{
    // [ZH] 本示例直接在源码中写死连接地址,不解析命令行参数。
    // [EN] This example hard-codes the connection addresses in the source code.
    const char* controller_ip = "10.27.1.2";
    const char* teach_panel_ip = "10.27.1.102";
    const int execute_generated_script = 0;
    int overall_status = 0;

#define RECORD_STATUS(label, expr) \
    do { \
        int status = (expr); \
        printf("[c99_bas_script] %s status: %d\n", (label), status); \
        if (status != 0) { \
            overall_status = status; \
        } \
    } while (0)

    // [ZH] 创建并连接 SDK 句柄。构造脚本文本本身不需要连接,执行脚本才需要连接。
    // [EN] Create and connect the SDK handle. Building text does not need a connection; executing does.
    ArmHandle* handle = Arm_Create();
    if (handle == NULL) {
        printf("[c99_bas_script] 创建句柄失败 / Create handle failed\n");
        return 1;
    }

    int connect_ret = Arm_Connect(handle, controller_ip, teach_panel_ip);
    if (connect_ret != 0) {
        printf("[c99_bas_script] 连接机器人失败 / Connect failed: %d\n", connect_ret);
        Arm_Destroy(handle);
        return 1;
    }
    printf("[c99_bas_script] 机器人连接成功 / Robot connected successfully\n");

    // [ZH] 覆盖空构造器、命名、追加原始文本、行数、导出文本和 Reset。
    // [EN] Cover empty creation, naming, raw append, line count, text export, and reset.
    ArmBasScriptHandle* scratch_script = NULL;
    RECORD_STATUS("Create", Arm_BasScript_Create(&scratch_script));
    RECORD_STATUS("SetName", Arm_BasScript_SetName(scratch_script, "scratch.bas"));
    RECORD_STATUS("AppendLine", Arm_BasScript_AppendLine(scratch_script, "WAIT TIME 0.1"));
    const char* raw_lines[2] = {"R[1]=1", "R[2]=2"};
    RECORD_STATUS("AppendLines", Arm_BasScript_AppendLines(scratch_script, raw_lines, 2U));
    size_t scratch_line_count = 0U;
    RECORD_STATUS("GetLineCount", Arm_BasScript_GetLineCount(scratch_script, &scratch_line_count));
    char scratch_text[2048] = {0};
    RECORD_STATUS("GetText(scratch)", Arm_BasScript_GetText(scratch_script, scratch_text, sizeof(scratch_text)));
    RECORD_STATUS("Reset", Arm_BasScript_Reset(scratch_script));
    printf("[c99_bas_script] scratch line count: %zu\n", scratch_line_count);
    printf("[c99_bas_script] scratch text:\n%s\n", scratch_text);
    Arm_BasScript_Destroy(scratch_script);

    // [ZH] 创建主脚本和附加参数构造器。
    // [EN] Create the main script and extra-parameter builder.
    ArmBasScriptHandle* script = NULL;
    ArmBasExtraParamHandle* extra = NULL;
    RECORD_STATUS("CreateWithName", Arm_BasScript_CreateWithName("example_c99.bas", &script));
    RECORD_STATUS("ExtraParam_Create", Arm_BasExtraParam_Create(&extra));
    RECORD_STATUS("ExtraParam_Acceleration", Arm_BasExtraParam_Acceleration(extra, 80.0));
    RECORD_STATUS("ExtraParam_Rctp", Arm_BasExtraParam_Rctp(extra));
    RECORD_STATUS("ExtraParam_Offset", Arm_BasExtraParam_Offset(extra, 1));
    RECORD_STATUS("ExtraParam_Tb", Arm_BasExtraParam_Tb(extra, 0.1, "RUN", "helper.bas", 0, ""));
    RECORD_STATUS("ExtraParam_Skip", Arm_BasExtraParam_Skip(extra, 10));
    RECORD_STATUS("ExtraParam_Approach", Arm_BasExtraParam_Approach(extra, 10.0, 5.0));
    char extra_text[1024] = {0};
    RECORD_STATUS("ExtraParam_GetText", Arm_BasExtraParam_GetText(extra, extra_text, sizeof(extra_text)));
    printf("[c99_bas_script] extra text: %s\n", extra_text);

    // [ZH] 覆盖基础参数与赋值接口。
    // [EN] Cover parameter and assignment APIs.
    RECORD_STATUS(
        "SetParam",
        Arm_BasScript_SetParam(
            script,
            ARM_BAS_PARAM_OVC,
            ARM_BAS_VALUE_TYPE_VALUE,
            Arm_BasValue_Float64(20.0)
        )
    );
    RECORD_STATUS(
        "AssignValue(value)",
        Arm_BasScript_AssignValue(
            script,
            ARM_BAS_ASSIGN_R,
            1,
            Arm_BasValue_TaggedInt(ARM_BAS_VALUE_TAG_OTHER_TYPE, ARM_BAS_OTHER_VALUE),
            Arm_BasValue_Float64(3.14),
            0,
            0
        )
    );
    RECORD_STATUS(
        "AssignValue(string)",
        Arm_BasScript_AssignValue(
            script,
            ARM_BAS_ASSIGN_SR,
            1,
            Arm_BasValue_TaggedInt(ARM_BAS_VALUE_TAG_OTHER_TYPE, ARM_BAS_OTHER_STRING),
            Arm_BasValue_String("hello"),
            0,
            0
        )
    );

    // [ZH] 覆盖运动语句构造接口。
    // [EN] Cover motion-statement construction APIs.
    int32_t jump_points[3] = {1, 2, 3};
    RECORD_STATUS(
        "Motion_MoveJoint",
        Arm_BasScript_Motion_MoveJoint(
            script, ARM_BAS_MOVE_POSE_PR, 1, ARM_BAS_SPEED_VALUE, 20.0,
            ARM_BAS_SMOOTH_FINE, 0.0, extra
        )
    );
    RECORD_STATUS(
        "Motion_MoveLine",
        Arm_BasScript_Motion_MoveLine(
            script, ARM_BAS_MOVE_POSE_PR, 2, ARM_BAS_SPEED_VALUE, 100.0,
            ARM_BAS_SMOOTH_DISTANCE, 5.0, extra
        )
    );
    RECORD_STATUS(
        "Motion_MoveCircle",
        Arm_BasScript_Motion_MoveCircle(
            script, ARM_BAS_MOVE_POSE_PR, 2, ARM_BAS_MOVE_POSE_PR, 3,
            ARM_BAS_SPEED_VALUE, 100.0, ARM_BAS_SMOOTH_FINE, 0.0, extra
        )
    );
    RECORD_STATUS(
        "Motion_MoveJump",
        Arm_BasScript_Motion_MoveJump(
            script, ARM_BAS_MOVE_POSE_PR, 4, 100.0, 50.0,
            ARM_BAS_SPEED_VALUE, 20.0, ARM_BAS_SMOOTH_FINE, 0.0, extra
        )
    );
    RECORD_STATUS(
        "Motion_MoveJump3",
        Arm_BasScript_Motion_MoveJump3(
            script, ARM_BAS_MOVE_POSE_PR, jump_points, 3U, 100.0, 50.0,
            ARM_BAS_SMOOTH_FINE, 0.0, extra
        )
    );
    RECORD_STATUS(
        "Motion_MoveJump3cp",
        Arm_BasScript_Motion_MoveJump3cp(
            script, ARM_BAS_MOVE_POSE_PR, jump_points, 3U, 100.0,
            ARM_BAS_SMOOTH_FINE, 0.0, extra
        )
    );

    // [ZH] 覆盖逻辑语句构造接口。
    // [EN] Cover logical-statement construction APIs.
    ArmBasValue reg_r = Arm_BasValue_TaggedInt(ARM_BAS_VALUE_TAG_REGISTER_TYPE, ARM_BAS_REGISTER_R);
    ArmBasValue io_di = Arm_BasValue_TaggedInt(ARM_BAS_VALUE_TAG_IO_TYPE, ARM_BAS_IO_DI);
    ArmBasValue other_value = Arm_BasValue_TaggedInt(ARM_BAS_VALUE_TAG_OTHER_TYPE, ARM_BAS_OTHER_VALUE);
    ArmBasValue other_status = Arm_BasValue_TaggedInt(ARM_BAS_VALUE_TAG_OTHER_TYPE, ARM_BAS_OTHER_IO_STATUS);
    ArmBasValue status_on = Arm_BasValue_TaggedInt(ARM_BAS_VALUE_TAG_IO_STATUS, ARM_BAS_IO_STATUS_ON);
    RECORD_STATUS("Logical_If", Arm_BasScript_Logical_If(script, reg_r, 1, other_value, Arm_BasValue_Int32(1), ARM_BAS_BOOLEAN_EQ));
    RECORD_STATUS("Logical_ElseIf", Arm_BasScript_Logical_ElseIf(script, reg_r, 1, other_value, Arm_BasValue_Int32(2), ARM_BAS_BOOLEAN_EQ));
    RECORD_STATUS("Logical_Else", Arm_BasScript_Logical_Else(script));
    RECORD_STATUS("Logical_EndIf", Arm_BasScript_Logical_EndIf(script));
    RECORD_STATUS("Logical_Switch", Arm_BasScript_Logical_Switch(script, reg_r, 1));
    RECORD_STATUS("Logical_Case", Arm_BasScript_Logical_Case(script, other_value, Arm_BasValue_Int32(1)));
    RECORD_STATUS("Logical_Default", Arm_BasScript_Logical_Default(script));
    RECORD_STATUS("Logical_EndSwitch", Arm_BasScript_Logical_EndSwitch(script));
    RECORD_STATUS("Logical_While", Arm_BasScript_Logical_While(script, reg_r, 1, other_value, Arm_BasValue_Int32(3), ARM_BAS_BOOLEAN_LT));
    RECORD_STATUS("Logical_Continue", Arm_BasScript_Logical_Continue(script));
    RECORD_STATUS("Logical_Break", Arm_BasScript_Logical_Break(script));
    RECORD_STATUS("Logical_EndWhile", Arm_BasScript_Logical_EndWhile(script));
    RECORD_STATUS("Logical_Label", Arm_BasScript_Logical_Label(script, 10));
    RECORD_STATUS("Logical_Goto", Arm_BasScript_Logical_Goto(script, 10));
    RECORD_STATUS("Logical_SkipCondition", Arm_BasScript_Logical_SkipCondition(script, io_di, 1, other_status, status_on, ARM_BAS_BOOLEAN_EQ));

    // [ZH] 覆盖流程控制语句构造接口。
    // [EN] Cover structural-control statement construction APIs.
    RECORD_STATUS("Structure_Wait", Arm_BasScript_Structure_Wait(script, io_di, 1, other_status, status_on, ARM_BAS_BOOLEAN_EQ));
    RECORD_STATUS("Structure_WaitTime", Arm_BasScript_Structure_WaitTime(script, ARM_BAS_VALUE_TYPE_VALUE, Arm_BasValue_Float64(0.1)));
    RECORD_STATUS("Structure_Pause", Arm_BasScript_Structure_Pause(script));
    RECORD_STATUS("Structure_Abort", Arm_BasScript_Structure_Abort(script));
    RECORD_STATUS("Structure_Call", Arm_BasScript_Structure_Call(script, "helper.bas"));
    RECORD_STATUS("Structure_Run", Arm_BasScript_Structure_Run(script, "helper.bas"));
    RECORD_STATUS("Structure_Load", Arm_BasScript_Structure_Load(script, ARM_BAS_LOAD_STRING, Arm_BasValue_String("demo_program")));
    RECORD_STATUS("Structure_Unload", Arm_BasScript_Structure_Unload(script, ARM_BAS_LOAD_STRING, Arm_BasValue_String("demo_program")));
    RECORD_STATUS("Structure_Exec", Arm_BasScript_Structure_Exec(script, ARM_BAS_LOAD_STRING, Arm_BasValue_String("demo_program")));

    // [ZH] 覆盖 Socket、Modbus 和视觉语句构造接口。
    // [EN] Cover Socket, Modbus, and vision statement construction APIs.
    RECORD_STATUS("Socket_Open", Arm_BasScript_Socket_Open(script, 1));
    RECORD_STATUS("Socket_Connect", Arm_BasScript_Socket_Connect(script, 1));
    RECORD_STATUS("Socket_Send", Arm_BasScript_Socket_Send(script, 1, ARM_BAS_STR_STRING, Arm_BasValue_String("ping")));
    RECORD_STATUS("Socket_Recv", Arm_BasScript_Socket_Recv(script, 1, 32, ARM_BAS_STR_SR, Arm_BasValue_Int32(1)));
    RECORD_STATUS("Socket_Close", Arm_BasScript_Socket_Close(script, 1));
    RECORD_STATUS("Modbus_ReadMH", Arm_BasScript_Modbus_ReadMH(script, 1, 1, 0, 2, 1));
    RECORD_STATUS("Modbus_ReadMI", Arm_BasScript_Modbus_ReadMI(script, 1, 1, 0, 2, 2));
    RECORD_STATUS("Modbus_WriteMH", Arm_BasScript_Modbus_WriteMH(script, 1, 1, 0, 1, ARM_BAS_VALUE_TYPE_VALUE, 10));
    RECORD_STATUS("Vision_Find", Arm_BasScript_Vision_Find(script, "camera"));
    RECORD_STATUS("Vision_GetOffset", Arm_BasScript_Vision_GetOffset(script, "camera", 1, 10));
    RECORD_STATUS("Vision_GetQuantity", Arm_BasScript_Vision_GetQuantity(script, "camera", 2));

    // [ZH] 导出最终脚本文本。默认不执行,避免示例运行时直接下发复杂脚本。
    // [EN] Export the final script text. Execution is disabled by default to avoid sending a complex script.
    char script_name[128] = {0};
    char script_text[8192] = {0};
    RECORD_STATUS("GetName", Arm_BasScript_GetName(script, script_name, sizeof(script_name)));
    RECORD_STATUS("GetText(final)", Arm_BasScript_GetText(script, script_text, sizeof(script_text)));
    printf("[c99_bas_script] script name: %s\n", script_name);
    printf("[c99_bas_script] script text:\n%s\n", script_text);
    if (execute_generated_script != 0) {
        RECORD_STATUS("Execute", Arm_BasScript_Execute(handle, script));
    } else {
        printf("[c99_bas_script] Execute skipped by default / 默认跳过 Execute\n");
    }

    RECORD_STATUS("ExtraParam_Reset", Arm_BasExtraParam_Reset(extra));
    Arm_BasExtraParam_Destroy(extra);
    Arm_BasScript_Destroy(script);
    Arm_Disconnect(handle);
    Arm_Destroy(handle);
    printf("[c99_bas_script] 示例结束 / Example finished\n");
#undef RECORD_STATUS
    return overall_status == 0 ? 0 : 1;
}