modasciiClose (Function)

Top  Previous  Next

Architecture:

X32 / NX32 / NX32L

Device support:

All devices with RS485

Firmware version:

4.50 / 1.00.00


This function will close a MODBUS ASCII connection, previously opened by the modasciiOpen function.

 

Input:

net_id : INT

The ID of the MODBUS connection.

 

 

Returns: INT

0

- Success.

-1

- Illegal MODBUS connection ID.

 

Declaration:

FUNCTION modasciiClose;
VAR_INPUT
  net_id : INT;
END_VAR;

 

 

Example:

INCLUDE rtcu.inc
 
VAR_INPUT
  switch : BOOL R_EDGE;
END_VAR;
 
VAR
  mb_net : INT;
  mode   : SINT;
END_VAR;
 
PROGRAM ModbusExample;
 
  mb_net := modasciiOpen(mode := mode, unit_id := 1, port := 2, baud := 57600, parity := 0);
 
BEGIN
  IF switch THEN
    // Close MODBUS net
    modasciiClose(net_id := mb_net);
 
    // Open new MODBUS net
    IF mode = 0 THEN
        mode := 1;
    ELSE
        mode := 0;
    END_IF;
     mb_net := modasciiOpen(mode := mode, unit_id := 1, port := 2, baud := 57600, parity := 0);
  END_IF;
END;
END_PROGRAM;