User Tools

Site Tools


control_connections

Control connections

GetConnectionAddress (connection)

The GetConnectionAddress function returns the current address of the device with which it is communicating. The function is available since version 3.0.

The connection parameter specifies which connection to take the address from:

  • connection ID
  • Lua variable name
  Please note that numerical constants like ID numbers can make 
  the reading of the code complicated and it is preferable to 
  use named lines.

If no connection is found, nil is returned.

For connections connected via RS-485, the address is a number. GetConnectionAddress will return values ​​of type number.

For TCP and UDP connections, the address is its IP address or host name. GetConnectionAddress will return values ​​of type string.

SetConnectionAddress (connection, new_address)

The SetConnectionAddress function replaces the current address of the device being communicated with a new one. The function is available since version 3.0. SetConnectionAddress is designed to work in projects with hot backup controllers and allows you to read registers from a particular (active, working) PLC.

The connection parameter specifies for which connection the address should be replaced:

  • connection ID
  • Lua variable name

If no connection is found, nil is returned. If the address was changed successfully, the function returns true. If you try to replace the address in internal register connection, the function returns false.

For connections connected via RS-485, the address is a number. SetConnectionAddress expects the value of new_address to be of type number.

For TCP and UDP connections, the address is its IP address or host name. SetConnectionAddress expects the values ​​of new_address to be of type string.

GetConnectionUnitId (mb_connection)

The GetConnectionUnitId function returns the current Unit Id of the specified Modbus TCP connection. The function is available since version 3.1.

The mb_connection parameter is the Modbus connection ID or its Lua name.

If no connection was found, nil will be returned.

Unit Id is a number (0 .. 255). GetConnectionUnitId will return values ​​of type number.

SetConnectionUnitId(mb_connection, new_unit_id)

The SetConnectionUnitId function replaces the current Unit Id in provided Modbus TCP connection. The function is available since version 3.1. SetConnectionUnitId is designed to work in projects with hot backup controllers and allows you to read registers from a particular (active, working) PLC.

  • mb_connection - Modbus TCP connection ID or its Lua name.

If no connection is found, nil is returned. If the unit id was changed successfully, the function returns true. If you try to replace the address in internal register connection, the function returns false.

Unit Id is a number (0 .. 255). SetConnectionUnitId expects the value of new_unit_id to be of type number.

EnableConnection (connection)

EnableConnection turns on polling registers “on-the-fly” in the specified connection. The function is available since version 3.0. In the project configuration, the checkbox 'Disconnect' for the specified connection does not change.

  • connection - ID or Lua name

DisableConnection(connection)

DisableConnection disables polling registers “on the fly” in the specified connection. The function is available since version 3.0. In the project configuration, the checkbox 'Disconnect' for the specified connection does not change.

  • connection - ID or Lua name

IsConnectionEnabled(connection)

The IsConnectionEnabled function tells whether the polling of registers in the specified connection is enabled. The function is available since version 3.0.

  • connection - ID or Lua name for the connection to be enabled.

GetConnectionErrors(connection)

The GetConnectionErrors function reports whether there were errors while reading the registers in the last scan in the specified connection. The function is available since version 3.0.

  • connection - ID of Lua name of the connection being checked

If there were no errors, then the function returns zero. If there were errors, then the ID of the last register is returned, which was not read.

GetConnectionScanTime(connection)

The GetConnectionScanTime function returns the time taken to poll the registers in the last scan in the specified connection. The function is available since version 3.0.

  • connection - ID or Lua variable name

The function returns the time in milliseconds.

GetConnectionErrorScans(connection)

The GetConnectionErrorScans function returns the number of consecutive scans in which there were errors reading the registers in the specified connection. The function is available since version 3.0.

  • connection - ID or Lua variable name

The function returns the number of scans in which read errors occurred. If in any scan there were no read errors in this connection, the counter is reset to zero.

control_connections.txt · Last modified: 2022/09/29 13:00 by atolstov

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki