SetSerialConf: Change the Serial Line Configuration

Function Description

SetSerialConf is used to change the serial line configuration.

Graphical Representation

NOTE: Changing the configuration of the Serial Line(s) port(s) during programming execution can interrupt ongoing communications with other connected devices.
 WARNING
LOSS OF CONTROL DUE TO CONFIGURATION CHANGE
Validate and test all the parameters of the SetSerialConf function before putting your program into service.
Failure to follow these instructions can result in death, serious injury, or equipment damage.

Parameter Description

Input

Type

Comment

Link

LinkNumber (see EcoStruxure Machine Expert, Modbus and ASCII Read/Write Functions, PLCCommunication Library Guide)

LinkNumber is the communication port number.

PointerToSerialConf

PointerToSerialConf

PointerToSerialConf is the address of the configuration structure (variable of SERIAL_CONF type) in which the new configuration parameters are stored. The ADR standard function must be used to define the associated pointer. (See the example below.) If 0, set the application default configuration to the serial line.

Output

Type

Comment

SetSerialConf

WORD

This function returns:

  • 0: The new configuration is set

  • 255: The new configuration is refused because:

    • the function is in progress

    • the input parameters are not valid

Example

VAR 
  MySerialConf: SERIAL_CONF 
  result: WORD;
END_VAR
(*Get current configuration of serial line 1*)
GetSerialConf(1, ADR(MySerialConf));
(*Change to modbus RTU slave address 9*)
MySerialConf.Protocol := 0;          (*Modbus RTU/Machine Expert protocol (in this case CodesysCompliant selects the protocol)*)
MySerialConf.CodesysCompliant := 0; (*Modbus RTU*)
MySerialConf.address := 9;          (*Set modbus address to 9*)
(*Reconfigure the serial line 1*)
result := SetSerialConf(1, ADR(MySerialConf));