SetSerialConf: Change the Serial Line Configuration

Function Description

SetSerialConf is used to change the serial line configuration.

Graphical Representation

G-RU-0010375.2.gif-high.gif

 

 

NOTE: Changing the configuration of the Serial Line(s) port(s) during programming execution can interrupt ongoing communications with other connected devices.

Warning_Color.gifWARNING

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

LinkNumber is the communication port number.

PointerToSerialConf

POINTER TO SERIAL_CONF

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:

o0: The new configuration is set

o255: The new configuration is refused because:

othe function is in progress

othe 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));