IO
The IO commands are used for reading and writing the mechanical arm's system IO states and setting related parameters.
Command Function Table
Command | Function |
---|---|
DI | Get the status of a DI port |
DIGroup | Get the status of multiple DI ports |
DO | Set the status of a digital output port |
DOGroup | Set the status of multiple digital output ports |
GetDO | Get the current status of a digital output port |
GetDOGroup | Get the current status of multiple digital output ports |
AI | Get the value of an AI port |
AO | Set the value of an analog output port |
GetAO | Get the current value of an analog output port |
DI
Prototype:
DI(index)
Description:
Reads the status of a digital input port.
Required Parameter:
index
: The number of the DI terminal.
Returns:
- The status of the corresponding DI terminal (ON/OFF).
Example:
-- When DI1 is ON, the mechanical arm moves to point P1 in a linear motion.
if (DI(1) == ON) then
MovL(P1)
end
DIGroup
Prototype:
DIGroup(index1, ..., indexN)
Description:
Reads the status of multiple digital input ports.
Required Parameters:
index
: The numbers of the DI terminals, separated by commas.
Returns:
- The status of the corresponding DI terminals (ON/OFF), returned as an array.
Example:
-- When both DI1 and DI2 are ON, the mechanical arm moves to point P1 in a linear motion.
local digroup = DIGroup(1, 2)
if (digroup[1] & digroup[2] == ON) then
MovL(P1)
end
DO
Prototype:
DO(index, ON|OFF, time_ms)
Description:
Sets the status of a digital output port.
Required Parameters:
index
: The number of the DO terminal.ON|OFF
: The status to set the DO port.
Optional Parameter:
time_ms
: Duration for which the output will be active, in milliseconds, ranging from[25, 60000]
. If this parameter is set, the system will automatically toggle the DO after the specified time. The toggle is asynchronous and does not block the instruction queue; the system will execute the next instruction immediately after setting the DO output.
Example:
-- Set DO1 to ON.
DO(1, ON)
-- Set DO1 to ON and automatically set it to OFF after 50ms.
DO(1, ON, 50)
DOGroup
Prototype:
DOGroup({index1, ON|OFF}, ..., {indexN, ON|OFF})
Description:
Sets the status of multiple digital output ports.
Required Parameters:
index
: The number of the DO terminal.ON|OFF
: The status to set for the DO port. Multiple groups can be set, each enclosed in braces, separated by commas.
Example:
-- Set DO1 and DO2 to ON.
DOGroup({1, ON}, {2, ON})
GetDO
Prototype:
GetDO(index)
Description:
Gets the current status of a digital output port.
Required Parameter:
index
: The number of the DO terminal.
Returns:
- The status of the corresponding DO terminal (ON/OFF).
Example:
-- Get the current status of DO1.
GetDO(1)
GetDOGroup
Prototype:
GetDOGroup(index1, ..., indexN)
Description:
Gets the current status of multiple digital output ports.
Required Parameters:
index
: The numbers of the DO terminals, separated by commas.
Returns:
- The status of the corresponding DO terminals (ON/OFF), returned as an array.
Example:
-- Get the current status of DO1 and DO2.
GetDOGroup(1, 2)
AI
Prototype:
AI(index)
Description:
Reads the value of an analog input port.
Required Parameter:
index
: The number of the AI terminal.
Returns:
- The value of the corresponding AI terminal.
Example:
-- Read the value of AI1 and assign it to the variable test.
test = AI(1)
AO
Prototype:
AO(index, value)
Description:
Sets the value of an analog output port.
Required Parameters:
index
: The number of the AO terminal.value
: The value to set, with a voltage range of[0, 10]
volts or a current range of[4, 20]
mA.
Example:
-- Set the output value of AO1 to 2V.
AO(1, 2)
GetAO
Prototype:
GetAO(index)
Description:
Gets the current value of an analog output port.
Required Parameter:
index
: The number of the AO terminal.
Returns:
- The current value of the corresponding AO terminal.
Example:
-- Get the current value of AO1.
GetAO(1)