modbusClose (Function)

Top  Previous  Next

Architecture:

X32 / NX32 / NX32L

Firmware version:

4.50 / 1.00.00


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// open as master
END_VAR;
 
PROGRAM ModbusExample;
 
   mb_net := modbusOpenX(mode := 1, unit_id := mb_id, port := 2, baud := 57600, parity := 0);
 
BEGIN
   IF switch THEN
      // Close MODBUS net
      modbusClose(net_id := mb_net);
 
      // Open new MODBUS net
      IF mb_id = 0 THEN
         mb_id := 1// open as slave
      ELSE
         mb_id := 0// open as master
      END_IF;
      mb_net := modbusOpenX(mode := 1, unit_id := mb_id, port := 2, baud := 57600, parity := 0);
   END_IF;
END;
END_PROGRAM;