This function will close a MODBUS connection, previously opened by the modbusOpen or modbusOpenX functions.
Input:
net_id : INT
The ID of the MODBUS connection.
Returns: INT
0
|
- Success.
|
-1
|
- Illegal MODBUS connection ID.
|
Declaration:
FUNCTION modbusClose;
VAR_INPUT
net_id : INT;
END_VAR;
Example:
INCLUDE rtcu.inc
VAR_INPUT
switch : BOOL R_EDGE;
END_VAR;
VAR
mb_net : INT;
mb_id : INT := 0;
END_VAR;
PROGRAM ModbusExample;
mb_net := modbusOpenX(mode := 1, unit_id := mb_id, port := 2, baud := 57600, parity := 0);
BEGIN
IF switch THEN
modbusClose(net_id := mb_net);
IF mb_id = 0 THEN
mb_id := 1;
ELSE
mb_id := 0;
END_IF;
mb_net := modbusOpenX(mode := 1, unit_id := mb_id, port := 2, baud := 57600, parity := 0);
END_IF;
END;
END_PROGRAM;
|