Skip to content

4.10 BasScript Script Program Class

Overview

BasScript is used to construct BAS instruction sequences on the host side in a structured way, including motion, logic, program control, communication, vision, and Modbus instructions.

Core Features

  • Build motion instructions ( MoveJoint , MoveLine , MoveCircle , etc.)
  • Build logic instructions ( IF , WHILE , SWITCH , GOTO , etc.)
  • Build assignment, wait, pause, and abort instructions
  • Build program call and management instructions
  • Build Socket communication instructions
  • Build Modbus register read/write instructions
  • Build vision instructions
  • Configure extra parameters (acceleration, RTCP, frame offset, etc.)
  • Support high-level jump instructions ( JUMP series)

Use Cases

  • Automatically generate complex robot programs
  • Edit and modify robot programs
  • Reuse common program modules and instruction sequences
  • Implement seamless integration between host and robot programs
  • Build customized robot motion trajectories
  • Integrate vision, communication, and Modbus functionality into robot programs

Class Constructor

Method NameBasScript(string name )
DescriptionConstructs a BAS instruction sequence class for use in robots
Request Parametersname : string Script program name
Compatible robot software versionCollaborative (Copper): v7.5.2.0+
Industrial (Bronze): Not supported
NoteAll methods in this class have the same compatible version requirements as this class

Subclass Structure

The BasScript class contains the following subclasses for organizing different instruction categories:

  1. ExtraParam: Extra parameter class for building complex robot control commands
  2. BasMotion: Motion instruction subclass, contains all robot motion-related methods
  3. BasLogical: Logical instruction subclass, contains all logic control-related methods
  4. BasStructure: Structural instruction subclass, contains all structure control-related methods
  5. BasSocket: Socket communication subclass, contains all Socket communication-related methods
  6. BasModbus: Modbus communication subclass, contains all Modbus communication-related methods
  7. BasVision: Vision instruction subclass, contains all vision-related methods

4.10.1 ExtraParam Class

Method NameExtraParam()
DescriptionExtra parameter class for building complex robot control commands
Request ParametersNone
Return ValueExtraParam object

4.10.1.1 Set Acceleration

Method NameExtraParam.Acceleration(double value )
DescriptionSets acceleration, range is 1~120%
Request Parametersvalue : double Acceleration value, unit: % (floating point)
Return ValueStatusCode: Parameter setting execution result

4.10.1.2 Set RTCP Parameter

Method NameExtraParam.RTCP()
DescriptionSets RTCP parameter, only supports MoveL and MoveC instructions
Request ParametersNone
Return ValueStatusCode: Parameter setting execution result

4.10.1.3 Set Frame Offset

Method NameExtraParam.Offset(int index )
DescriptionSets frame offset
Request Parametersindex : int Offset index (integer)
Return ValueStatusCode: Parameter setting execution result

4.10.1.4 Set Time-Base Run/Assign

Method NameExtraParam.TB(double second , string type , string name )
DescriptionSets time-base run or assign, range is 0.01-30s, values less than 0.01 will not save successfully
Request Parameterssecond : double Seconds, unit: sec (floating point)
type : string Execution type (string)
name : string Name (for running, string)
Return ValueStatusCode: Parameter setting execution result
Method NameExtraParam.TB(double second , string type , int index , int status )
DescriptionSets time-base run or assign, range is 0.01-30s, values less than 0.01 will not save successfully
Request Parameterssecond : double Seconds, unit: sec (floating point)
type : string IO type (string)
index : int Index (for assignment, integer)
status : int Status (for assignment, integer)
Return ValueStatusCode: Parameter setting execution result

4.10.1.5 Set Skip

Method NameExtraParam.SKIP(int index )
DescriptionSets jump, when the jump condition set by SKIP CONDITION instruction is met, directly jumps from the current line containing SKIP instruction to the target instruction line or target program
Request Parametersindex : int Index of the target label (integer)
Return ValueStatusCode: Parameter setting execution result

4.10.1.6 Set Departure and Approach Distance

Method NameExtraParam.Approach(double departureDist , double approachingDist )
DescriptionSets departure and approach distance for gate-type motion, only used for JUMP instruction
Request ParametersdepartureDist : double Departure distance, unit: mm (floating point)
approachingDist : double Approach distance, unit: mm (floating point)
Return ValueStatusCode: Parameter setting execution result

4.10.2 BasMotion Motion Instruction Subclass

BasMotion subclass contains all robot motion-related methods, used for building motion instruction sequences.

4.10.2.1 MoveJoint Motion to Point Instruction

Method NameBasScript.BasMotion.MoveJoint(MovePoseType poseType , int poseIndex , SpeedType speedType , double speedValue , SmoothType smoothType , double smoothDistance = 0, ExtraParam extraParam = null)
DescriptionJoint motion instruction, moves the robot to a specified position in the workspace with specified movement speed and method, corresponds to MoveJoint instruction in robot program writing
Request ParametersposeType : MovePoseType Pose type
poseIndex : int Pose index
speedType : SpeedType Speed type
speedValue : double Speed value, unit: %
smoothType : SmoothType Smooth type
smoothDistance : double Smooth distance, unit: mm, value range: 0~1000
extraParam : ExtraParam Additional parameter
Return ValueStatusCode: Motion instruction execution result

4.10.2.2 MoveLine Linear Motion to Point Instruction

Method NameBasScript.BasMotion.MoveLine(MovePoseType poseType , int poseIndex , SpeedType speedType , double speedValue , SmoothType smoothType , double smoothDistance = 0, ExtraParam extraParam = null)
DescriptionLinear motion instruction, moves the robot linearly to a specified position in the workspace with specified movement speed and method, corresponds to MoveLine instruction in robot program writing
Request ParametersposeType : MovePoseType Pose type
poseIndex : int Pose index
speedType : SpeedType Speed type
speedValue : double Speed value, unit: mm/s
smoothType : SmoothType Smooth type
smoothDistance : double Smooth distance, unit: mm, value range: 0~1000
extraParam : ExtraParam Additional parameter
Return ValueStatusCode: Motion instruction execution result

4.10.2.3 MoveCircle Arc Motion to Point Instruction

Method NameBasScript.BasMotion.MoveCircle(MovePoseType poseType1 , int poseIndex1 , MovePoseType poseType2 , int poseIndex2 , SpeedType speedType , double speedValue , SmoothType smoothType , double smoothDistance = 0, ExtraParam extraParam = null)
DescriptionArc motion instruction, moves the robot in an arc to a specified position in the workspace with specified movement speed and method, corresponds to MoveCircle instruction in robot program writing
Request ParametersposeType1 : MovePoseType First pose type
poseIndex1 : int First pose index
poseType2 : MovePoseType Second pose type
poseIndex2 : int Second pose index
speedType : SpeedType Speed type
speedValue : double Speed value, unit: mm/s
smoothType : SmoothType Smooth type
smoothDistance : double Smooth distance, unit: mm, value range: 0~1000
extraParam : ExtraParam Additional parameter
Return ValueStatusCode: Motion instruction execution result

4.10.2.4 Jump Point-to-Point Motion Instruction

Method NameBasScript.BasMotion.Jump(MovePoseType poseType , int poseIndex , double speedValue , double speedRatio , SpeedType limZType , double limZValue , SmoothType smoothType , double smoothDistance = 0, ExtraParam extraParam = null)
DescriptionGate-type motion instruction, specifies the robot to perform gate-type motion (first vertically up, then horizontally move, finally vertically down), corresponds to JUMP instruction in robot program writing
Request ParametersposeType : MovePoseType Target pose storage type
poseIndex : int Target position index
speedValue : double Motion speed value, unit: mm/s
speedRatio : double Motion speed ratio, unit: %
limZType : SpeedType Z-axis limit type
limZValue : double Z-axis limit value
smoothType : SmoothType Smooth type
smoothDistance : double Smooth distance, unit: mm, value range: 0~1000
extraParam : ExtraParam Extra parameter
Return ValueStatusCode: Motion instruction execution result

4.10.2.5 Jump3 Three-Point Jump Instruction

Method NameBasScript.BasMotion.Jump3(MovePoseType poseType , int poseIndex , double speedValue , double speedRatio , SmoothType smoothType , double smoothDistance = 0, ExtraParam extraParam = null)
DescriptionGate-type motion instruction, specifies the robot to perform gate-type motion, including departure, approach, and target positions, corresponds to JUMP3 instruction in robot program writing
Request ParametersposeType : MovePoseType Target pose storage type
poseIndex : int 3 target position indices
speedValue : double Motion speed value, unit: mm/s
speedRatio : double Motion speed ratio, unit: %
smoothType : SmoothType Smooth type
smoothDistance : double Smooth distance, unit: mm, value range: 0~1000
extraParam : ExtraParam Extra parameter
Return ValueStatusCode: Motion instruction execution result

4.10.2.6 Jump3CP Three-Point Jump CP Instruction

Method NameBasScript.BasMotion.Jump3CP(MovePoseType poseType , int poseIndex , double speedValue , SmoothType smoothType , double smoothDistance = 0, ExtraParam extraParam = null)
DescriptionGate-type motion instruction, specifies the robot to perform gate-type motion, including departure, approach, and target positions, corresponds to JUMP3CP instruction in robot program writing
Request ParametersposeType : MovePoseType Target pose storage type
poseIndex : int 3 target position indices
speedValue : double Motion speed value, unit: mm/s
smoothType : SmoothType Smooth type
smoothDistance : double Smooth distance, unit: mm, value range: 0~1000
extraParam : ExtraParam Extra parameter
Return ValueStatusCode: Motion instruction execution result

4.10.3 BasLogical Logical Instruction Subclass

BasLogical subclass contains all logic control-related methods, used for building logic control instruction sequences.

4.10.3.1 IF Conditional Instruction

Method NameBasScript.BasLogical.IF(param1, index, param2, value, operatorType)
DescriptionAdds a logical IF statement to the script
Request Parametersparam1 : First parameter, type RegisterType or IOType
index : Index (integer)
param2 : Second parameter, type RegisterType, IOType, or OtherType
value : Value, type index, number, string, or IOStatus
operatorType : Boolean operator, default is equal
Return ValueStatusCode: Operation execution result

4.10.3.2 ELSE_IF Conditional Branch Instruction

Method NameBasScript.BasLogical.ELSE_IF(param1, index, param2, value, operatorType)
DescriptionAdds a logical ELSE IF statement to the script
Request Parametersparam1 : First parameter, type RegisterType or IOType
index : Index (integer)
param2 : Second parameter, type RegisterType, IOType, or OtherType
value : Value, type index, number, string, or IOStatus
operatorType : Boolean operator, default is equal
Return ValueStatusCode: Operation execution result

4.10.3.3 ELSE Instruction

Method NameBasScript.BasLogical.ELSE()
DescriptionAdds a logical ELSE statement to the script
Request ParametersNone
Return ValueStatusCode: Operation execution result

4.10.3.4 END_IF End Conditional Instruction

Method NameBasScript.BasLogical.END_IF()
DescriptionEnds the logical IF statement
Request ParametersNone
Return ValueStatusCode: Operation execution result

4.10.3.5 WHILE Loop Instruction

Method NameBasScript.BasLogical.WHILE(param1, index, param2, value, operatorType)
DescriptionAdds a logical WHILE statement to the script
Request Parametersparam1 : First parameter, type RegisterType or IOType
index : Index (integer)
param2 : Second parameter, type RegisterType, IOType, or OtherType
value : Value, type index, number, string, or IOStatus
operatorType : Boolean operator, default is equal
Return ValueStatusCode: Operation execution result

4.10.3.6 END_WHILE End Loop Instruction

Method NameBasScript.BasLogical.END_WHILE()
DescriptionEnds the logical While statement
Request ParametersNone
Return ValueStatusCode: Operation execution result

4.10.3.7 SWITCH Multi-Branch Selection Instruction

Method NameBasScript.BasLogical.SWITCH(param, index)
DescriptionAdds a logical SWITCH statement to the script
Request Parametersparam : Parameter, type RegisterType or IOType
index : Index of the parameter
Return ValueStatusCode: Operation execution result

4.10.3.8 CASE Branch Instruction

Method NameBasScript.BasLogical.CASE(param, value)
DescriptionAdds a logical CASE statement to the script
Request Parametersparam : Parameter, type RegisterType, IOType, or OtherType
value : Value, type index, number, string
Return ValueStatusCode: Operation execution result

4.10.3.9 DEFAULT Branch Instruction

Method NameBasScript.BasLogical.DEFAULT()
DescriptionAdds a logical DEFAULT statement to the script
Request ParametersNone
Return ValueStatusCode: Operation execution result

4.10.3.10 END_SWITCH End Multi-Branch Selection Instruction

Method NameBasScript.BasLogical.END_SWITCH()
DescriptionEnds the logical SWITCH statement
Request ParametersNone
Return ValueStatusCode: Operation execution result

4.10.3.11 SKIP_CONDITION Skip Condition Instruction

Method NameBasScript.BasLogical.SKIP_CONDITION(param1, index, param2, value, operatorType)
DescriptionAdds a logical SKIP CONDITION statement to the script
Request Parametersparam1 : First parameter, type RegisterType or IOType
index : Index of parameter 1
param2 : Second parameter, type RegisterType, IOType, or OtherType
value : Value, type index, number, string, or IOStatus
operatorType : Boolean operator, default is equal
Return ValueStatusCode: Operation execution result

4.10.3.12 GOTO Jump Instruction

Method NameBasScript.BasLogical.GOTO(index)
DescriptionGOTO jump statement
Request Parametersindex : Index of the target label
Return ValueStatusCode: Operation execution result

4.10.3.13 LABEL Instruction

Method NameBasScript.BasLogical.LABEL(index)
DescriptionLABEL statement
Request Parametersindex : Index of the label
Return ValueStatusCode: Operation execution result

4.10.3.14 BREAK Break Out of Loop Instruction

Method NameBasScript.BasLogical.BREAK()
DescriptionBREAK statement
Request ParametersNone
Return ValueStatusCode: Operation execution result

4.10.3.15 CONTINUE Skip Loop Instruction

Method NameBasScript.BasLogical.CONTINUE()
DescriptionCONTINUE statement
Request ParametersNone
Return ValueStatusCode: Operation execution result

4.10.4 BasStructure Structural Instruction Subclass

BasStructure subclass contains all structure control-related methods, used for building structure control instruction sequences.

4.10.4.1 WAIT Wait Condition Instruction

Method NameBasScript.BasStructure.WAIT(RegisterType param1 , int index , ValueType param2 , object value , BooleanOperator operatorType = BooleanOperator.EQ)
DescriptionWait condition instruction, executes WAIT instruction only when the condition is met, the program can continue to execute downward, otherwise it waits until the condition is met, corresponds to WAIT COND statement in robot program writing
Request Parametersparam1 : RegisterType First parameter (register or IO signal)
index : int Index of parameter 1
param2 : ValueType Second parameter (register, IO signal, or other type)
value : object Index or value of parameter 2
operatorType : BooleanOperator Logical operator, default is equal
Return ValueStatusCode: Operation execution result

4.10.4.2 WAIT_TIME Wait Time Instruction

Method NameBasScript.BasStructure.WAIT_TIME(ValueType param , double value )
DescriptionWait time instruction, executes WAIT TIME instruction, the robot waits for the specified time before continuing to execute subsequent instructions, corresponds to WAIT TIME statement in robot program writing
Request Parametersparam : ValueType Parameter type (R register or value)
value : double Time value, unit: sec
Return ValueStatusCode: Operation execution result

4.10.4.3 PAUSE Instruction

Method NameBasScript.BasStructure.PAUSE()
DescriptionPAUSE statement
Request ParametersNone
Return ValueStatusCode: Operation execution result

4.10.4.4 ABORT Instruction

Method NameBasScript.BasStructure.ABORT()
DescriptionABORT statement
Request ParametersNone
Return ValueStatusCode: Operation execution result

4.10.4.5 CALL Synchronous Program Call Instruction

Method NameBasScript.BasStructure.CALL(name)
DescriptionCALL synchronous program call
Request Parametersname : Program name
Return ValueStatusCode: Operation execution result

4.10.4.6 RUN Asynchronous Program Call Instruction

Method NameBasScript.BasStructure.RUN(name)
DescriptionRUN asynchronous program call
Request Parametersname : Program name
Return ValueStatusCode: Operation execution result

4.10.4.7 LOAD Load Program Instruction

Method NameBasScript.BasStructure.LOAD(param, value)
DescriptionLOAD load program
Request Parametersparam : Parameter, R register, SR register, number, or string
value : Value of the parameter, number or string
Return ValueStatusCode: Operation execution result

4.10.4.8 UNLOAD Unload Program Instruction

Method NameBasScript.BasStructure.UNLOAD(param, value)
DescriptionUNLOAD unload program
Request Parametersparam : Parameter, R register, SR register, number, or string
value : Value of the parameter, number or string
Return ValueStatusCode: Operation execution result

4.10.4.9 EXEC Execute Program Instruction

Method NameBasScript.BasStructure.EXEC(param, value)
DescriptionEXEC execute program
Request Parametersparam : Parameter, R register, SR register, number, or string
value : Value of the parameter, number or string
Return ValueStatusCode: Operation execution result

4.10.5 BasSocket Socket Communication Subclass

BasSocket subclass contains all Socket communication-related methods, used for building Socket communication instruction sequences.

4.10.5.1 OPEN Open Socket Connection Instruction

Method NameBasScript.BasSocket.OPEN(int index )
DescriptionUses Socket Open instruction to create a Server and wait for Client connection, corresponds to SOCKET OPEN in robot program writing
Request Parametersindex : int SK register index
Return ValueStatusCode: Operation execution result

4.10.5.2 CLOSE Close Socket Connection Instruction

Method NameBasScript.BasSocket.CLOSE(int index )
DescriptionCloses the specified socket connection, corresponds to SOCKET CLOSE in robot program writing
Request Parametersindex : int SK register index
Return ValueStatusCode: Operation execution result

4.10.5.3 CONNECT Socket Connection Instruction

Method NameBasScript.BasSocket.CONNECT(int index )
DescriptionUses Socket Connect instruction to connect to the specified socket server, corresponds to SOCKET CONNECT in robot program writing
Request Parametersindex : int SK register index
Return ValueStatusCode: Operation execution result

4.10.5.4 SEND Send Socket Data Instruction

Method NameBasScript.BasSocket.SEND(int index , StrType msgType , object value )
DescriptionUses Socket Send instruction to send data to the specified socket connection, corresponds to SOCKET SEND in robot program writing
Request Parametersindex : int SK register index
msgType : StrType Message type
value : object Message content or index
Return ValueStatusCode: Operation execution result

4.10.5.5 RECV Receive Socket Data Instruction

Method NameBasScript.BasSocket.RECV(int index , int msgLength , StrType msgType , object value )
DescriptionUses Socket Recv instruction to read characters from the specified socket connection, can specify maximum length, corresponds to SOCKET RECV in robot program writing
Request Parametersindex : int SK register index
msgLength : int Message maximum length
msgType : StrType Message type
value : object Message content or index
Return ValueStatusCode: Operation execution result

4.10.6 BasModbus Modbus Communication Subclass

BasModbus subclass contains all Modbus communication-related methods, used for building Modbus register read/write instruction sequences.

4.10.6.1 READ_MH Read Modbus Holding Register Instruction

Method NameBasScript.BasModbus.READ_MH(int index , int id , int address , int length , int rIndex )
DescriptionRead Modbus holding register instruction, corresponds to READ_MH in robot program writing
Request Parametersindex : int Channel index
id : int Modbus ID
address : int Register start address
length : int Register length, i.e., number of registers to read
rIndex : int R register start index to write result
Return ValueStatusCode: Operation execution result

4.10.6.2 READ_MI Read Modbus Input Register Instruction

Method NameBasScript.BasModbus.READ_MI(int index , int id , int address , int length , int rIndex )
DescriptionRead Modbus input register instruction, corresponds to READ_MI in robot program writing
Request Parametersindex : int Channel index
id : int Modbus ID
address : int Register start address
length : int Register length, i.e., number of registers to read
rIndex : int R register start index to write result
Return ValueStatusCode: Operation execution result

4.10.6.3 WRITE_MH Write Modbus Holding Register Instruction

Method NameBasScript.BasModbus.WRITE_MH(int index , int id , int address , int length , ValueType valueType , int value )
DescriptionWrite Modbus holding register instruction, corresponds to WRITE_MH in robot program writing
Request Parametersindex : int Channel index
id : int Modbus ID
address : int Register start address
length : int Register length, i.e., number of registers to write
valueType : ValueType Value type
value : int Value or R register start index
Return ValueStatusCode: Operation execution result

4.10.7 BasVision Vision Instruction Subclass

BasVision subclass contains all vision-related methods, used for building vision program instruction sequences.

4.10.7.1 FIND Find Vision Program Instruction

Method NameBasScript.BasVision.FIND(string name )
DescriptionExecutes vision find program, corresponds to VISION FIND in robot program writing
Request Parametersname : string Vision program name
Return ValueStatusCode: Operation execution result

4.10.7.2 GET_OFFSET Get Vision Program Offset Instruction

Method NameBasScript.BasVision.GET_OFFSET(string name , int index , int labelIndex )
DescriptionGets offset after vision program execution, corresponds to VISION GET OFFSET in robot program writing
Request Parametersname : string Vision program name
index : int Vision register index
labelIndex : int Label index
Return ValueStatusCode: Operation execution result

4.10.7.3 GET_QUANTITY Get Vision Program Result Instruction

Method NameBasScript.BasVision.GET_QUANTITY(string name , int index )
DescriptionGets result quantity after vision program execution, corresponds to VISION GET QUANTITY in robot program writing
Request Parametersname : string Vision program name
index : int R register index to store result
Return ValueStatusCode: Operation execution result

4.10.8 AssignValue Assignment Instruction (Full Parameters)

Method NameBasScript.AssignValue(AssignType param1 , int index , AssignType param2 , object value , int optIndex = 0, int optValue = 0)
DescriptionAssignment instruction, used to assign values to registers, IO signals, etc., corresponds to ASSIGN statement in robot program writing
Request Parametersparam1 : AssignType First parameter (register or IO signal)
index : int Index of parameter 1
param2 : AssignType Second parameter (register, IO signal, or other type)
value : object Index or value of parameter 2
optIndex : int Additional index for parameter 1 when param1 is PR_ELEMENT, default 0
optValue : int Additional index for parameter 2 when param2 is PR_ELEMENT or pulse value when value is IOStatus.PULSE, default 0
Return ValueStatusCode: Operation execution result

4.10.9 AssignValue Assignment Instruction (Simplified Parameters)

Method NameBasScript.AssignValue(AssignType param , int index , object value )
DescriptionAssignment instruction (simplified parameters), used to assign values to registers, IO signals, etc., corresponds to ASSIGN statement in robot program writing
Request Parametersparam : AssignType Parameter type (register or IO signal)
index : int Parameter index
value : object Value (IOStatus, double, or string)
Return ValueStatusCode: Operation execution result

4.10.10 SetParam Set Parameter Instruction

Method NameBasScript.SetParam(ParamType type , ValueType valueType , object value )
DescriptionSet parameter instruction, used to set various parameters of the robot, corresponds to SET PARAM in robot program writing
Request Parameterstype : ParamType Parameter type
valueType : ValueType Value type
value : object Value
Return ValueStatusCode: Operation execution result